Jump to content


Photo

logging in blackbox

development logging blackbox

  • Please log in to reply
4 replies to this topic

#1 mojmir

mojmir

    BB Developer

  • Moderators
  • 254 posts

Posted 05 March 2014 - 09:03 AM

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 :D

 



#2 diabol

diabol

    Lazyass

  • Moderators
  • 235 posts

Posted 05 March 2014 - 03:04 PM

finally.

I think I'll later connect the api's dbg_printf if you haven't done that already :)



#3 mojmir

mojmir

    BB Developer

  • Moderators
  • 254 posts

Posted 05 March 2014 - 03:10 PM

nah, not yet. i did not go deeper than main() function (i.e. connect, one line of log and disconnect)

not enough time.. the builds will not break themselves, you know :P

 

p.s.: do not forget init submodules:

git submodule initgit submodule syncgit submodule update --recursive


#4 diabol

diabol

    Lazyass

  • Moderators
  • 235 posts

Posted 05 March 2014 - 04:36 PM

 

nah, not yet. i did not go deeper than main() function (i.e. connect, one line of log and disconnect)

not enough time.. the builds will not break themselves, you know :P

 

p.s.: do not forget init submodules:

git submodule initgit submodule syncgit submodule update --recursive

 

what's the point in making it complicated when you explain how it works? :D



#5 mojmir

mojmir

    BB Developer

  • Moderators
  • 254 posts

Posted 06 March 2014 - 09:38 AM

because that way you will understand it and after then you can make waay more complex bugs ;)


  • diabol likes this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users