Boost logo

Boost Users :

From: Oliver Schoenborn (oliver.schoenborn_at_[hidden])
Date: 2005-08-22 08:36:46


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_at_[hidden]
> [mailto:boost-users-bounces_at_[hidden]] On Behalf Of
> Austin Bingham
> Sent: August 18, 2005 7:00 AM
> To: boost-users_at_[hidden]
> 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 <oliver.schoenborn_at_[hidden]> 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_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net