很早就希望boost中能有一个log库,昨天看到了这个,高兴了一下 ^_^

     news://news.gmane.org/gmane.comp.lib.boost.user 
   
    Subject: [Review] The review of the Boost.Logging library starts November 7th

    Hi all,
    today starts the review of the Boost.Logging library written by John Torjo.
    It will end on November 16th.

    About the library:

    As applications are becoming more and more complex, logging is more and more
    of a must, in nowadays software.

    The Boost Logging Library is a library that:
    * makes it very easy to declare/define logs
    * allows you very simple access to logs
    * allows you to easily use/manipulate log levels (like, dbg/err/info/etc.)
    * allows for log hierarchies, and for manipulating log hierarchies
    * is thread-safe

    To get you started, here's some basic usage:

    BOOST_LOGL(app,dbg) << "debugging: " << i << '-' << j << std::endl;
    BOOST_LOG(app) << "I just wanted to tell you something....";
    BOOST_LOGL(app,err) << "this is an error!";

    The latest version of the lib can be found here:     http://torjo.com/code/logging.zip

   不过 ,好象高兴得有点早 ,    早上一起来打开 news://news.gmane.org/gmane.comp.lib.boost.devel 就看到下面的Subject: 

    Boost.Logging: formal review(最关键的一句我用红色标出了)。

    Being the author of at least 3 different solution for logging/tracing myself, I do believe it's one of the most important general purpose library in big project development. Unfortunately proposed submission in no way came close to being an acceptable choice. Numerous design and implementation issues, weak user and absent reference documentation and  absent test suite
(last two points is something that review manager is responsible for IMO. No tests or docs - no review. That's it) result in: My vote is NO. Please read further for detailed analysis. 

   这个详细的分析写得很长很长,但很有价值,整理一个目录贴在下面了,具体内容有兴趣的朋友去http://permalink.gmane.org/gmane.comp.lib.boost.devel/134338看。

    I. Design Flaws
        1. Filtering support
        2. Configuration support
        3. Per output configuration.
        4. Internationalization support
        5. File and line
        6. Misfeature: pre-init cashing
        7. Misfeature: log hierarchies
        8. Misfeature: compile-time log support
        9. Interface
        10. Performance
    II. Implementation flaws
        1. File appender hierarchy
        2. Multithreading support implementation
        3 . enabled_logger::m_stream
        4. collection in use
        5. exception support
        5. appender_array   (嘿,有两个第5项,不是我的错,原文如此)
        6. Appenders copying.
        7. #ifdef UNICODE
        8. shared_memory.hpp
        9. Time string cashing
        10. write_msg locking

        看来这个库要评审通过还有些困难,不过这不妨碍我们下一个来尝尝鲜。将logging.zip解压到boost目录下,在 \boost_1_33_0\libs\log\build 目录用 bjam -a  生成所有的目标文件,就可以试试手了。不要copy/paste boost_1_33_0/libs/log/doc/basic_usage.html里代码,有错误。评审时要求  What is your evaluation of the documentation?。而文档上的代码copy/paste后不能用,还真是失败。下面是boost_1_33_0\libs\log\examples\basic_usage例子,很简单,看看感觉如何:

 1 // declare.h - declare the logs
 2 #ifndef SAMPLE_DECLARE_H
 3 #define SAMPLE_DECLARE_H
 4 
 5 #include <boost/log/log.hpp>
 6 
 7 BOOST_DECLARE_LOG(app)
 8 BOOST_DECLARE_LOG(dbg)
 9 BOOST_DECLARE_LOG(info)
10 
11 void init_logs();
12 
13 #endif
14 

 

1 // define.cpp - define the logs
2 #include "declare.h"
3 
4 BOOST_DEFINE_LOG(app, _T("app"))
5 BOOST_DEFINE_LOG(dbg, _T("DEBUG"))
6 BOOST_DEFINE_LOG(info, _T("Inf"))
7 

 

 1 // init.cpp - initialize the logs
 2 //            (where do they output information, and how)
 3 
 4 #include <boost/log/functions.hpp>
 5 
 6 #include <iostream>
 7 
 8 void init_logs() {
 9     using namespace boost::logging;
10 
11     manipulate_logs(_T("*"))
12         // all logs prefix the message by time
13         .add_modifier(prepend_time(_T("$hh:$mm:$ss ")), DEFAULT_INDEX + 1 )
14         // all log' messages are prefixed by the log name ("app", or "DEBUG" or "Inf")
15         .add_modifier(&prepend_prefix)
16         // all messages are written to cout
17         .add_appender(&write_to_cout);
18 
19     // app messages are also written to file 'out.txt'
20     manipulate_logs(_T("app")).add_appender(write_to_file("out.txt") );
21     // dbg messages are also written to Output Debug Window
22 #ifdef BOOST_LOG_WIN32
23     manipulate_logs(_T("DEBUG")).add_appender(write_to_dbg_wnd );
24 #endif
25     flush_log_cache();
26 }
27 

 

 1 // use.cpp - write to the logs
 2 #include "declare.h"
 3 
 4 int main() {
 5     init_logs();
 6 
 7     int i = 1, j = 2, k = 3;
 8     BOOST_LOG(app) << "testing " << i << '-' << j << '-' << k  << std::endl;
 9     BOOST_LOG(dbg) << "this is a debug message, i=" << i << std::endl;
10 
11     BOOST_LOG(info) << "I just wanted to tell you something."  << std::endl;
12     BOOST_LOG(info) << "Logged-on Users approach max. limit"  << std::endl;
13     BOOST_LOG(dbg) << "Too many users!"  << std::endl;
14 
15     BOOST_LOG(app) << "an application message" << std::endl;
16     BOOST_LOG(info) << "a simple info" << std::endl;
17 }
18