From: <log...@li...> - 2015-03-15 23:25:58
|
Hi all, A silly question, I'm looking to use log4cpp for a data collection system I'm working on. To help in post mortem analysis it's often useful to separate out log messages by some common key to be able to piece out what happened. The system starts multiple transaction state machines each identified by a unique ID, creating them at runtime. They are one-shot, so once complete, the objects are freed. It appears it would make sense for each transaction state machine to have its own log category, as the log messages can then be grepped for and it ensures *every* log message from that log instance will have the ID prepended. It seems I can create as many category objects as I like, but what isn't clear is what happens to the category objects when they're no longer needed: I don't see any way to close them off or destroy them. (I could call delete(&category); but I'm not sure where else the pointer may be used.) Is there a way to remove categories once they're no longer in use? Regards, -- _ ___ Stuart Longland - Systems Engineer \ /|_) | T: +61 7 3535 9619 \/ | \ | 38b Douglas Street F: +61 7 3535 9699 SYSTEMS Milton QLD 4064 http://www.vrt.com.au |
From: <log...@li...> - 2015-03-16 01:11:32
|
On 3/15/15, 7:25 PM, "log...@li..." <log...@li...> wrote: >It appears it would make sense for each transaction state machine to >have its own log category, as the log messages can then be grepped for >and it ensures *every* log message from that log instance will have the >ID prepended. I think you want to use a diagnostic context, not a category. Just push and pop the ID with the NDC routines. (And you can't really destroy a category, so that's why it's a bad choice to use that.) -- Scott |
From: <log...@li...> - 2015-03-16 05:57:15
|
Hello Stuart, The categories in current design are seen as purposed for kind of static matters, those which do not actively come into the processing and leave it. There is static helper method to make their creation convenient and controlled. However, there is no destroy method since the pointer given out might still be kept somewhere else, out of log4cpp internals. If you'd like to have an unique id coming along with your log messages, you could take advantage of the NDC feature. It is exactly purposed for attaching kind of context to the log messages. It can be turned on and off from properties file without rebuilding, but note that is linked with a thread, and not with the particular category. If your processing is not thread-based, won't it be easier to log the id just as a part of the message itself? Alexander. On Mar 16, 2015 3:26 AM, <log...@li...> wrote: > Hi all, > > A silly question, I'm looking to use log4cpp for a data collection > system I'm working on. > > To help in post mortem analysis it's often useful to separate out log > messages by some common key to be able to piece out what happened. The > system starts multiple transaction state machines each identified by a > unique ID, creating them at runtime. They are one-shot, so once > complete, the objects are freed. > > It appears it would make sense for each transaction state machine to > have its own log category, as the log messages can then be grepped for > and it ensures *every* log message from that log instance will have the > ID prepended. > > It seems I can create as many category objects as I like, but what isn't > clear is what happens to the category objects when they're no longer > needed: I don't see any way to close them off or destroy them. (I could > call delete(&category); but I'm not sure where else the pointer may be > used.) > > Is there a way to remove categories once they're no longer in use? > Regards, > -- > _ ___ Stuart Longland - Systems Engineer > \ /|_) | T: +61 7 3535 9619 > \/ | \ | 38b Douglas Street F: +61 7 3535 9699 > SYSTEMS Milton QLD 4064 http://www.vrt.com.au > > > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming The Go Parallel Website, > sponsored > by Intel and developed in partnership with Slashdot Media, is your hub for > all > things parallel software development, from weekly thought leadership blogs > to > news, videos, case studies, tutorials and more. Take a look and join the > conversation now. http://goparallel.sourceforge.net/ > _______________________________________________ > Log4cpp-devel mailing list > Log...@li... > https://lists.sourceforge.net/lists/listinfo/log4cpp-devel > |
From: <log...@li...> - 2015-03-16 23:33:23
|
Hi Scott and Alexander, On 16/03/15 09:39, log...@li... wrote: > On 3/15/15, 7:25 PM, "log...@li..." <log...@li...> wrote: > >> It appears it would make sense for each transaction state machine to >> have its own log category, as the log messages can then be grepped for >> and it ensures *every* log message from that log instance will have the >> ID prepended. > > I think you want to use a diagnostic context, not a category. Just push and pop the ID with the NDC routines. > > (And you can't really destroy a category, so that's why it's a bad choice to use that.) On 16/03/15 15:57, log...@li... wrote: > The categories in current design are seen as purposed for kind of static > matters, those which do not actively come into the processing and leave > it. There is static helper method to make their creation convenient and > controlled. However, there is no destroy method since the pointer given > out might still be kept somewhere else, out of log4cpp internals. > If you'd like to have an unique id coming along with your log messages, > you could take advantage of the NDC feature. It is exactly purposed for > attaching kind of context to the log messages. It can be turned on and > off from properties file without rebuilding, but note that is linked > with a thread, and not with the particular category. > If your processing is not thread-based, won't it be easier to log the id > just as a part of the message itself? I'm doing some further research into this, NDC sounds closer to what I'm after, however one things that concerns me is that it appears I need to manually push my context onto it each time I enter a context rather than just writing to an object that does this for me. Basically what I'm after, is an object that I can hold either by reference or pointer, that when I write to it, it applies the necessary tagging to identify that line in the log and know where it came from. Categories aren't ideal, but it does achieve this in a structured manner. I don't have to remember to tell it that I'm in a transaction state machine context (which may be in a separate thread) or have to remember to remove it at the end. I'll do some more digging and see what I can uncover, but this looks like it gets at least part-way there. -- _ ___ Stuart Longland - Systems Engineer \ /|_) | T: +61 7 3535 9619 \/ | \ | 38b Douglas Street F: +61 7 3535 9699 SYSTEMS Milton QLD 4064 http://www.vrt.com.au |
From: <log...@li...> - 2015-03-16 23:35:31
|
On 3/16/15, 11:33 PM, "log...@li..." <log...@li...> wrote: > >I'm doing some further research into this, NDC sounds closer to what I'm >after, however one things that concerns me is that it appears I need to >manually push my context onto it each time I enter a context rather than >just writing to an object that does this for me. Yes, but you can wrap all that into your classes via c'tors and d'tors so that it's automatic if you design things right. >Basically what I'm after, is an object that I can hold either by >reference or pointer, that when I write to it, it applies the necessary >tagging to identify that line in the log and know where it came from. You could also wrap the Category interface so that when you call methods on it, it pushes/pops the NDC for you before calling the category methods. -- Scott |
From: <log...@li...> - 2015-03-17 01:14:29
|
On 17/03/15 09:35, log...@li... wrote: > On 3/16/15, 11:33 PM, "log...@li..." > <log...@li...> wrote: > > >> >> I'm doing some further research into this, NDC sounds closer to what I'm >> after, however one things that concerns me is that it appears I need to >> manually push my context onto it each time I enter a context rather than >> just writing to an object that does this for me. > > Yes, but you can wrap all that into your classes via c'tors and d'tors so > that it's automatic if you design things right. > >> Basically what I'm after, is an object that I can hold either by >> reference or pointer, that when I write to it, it applies the necessary >> tagging to identify that line in the log and know where it came from. > > You could also wrap the Category interface so that when you call methods > on it, it pushes/pops the NDC for you before calling the category methods. Indeed, for now I'll see how the following goes. class LogContext { public: LogContext(log4cpp::Category& log, const std::string& context) : log(log) { log4cpp::NDC::push(context); } ~LogContext() { log4cpp::NDC::pop(); } log4cpp::Category& log; }; The idea being it gets allocated on the stack, and will be popped off when the function exits. This might do the trick. -- _ ___ Stuart Longland - Systems Engineer \ /|_) | T: +61 7 3535 9619 \/ | \ | 38b Douglas Street F: +61 7 3535 9699 SYSTEMS Milton QLD 4064 http://www.vrt.com.au |