re,
i added the possibility to use some logging mechanisms to blackbox.
1) What the...
the logging uses an external library, which is currently present in blackbox as submodule.
there are two new additions to source tree:
- 3rd_party/flogging
this is the external library. the important part for blackbox is 3rd_party/flogging/trace_client
- 3rd_party/logging
this is the wrapper on the top of flogging library that will be included in files. it contains:
- 3rd_party/logging/logging.h
this is the include that will be included in files that are using logging
- 3rd_party/logging/server/trace_server.exe
server for receiving log messages
2) How the ... i use it
1. enable logging in the top-level CMakeLists.txt by removing the comment # character on the line
set(USE_LOGGING 1)
2. include logging.h in your file. the path to logging shoud be added by cmake, so you do not need to specify full path
#include <logging.h>
3. run server. you can find a copy in
3rd_party/logging/server/trace_server.exe
4. run client (blackbox)
2) How the ... i use it from code
There are few macros in the library that are important.
2.1) initializing/setup macros
usual sequence in main.cpp is
TRACE_APPNAME("BlackBox");TRACE_CONNECT();
sometimes these comes handy:
- following line turns on or off buffering. buffering in off means, that the messages will be sent synchronously, i.e. the client waits until the message is sent. it's good when your client crashes and you do not want to loose the messages in buffer. but un-buffered mode is slower than buffered.
TRACE_SETBUFFERED(true or false);
- set level
TRACE_SETLEVEL(n)
2.1) logging macros
- text logging
TRACE_MSG(trace::e_Info, trace::CTX_BBCore, "Initializing BlackBox, version %s", BBLEAN_VERSION);
- plotting
TRACE_PLOT_XY(trace::e_Info, trace::CTX_Default, x, y, "myplot/mycurve_%i", 1);
the levels and contexts are defined in 3rd_party/logging/levels.h
namespace trace { enum E_TraceLevel { e_Fatal = 0, e_Error, e_Warning, e_Info, e_Detail, e_Debug, e_max_trace_level /// last item of enum }; typedef E_TraceLevel level_t;
and contexts are defined in a bit weird but handy way in 3rd_party/logging/contexts.inc
DRY(CTX_Default , (1 << 0))DRY(CTX_BBCore , (1 << 1))DRY(CTX_Plugin , (1 << 2))
if you need more, just add them.
and that's about it i think.
oh yes the server.. it's still a bit under construction.
so be careful and do not do things i wouldn't do