MCPcopy Create free account
hub / github.com/davisking/dlib / main

Function main

examples/logger_ex_2.cpp:111–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109}
110
111int main()
112{
113 setup_loggers();
114
115 // print our first message. It will go to cout because that is the default.
116 logp << LINFO << "This is an informational message.";
117
118 int variable = 8;
119
120 // Here is a debug message. It won't print though because its log level is too low (it is below LINFO).
121 logp << LDEBUG << "The integer variable is set to " << variable;
122
123
124 if (variable > 4)
125 logp << LWARN << "The variable is bigger than 4! Its value is " << variable;
126
127 logp << LINFO << "make two threads";
128 create_new_thread(thread,0);
129 create_new_thread(thread,0);
130
131 test mytest;
132 mytest.warning();
133
134 logp << LINFO << "we are going to sleep for half a second.";
135 // sleep for half a second
136 dlib::sleep(500);
137 logp << LINFO << "we just woke up";
138
139
140
141 logp << LINFO << "program ending";
142
143
144 // It is also worth pointing out that the logger messages are atomic. This means, for example, that
145 // in the above log statements that involve a string literal and a variable, no other thread can
146 // come in and print a log message in-between the literal string and the variable. This is good
147 // because it means your messages don't get corrupted. However, this also means that you shouldn't
148 // make any function calls inside a logging statement if those calls might try to log a message
149 // themselves since the atomic nature of the logger would cause your application to deadlock.
150}
151
152
153

Callers

nothing calls this directly

Calls 4

setup_loggersFunction · 0.85
warningMethod · 0.80
create_new_threadFunction · 0.50
sleepFunction · 0.50

Tested by

no test coverage detected