Boost logo

Boost :

From: John Torjo (john.groups_at_[hidden])
Date: 2008-02-06 22:06:07


Scott Woods wrote:
> [This is a continuation of my previous premature post - is there a pill for
> that?]
>
>
>>> - where is the default mode that just works "out of the box"
>>>
>>>
>>>
>> How about this:
>> http://torjo.com/log2/doc/html/scenarios_code.html#scenarios_code_mom
>>
>>
>
> If I could write something like;
>
> #include <boost/logging.hpp>
>
> using ...
>
> void test_mul_levels_one_logger() {
> log() << "hello world";
> }
>
> and this resulted in a file with the content;
>
> 2007-2-7_at_13:33:22 "hello world"
>
>
How 'bout this:

// no levels
#include <boost/logging/out_of_the_box/no_levels.hpp>

int main() {
    int i = 1;
    L_ << "this is so cool " << i++;
    L_ << "this is so cool again " << i++;
}

// if using levels
#include <boost/logging/out_of_the_box/use_levels.hpp>

int main() {
    int i = 1;
    L_(debug) << "this is so cool " << i++;
    L_(info) << "this is so cool again " << i++;
}

I've attached 2 files - which can be used for the out_of_the_box
scenario you'd like.

Best,
John

-- 
http://John.Torjo.com -- C++ expert
http://blog.torjo.com
... call me only if you want things done right

// out_of_the_box_no_levels.hpp

// Boost Logging library
//
// Author: John Torjo, www.torjo.com
//
// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org for updates, documentation, and revision history.
// See http://www.torjo.com/log2/ for more details

#ifndef JT28092007_out_of_the_box_no_levels_HPP_DEFINED
#define JT28092007_out_of_the_box_no_levels_HPP_DEFINED

#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif

#include <boost/logging/format/named_write.hpp>
typedef boost::logging::named_logger<>::type logger_type;
typedef boost::logging::filter::no_ts filter_type;

namespace boost { namespace logging {
    struct out_of_the_box_logger : logger_type {
        out_of_the_box_logger() {
            writer().write( BOOST_LOG_STR("%time%($hh:$mm.$ss.$mili) [%idx%] |\n"), BOOST_LOG_STR("cout file(log.txt) debug"));
            mark_as_initialized();
        }
    };

    struct do_log {
        static out_of_the_box_logger* l_() { static out_of_the_box_logger i; return &i; }
        static filter_type* l_filter_() { static filter_type f; return &f; }
    };

}}

#define L_ BOOST_LOG_USE_LOG_IF_FILTER( ::boost::logging::do_log::l_(), ::boost::logging::do_log::l_filter_()->is_enabled() )

#endif


// out_of_the_box_use_levels.hpp

// Boost Logging library
//
// Author: John Torjo, www.torjo.com
//
// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org for updates, documentation, and revision history.
// See http://www.torjo.com/log2/ for more details

#ifndef JT28092007_out_of_the_box_use_levels_HPP_DEFINED
#define JT28092007_out_of_the_box_use_levels_HPP_DEFINED

#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif

#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif

#include <boost/logging/format/named_write.hpp>
typedef boost::logging::named_logger<>::type logger_type;
typedef boost::logging::level::holder filter_type;

namespace boost { namespace logging {
    struct out_of_the_box_logger : logger_type {
        out_of_the_box_logger() {
            writer().write( BOOST_LOG_STR("%time%($hh:$mm.$ss.$mili) [%idx%] |\n"), BOOST_LOG_STR("cout file(log.txt) debug"));
            mark_as_initialized();
        }
    };

    struct do_log {
        static out_of_the_box_logger* l_() { static out_of_the_box_logger i; return &i; }
        static filter_type* l_filter_() { static filter_type f; return &f; }
    };

}}

#define L_(lvl) BOOST_LOG_USE_LOG_IF_FILTER( ::boost::logging::do_log::l_(), ::boost::logging::do_log::l_filter_(), lvl )

#endif


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk