| 47 | }; |
| 48 | |
| 49 | int main() |
| 50 | { |
| 51 | my_hook hook; |
| 52 | // This tells all dlib loggers to send their logging events to the hook object. That |
| 53 | // is, any time a logger generates a message it will call hook.log() with the message |
| 54 | // contents. Additionally, hook.log() will also only be called from one thread at a |
| 55 | // time so it is safe to use this kind of hook in a multi-threaded program with many |
| 56 | // loggers in many threads. |
| 57 | set_all_logging_output_hooks(hook); |
| 58 | // It should also be noted that the hook object must not be destructed while the |
| 59 | // loggers are still in use. So it is a good idea to declare the hook object |
| 60 | // somewhere where it will live the entire lifetime of the program, as we do here. |
| 61 | |
| 62 | |
| 63 | logger dlog("main"); |
| 64 | // Tell the dlog logger to emit a message for all logging events rather than its |
| 65 | // default behavior of only logging LERROR or above. |
| 66 | dlog.set_level(LALL); |
| 67 | |
| 68 | // All these message go to my_log_file.txt, but only the last two go to the console. |
| 69 | dlog << LDEBUG << "This is a debugging message."; |
| 70 | dlog << LINFO << "This is an informational message."; |
| 71 | dlog << LERROR << "An error message!"; |
| 72 | } |
| 73 |
nothing calls this directly
no test coverage detected