Thread: [Cppcms-users] booster::log
Brought to you by:
artyom-beilis
From: Marcel H. <ke...@co...> - 2012-03-15 10:29:43
|
hi everyone, I'm searching for a good logger tool for c++ and found (oh what a wonder) booster::log. It's simple and powerfull. Nice to handle and everything. I found boost.log too but can't install it, because I don't know how :D (funny, isn't it?) So two major questions. Would it be possible to add two things?! - add a constructor for sinks::file which takes the file name as a parameter and optionally the max files? It would be easier to construct this, because you don't have to create a pointer (or whatever) first and then hand it over to the logger - add a constructor to sinks::standard_error which takes a ostream as parameter. Maybe you define an other class that does this. and two other questions: - what is the const char *module in should_be_logged, set_log_level and so on? It's a "string", of course, but where do I get the string for my sink?! - Is it true, that I can only use booster without cppcms and that it's licended under the boost license? Regards, Marcel Hellwig |
From: Artyom B. <art...@ya...> - 2012-03-15 10:53:32
|
> >hi everyone, > >I'm searching for a good logger tool for c++ and found (oh what a >wonder) booster::log. >It's simple and powerfull. Nice to handle and everything. I found >boost.log too but can't install it, because I don't know how :D (funny, >isn't it?) Boost.Log passed a formal review about a year ago but needs lots of updates and meanwhile it is not ready. >Would it be possible to add two things?! > - add a constructor for sinks::file which takes the file name as a > parameter and optionally the max files? It would be easier to construct > this, because you don't have to create a pointer (or whatever) first and > then hand it over to the logger 1. You will still need to write something like booster::log::logger::instance().add_skink(booster::shared_ptr<booster::log::sink>(new booster::log::sinks::file(...))); 2. If you are using logger with CppCMS - it can configure it for you automatically: http://cppcms.com/wikipp/en/page/cppcms_1x_config#logging 3. Yes I can add an option :-), fill a request feature ticket or send a patch. > - add a constructor to sinks::standard_error which takes a ostream as >parameter. Maybe you define an other class that does this. The standard_error sink is defined as simple as that: class standard_error : public booster::log::sink { public: void standard_error::log(message const &msg) { std::cerr << format_plain_text_message(msg) << std::endl; } }; So just write your own sink :-) > >and two other questions: > - what is the const char *module in should_be_logged, set_log_level > and so on? It's a "string", of course, but where do I get the string for > my sink?! This string is module name so you write: BOOSTER_WARNING("bank") << "We run out of money"; This is handled automatically by macros for you. This string is a part of the message object. > - Is it true, that I can only use booster without cppcms and that it's >licended under the boost license? > Yes, it is true. Booster is an answer of my needs from Boost that boost does not allow me to handle properly, that is why Booster has the same license as Boost. >Regards, > >Marcel Hellwig > Regards, Artyom Beilis |
From: Marcel H. <ke...@co...> - 2012-03-15 12:30:43
|
>> and two other questions: >> - what is the const char *module in should_be_logged, set_log_level >> and so on? It's a "string", of course, but where do I get the string for >> my sink?! > > This string is module name so you write: > > BOOSTER_WARNING("bank")<< "We run out of money"; > > This is handled automatically by macros for you. > > This string is a part of the message object. I don't get it. If I write something like this: using namespace booster::log; booster::shared_ptr<sinks::file> fsink(new sinks::file()); fsink->open("server.log"); fsink->max_files(2); booster::shared_ptr<sinks::standard_error> csink(new sinks::standard_error()); logger::instance().add_sink(fsink); logger::instance().add_sink(csink); because I want to different log levels, which one is which? :D so how do I edit the level of fsink and csink separate? Which module should i declare? Wouldn't it be easier to hand a pointer to the method?! Marcel |
From: Artyom B. <art...@ya...> - 2012-03-15 12:44:41
|
> I don't get it. > If I write something like this: > > using namespace booster::log; > booster::shared_ptr<sinks::file> fsink(new sinks::file()); > fsink->open("server.log"); > fsink->max_files(2); > booster::shared_ptr<sinks::standard_error> csink(new > sinks::standard_error()); > > logger::instance().add_sink(fsink); > logger::instance().add_sink(csink); > > because I want to different log levels, which one is which? :D so how do > I edit the level of fsink and csink separate? Which module should i > declare? Wouldn't it be easier to hand a pointer to the method?! > The question to log or not to log decided on the logger level and not on the sink level. For example: BOOSTER_DEBUG("foo") << "This " << foo.heavy_value(); In normal (non-debug) mode the "foo.heavy_value()" would not be evaluated. Note, you can set logging level per module such that "foo" module would be logged for everything (debug) and "bar" module would be logged only for errors. The sinks are just allow to write to different locations, for example to both syslog and file or something like that. Of course you can do (if you want to) some filtering on sink level as well, but it is not its purpose. Just override the log(message const &) member function of a sink. Artyom Beilis |
From: Marcel H. <ke...@co...> - 2012-03-15 15:24:15
|
so if i guess it right: - a level is not sink specific, it's dependent on the message that should be logged. - a sink is the backend of the logger - every message goes to the logger and then to every sink. My idea is to implement a sink specifiec logger level, that means you register a sink l.add_sink(fsink, debug); l.add_sink(csink, error); with the error level. What does it mean: The responsibolity of logging is not in the message itself but in the registered sink. You don't have to check if the message itself should be logged, but if a sink is registered that has this loglevel (or above of course) You also may specific a name, instead of a pointer for a registered sink, f.e. fsink.name("fileLogger"); csink.name("ConsoleLogger"); My inspiration is the logger util from java which I really like. http://docs.oracle.com/javase/1.4.2/docs/api/java/util/logging/Logger.html The hirachy is optional but I like the concept. Regards, Marcel |
From: Marcel H. <ke...@co...> - 2012-03-15 15:55:02
|
ahh (: a light-bulb in front of me. the module is this BOOSTER_DEBUG("foo") << "bar"; ------ But still my problem is that i want to specific different log level for different handlers (the sinks in your way) I may try to include them. Are you interested in or do you want to make them on your own? It's up to you. Also i uploaded the diff for the sinks. https://sourceforge.net/tracker/index.php?func=detail&aid=3505317&group_id=209965&atid=1011837 also you haven't answered or implemented my patch i submitted a month ago! https://sourceforge.net/tracker/?func=detail&aid=3488226&group_id=209965&atid=1011837 come on... they are just whitespaces! (: Regards Marcel |
From: Artyom B. <art...@ya...> - 2012-03-16 20:42:05
|
> >But still my problem is that i want to specific different log level for >different handlers (the sinks in your way) >I may try to include them. Are you interested in or do you want to make >them on your own? It's up to you. You may create a filter sink that would be kind of "tee" device that can split a sink to different sinks... That may be nice. > >Also i uploaded the diff for the sinks. >https://sourceforge.net/tracker/index.php?func=detail&aid=3505317&group_id=209965&atid=1011837 > Applied, I changed an interfaces a little bit and made it more consistent with the CppCMS coding standards. >also you haven't answered or implemented my patch i submitted a month ago! >https://sourceforge.net/tracker/?func=detail&aid=3488226&group_id=209965&atid=1011837 > >come on... they are just whitespaces! (: > Fixed as well. Best, Artyom |