boost logging from shared libraries
First, I wasn't sure where would be the most appropriate place to post this question, so I apologize if it's gone to the wrong place. I'm trying to figure out how to put logging statements in some shared libraries which are then controlled via manipulate_logs() calls an the executable that uses the libraries. It appears, after some rudimentary experiments, that this does not work, and I was hoping to find out if there is a way to do it. The logging system, of course, does log manipulation using log names and regular expression matching. As such, I assumed that logs were statically allocated and, in some way, all registered with some central registry which made them all available via their names. Stepping through logging calls in the libraries seems to indicate that logging code is being accessed and, as far as I can tell, the logs are "enabled" and, in fact, trying to log messages (to cout, for what it's worth). However, I don't see anything printed except for log messages genereted from the executable's source code. So, is what I'm trying to do even feasible? I would love to be able to have diagnostics built into my libraries which I could dis/enable as necessary from the executive level. Hopefully I'm just missing something simple. Thanks. -- Austin Bingham "If I were creating the world I wouldn't mess about with butterflies and daffodils. I would have started with lasers, eight o'clock, Day One!" Evil
I have some dll's that have their own logs (each dll has a distinct namespace), they can be enabled/disabled with enable_log()/disable_log(). The main program has yet another set of logs. Just make sure that you have the proper appender for your dll logs. Sorry if this is not relevant to your problem. Oliver -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Austin Bingham Sent: August 17, 2005 10:58 AM To: boost-users@lists.boost.org; john@torjo.com Subject: [Boost-users] boost logging from shared libraries First, I wasn't sure where would be the most appropriate place to post this question, so I apologize if it's gone to the wrong place. I'm trying to figure out how to put logging statements in some shared libraries which are then controlled via manipulate_logs() calls an the executable that uses the libraries. It appears, after some rudimentary experiments, that this does not work, and I was hoping to find out if there is a way to do it. The logging system, of course, does log manipulation using log names and regular expression matching. As such, I assumed that logs were statically allocated and, in some way, all registered with some central registry which made them all available via their names. Stepping through logging calls in the libraries seems to indicate that logging code is being accessed and, as far as I can tell, the logs are "enabled" and, in fact, trying to log messages (to cout, for what it's worth). However, I don't see anything printed except for log messages genereted from the executable's source code. So, is what I'm trying to do even feasible? I would love to be able to have diagnostics built into my libraries which I could dis/enable as necessary from the executive level. Hopefully I'm just missing something simple. Thanks. -- Austin Bingham "If I were creating the world I wouldn't mess about with butterflies and daffodils. I would have started with lasers, eight o'clock, Day One!" Evil _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thanks, I think this is relevant to my problem. When you say "proper
appender for my dll logs", are you indicating that there is somehow a
special appender for shared library logs? Or just that I need to have
some appender for them? In my executable, I've got something to the
effect of:
manipulate_logs("*").add_appender(write_to_cout);
This is working for the logs messages from the executable, but not
from the shared libs. Is there something else I need to do?
Austin
On 8/17/05, Oliver Schoenborn
I have some dll's that have their own logs (each dll has a distinct namespace), they can be enabled/disabled with enable_log()/disable_log(). The main program has yet another set of logs. Just make sure that you have the proper appender for your dll logs. Sorry if this is not relevant to your problem. Oliver
I don't use manipulate_logs(), is this a more recent version? I'm using 1.33 of logging lib. Here is the code I use: // dll.h namespace co { BOOST_DECLARE_LOG_DLL(dbg) BOOST_DECLARE_LOG_DLL(info) BOOST_DECLARE_LOG_DLL(warn) BOOST_DECLARE_LOG_DLL(err) // init logs of dll: YOUR_DLL_DECL void initLogsDefault(); } // dll.cpp namespace co { BOOST_DEFINE_LOG_DLL(dbg, "dbg.common") BOOST_DEFINE_LOG_DLL(info, "info.common") BOOST_DEFINE_LOG_DLL(warn, "warn.common") BOOST_DEFINE_LOG_DLL(err, "err.common") void initLogsDefault() { // default on Windows is full buffering; disable this // for stdout and stderr setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); using namespace boost::logging; // all logs prefix the message by time add_modifier("*", prepend_time("$hh:$mm:$ss "), DEFAULT_INDEX + 1 ); // all log' messages are prefixed by the log name add_modifier("*", &prepend_prefix); } } // main.cpp void initLogs() { co::initLogsDefault(); using namespace boost::logging; add_appender("*", write_to_cout); flush_log_cache(); } int main() { initLogs(); ... } As you can see, you don't even need to enable anything, that's the default. However you do need appenders. The BOOST_DEFINE_LOG_DLL and declare counterpart were explained in my last email on same topic, and YOUR_DLL_DECL is __decl_export/import. Let me know if that still doesn't work for you. Oliver
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Austin Bingham Sent: August 18, 2005 7:00 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost logging from shared libraries
Thanks, I think this is relevant to my problem. When you say "proper appender for my dll logs", are you indicating that there is somehow a special appender for shared library logs? Or just that I need to have some appender for them? In my executable, I've got something to the effect of:
manipulate_logs("*").add_appender(write_to_cout);
This is working for the logs messages from the executable, but not from the shared libs. Is there something else I need to do?
Austin
On 8/17/05, Oliver Schoenborn
wrote: I have some dll's that have their own logs (each dll has a distinct namespace), they can be enabled/disabled with enable_log()/disable_log(). The main program has yet another set of logs. Just make sure that you have the proper appender for your dll logs. Sorry if this is not relevant to your problem. Oliver
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I just remembered that for windows I had to create a version of
BOOST_DECLARE_LOG and BOOST_DEFINE_LOG for dll's, as in:
#define BOOST_DECLARE_LOG_DLL(log_name) \
struct log_name ## _log_class { enum { is_compile_time = 0, is_enabled =
1 }; }; \
BOOST_LOG_USE_IN_DLL_DECL ::boost::logging::logger & log_name##_log();
// note: you need to include
participants (2)
-
Austin Bingham
-
Oliver Schoenborn