summaryrefslogtreecommitdiffstats
path: root/src/ml/dlib/examples/logger_ex.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 12:08:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 12:08:18 +0000
commit5da14042f70711ea5cf66e034699730335462f66 (patch)
tree0f6354ccac934ed87a2d555f45be4c831cf92f4a /src/ml/dlib/examples/logger_ex.cpp
parentReleasing debian version 1.44.3-2. (diff)
downloadnetdata-5da14042f70711ea5cf66e034699730335462f66.tar.xz
netdata-5da14042f70711ea5cf66e034699730335462f66.zip
Merging upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/ml/dlib/examples/logger_ex.cpp')
-rw-r--r--src/ml/dlib/examples/logger_ex.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/ml/dlib/examples/logger_ex.cpp b/src/ml/dlib/examples/logger_ex.cpp
new file mode 100644
index 000000000..281e2ad16
--- /dev/null
+++ b/src/ml/dlib/examples/logger_ex.cpp
@@ -0,0 +1,70 @@
+// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
+
+/*
+
+ This is a simple example illustrating the use of the logger object from
+ the dlib C++ Library.
+
+
+ The output of this program looks like this:
+
+ 0 INFO [0] example: This is an informational message.
+ 0 DEBUG [0] example: The integer variable is set to 8
+ 0 WARN [0] example: The variable is bigger than 4! Its value is 8
+ 0 INFO [0] example: we are going to sleep for half a second.
+ 503 INFO [0] example: we just woke up
+ 503 INFO [0] example: program ending
+
+
+ The first column shows the number of milliseconds since program start at the time
+ the message was printed, then the logging level of the message, then the thread that
+ printed the message, then the logger's name and finally the message itself.
+
+*/
+
+
+#include <dlib/logger.h>
+#include <dlib/misc_api.h>
+
+using namespace dlib;
+
+// Create a logger object somewhere. It is usually convenient to make it at the global scope
+// which is what I am doing here. The following statement creates a logger that is named example.
+logger dlog("example");
+
+int main()
+{
+ // Every logger has a logging level (given by dlog.level()). Each log message is tagged with a
+ // level and only levels equal to or higher than dlog.level() will be printed. By default all
+ // loggers start with level() == LERROR. In this case I'm going to set the lowest level LALL
+ // which means that dlog will print all logging messages it gets.
+ dlog.set_level(LALL);
+
+
+ // print our first message. It will go to cout because that is the default.
+ dlog << LINFO << "This is an informational message.";
+
+ // now print a debug message.
+ int variable = 8;
+ dlog << LDEBUG << "The integer variable is set to " << variable;
+
+ // the logger can be used pretty much like any ostream object. But you have to give a logging
+ // level first. But after that you can chain << operators like normal.
+
+ if (variable > 4)
+ dlog << LWARN << "The variable is bigger than 4! Its value is " << variable;
+
+
+
+ dlog << LINFO << "we are going to sleep for half a second.";
+ // sleep for half a second
+ dlib::sleep(500);
+ dlog << LINFO << "we just woke up";
+
+
+
+ dlog << LINFO << "program ending";
+}
+
+
+