update ffmpeg.git files for newer versions
[goodguy/cinelerra.git] / cinelerra-5.1 / tools / makeappimagetool / log.cpp
1 // local includes
2 #include "includes/log.h"
3
4 namespace linuxdeploy {
5     namespace core {
6         namespace log {
7             LD_LOGLEVEL ldLog::verbosity = LD_INFO;
8
9             void ldLog::setVerbosity(LD_LOGLEVEL verbosity) {
10                 ldLog::verbosity = verbosity;
11             }
12
13             ldLog::ldLog() {
14                 prependSpace = false;
15                 currentLogLevel = LD_INFO;
16                 logLevelSet = false;
17             };
18
19             ldLog::ldLog(bool prependSpace, bool logLevelSet, LD_LOGLEVEL logLevel) {
20                 this->prependSpace = prependSpace;
21                 this->currentLogLevel = logLevel;
22                 this->logLevelSet = logLevelSet;
23             }
24
25             void ldLog::checkPrependSpace() {
26                 if (prependSpace) {
27                     stream << " ";
28                     prependSpace = false;
29                 }
30             }
31
32             bool ldLog::checkVerbosity() {
33 //                std::cerr << "current: " << currentLogLevel << " verbosity: " << verbosity << std::endl;
34                 return (currentLogLevel >= verbosity);
35             }
36
37             ldLog ldLog::operator<<(const std::string& message) {
38                 if (checkVerbosity()) {
39                     checkPrependSpace();
40                     stream << message;
41                 }
42
43                 return ldLog(true, logLevelSet, currentLogLevel);
44             }
45             ldLog ldLog::operator<<(const char* message) {
46                 if (checkVerbosity()) {
47                     checkPrependSpace();
48                     stream << message;
49                 }
50
51                 return ldLog(true, logLevelSet, currentLogLevel);
52             }
53
54             ldLog ldLog::operator<<(const boost::filesystem::path& path) {
55                 if (checkVerbosity()) {
56                     checkPrependSpace();
57                     stream << path.string();
58                 }
59
60                 return ldLog(true, logLevelSet, currentLogLevel);
61             }
62
63             ldLog ldLog::operator<<(const int val) {
64                 return ldLog::operator<<(std::to_string(val));
65             }
66
67             ldLog ldLog::operator<<(const size_t val) {
68                 return ldLog::operator<<(std::to_string(val));
69             }
70
71             ldLog ldLog::operator<<(const double val) {
72                 return ldLog::operator<<(std::to_string(val));
73             }
74
75             ldLog ldLog::operator<<(stdEndlType strm) {
76                 if (checkVerbosity()) {
77                     checkPrependSpace();
78                     stream << strm;
79                 }
80
81                 return ldLog(false, logLevelSet, currentLogLevel);
82             }
83
84             ldLog ldLog::operator<<(const LD_LOGLEVEL logLevel) {
85                 if (logLevelSet) {
86                     throw std::runtime_error(
87                         "log level must be first element passed via the stream insertion operator");
88                 }
89
90                 logLevelSet = true;
91                 currentLogLevel = logLevel;
92
93                 if (checkVerbosity()) {
94                     switch (logLevel) {
95                         case LD_DEBUG:
96                             stream << "DEBUG: ";
97                             break;
98                         case LD_WARNING:
99                             stream << "WARNING: ";
100                             break;
101                         case LD_ERROR:
102                             stream << "ERROR: ";
103                             break;
104                         default:
105                             break;
106                     }
107                 }
108
109                 return ldLog(false, logLevelSet, currentLogLevel);
110             }
111
112             ldLog ldLog::operator<<(const LD_STREAM_CONTROL streamControl) {
113                 bool prependSpace = true;
114
115                 switch (streamControl) {
116                     case LD_NO_SPACE:
117                         prependSpace = false;
118                         break;
119                     default:
120                         break;
121                 }
122
123                 return ldLog(prependSpace, logLevelSet, currentLogLevel);
124             }
125
126             void ldLog::write(const char* s, const size_t n) {
127                 stream.write(s, n);
128             }
129         }
130     }
131 }