2 #include "includes/log.h"
4 namespace linuxdeploy {
7 LD_LOGLEVEL ldLog::verbosity = LD_INFO;
9 void ldLog::setVerbosity(LD_LOGLEVEL verbosity) {
10 ldLog::verbosity = verbosity;
15 currentLogLevel = LD_INFO;
19 ldLog::ldLog(bool prependSpace, bool logLevelSet, LD_LOGLEVEL logLevel) {
20 this->prependSpace = prependSpace;
21 this->currentLogLevel = logLevel;
22 this->logLevelSet = logLevelSet;
25 void ldLog::checkPrependSpace() {
32 bool ldLog::checkVerbosity() {
33 // std::cerr << "current: " << currentLogLevel << " verbosity: " << verbosity << std::endl;
34 return (currentLogLevel >= verbosity);
37 ldLog ldLog::operator<<(const std::string& message) {
38 if (checkVerbosity()) {
43 return ldLog(true, logLevelSet, currentLogLevel);
45 ldLog ldLog::operator<<(const char* message) {
46 if (checkVerbosity()) {
51 return ldLog(true, logLevelSet, currentLogLevel);
54 ldLog ldLog::operator<<(const boost::filesystem::path& path) {
55 if (checkVerbosity()) {
57 stream << path.string();
60 return ldLog(true, logLevelSet, currentLogLevel);
63 ldLog ldLog::operator<<(const int val) {
64 return ldLog::operator<<(std::to_string(val));
67 ldLog ldLog::operator<<(const size_t val) {
68 return ldLog::operator<<(std::to_string(val));
71 ldLog ldLog::operator<<(const double val) {
72 return ldLog::operator<<(std::to_string(val));
75 ldLog ldLog::operator<<(stdEndlType strm) {
76 if (checkVerbosity()) {
81 return ldLog(false, logLevelSet, currentLogLevel);
84 ldLog ldLog::operator<<(const LD_LOGLEVEL logLevel) {
86 throw std::runtime_error(
87 "log level must be first element passed via the stream insertion operator");
91 currentLogLevel = logLevel;
93 if (checkVerbosity()) {
99 stream << "WARNING: ";
109 return ldLog(false, logLevelSet, currentLogLevel);
112 ldLog ldLog::operator<<(const LD_STREAM_CONTROL streamControl) {
113 bool prependSpace = true;
115 switch (streamControl) {
117 prependSpace = false;
123 return ldLog(prependSpace, logLevelSet, currentLogLevel);
126 void ldLog::write(const char* s, const size_t n) {