Boost logo

Boost Users :

Subject: [Boost-users] [Boost.Log] Problem : Logs with channel and severity
From: Aman Feri (feriaman_at_[hidden])
Date: 2010-10-05 11:01:11


Hello.

It's my first post here... I'll try to be quick and sharp.
i apologise if i fail.

I spend a long time reading the Boost.Log documentation, but I'm lost.

I try to generate logs with this Format :
[ProcessId][ThreadId[TimeStamp][Channel][Severity] Text

For now i succeeded this Format :
[ProcessId][ThreadId[TimeStamp][][] Text

Here's what i did.
Header :
-------------------------
class Trace
{
    public :
        enum SeverityLevels {...};
        enum Channels{...};

        typedef boost::log::sources::severity_channel_logger_mt<
            SeverityLevels, // the type of the severity level
            Channels // the type of the channel name
> MyLogger; // logger type

    public :
        static MyLogger m_channel1; // one channel <-> one logger
        static MyLogger m_channel2; // one channel <-> one logger
        ...
    public :
        static void init(); // initialisation
};
-------------------------

Source :
-------------------------
void Trace::init()
{
    boost::log::add_common_attributes();
    init_log_to_file
    (
        ...
        boost::log::keywords::format =
"[%ProcessID%][%ThreadID%][%TimeStamp%][%Channel%][%Severity%]: %_%"
    );
}
-------------------------

And i somewhere implemented a #define that make this compilable :
-------------------------
TRACE(channel_networking,debug) << "Logs enabled" << 4;
-------------------------

The problematic code is that one, that i try to add in my init() function :
-------------------------
boost::shared_ptr< boost::log::sinks::synchronous_sink<
boost::log::sinks::basic_text_file_backend< char > > > pBackend;
pBackend = boost::log::init_log_to_file(...);
pBackend->locked_backend()->set_formatter(boost::log::formatters::stream <<
boost::log::formatters::attr< Channels >("Channel"));
-------------------------
I try here to add a formater to the backend part of the sink i just created
with init_log_to_file(...)

And i somewhere defined this operator :
-------------------------
std::ostream& operator<< (std::ostream& strm, Trace::Channels const& val)
-------------------------

The result is :
- compilation is OK
- linking is OK
- running is OK (no exception throwed)
- but my log file is empty.

Thanks x 1 to every reader of this message.
Thanks x 2 to every answerer to this message
Thanks x 4 to every helper



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