Ejemplo n.º 1
0
    template<class msg_type> void operator()(msg_type & str) const {
        bool is_needed = true;
        if ( ! convert::get_underlying_string(str).empty())
            if ( *(convert::get_underlying_string(str).rbegin()) == '\n')
                is_needed = false;

        if ( is_needed)
            convert::write( BOOST_LOG_STR("\n"), str );
    }
Ejemplo n.º 2
0
 template<class msg_type> void operator()(msg_type & str) const {
     convert::write( BOOST_LOG_STR("\n"), str );
 }
Ejemplo n.º 3
0
 // when we enter here, we know the logger is enabled
 hold_string_type gathered_info() {
     hold_string_type str = m_out.str();
     m_gather.do_gather(str);
     return BOOST_LOG_STR("start of ") + str;
 }
Ejemplo n.º 4
0
    void set_format(const hold_string_type & format) {
        // format too big
        BOOST_ASSERT( format.size() < 64);
        m_format.clear();

        m_day = -1; m_month = -1; m_yy = -1; m_yyyy = -1; m_hour = -1; m_min = -1; m_sec = -1;m_millisec = -1;m_microsec = -1;m_nanosec = -1;

        typedef hold_string_type::size_type uint;
        uint day_idx    = format.find(BOOST_LOG_STR("$dd"));
        uint month_idx  = format.find(BOOST_LOG_STR("$MM"));
        uint yy_idx     = format.find(BOOST_LOG_STR("$yy"));
        uint yyyy_idx   = format.find(BOOST_LOG_STR("$yyyy"));
        uint hour_idx   = format.find(BOOST_LOG_STR("$hh"));
        uint min_idx    = format.find(BOOST_LOG_STR("$mm"));
        uint sec_idx    = format.find(BOOST_LOG_STR("$ss"));
        uint millisec_idx    = format.find(BOOST_LOG_STR("$mili"));
        uint microsec_idx    = format.find(BOOST_LOG_STR("$micro"));
        uint nanosec_idx    = format.find(BOOST_LOG_STR("$nano"));

        typedef std::vector<index_info> array;
        array indexes;
        if ( day_idx != hold_string_type::npos)
            indexes.push_back( index_info(day_idx, &m_day) );
        if ( month_idx != hold_string_type::npos)
            indexes.push_back( index_info(month_idx, &m_month) );

        if ( yy_idx != hold_string_type::npos || yyyy_idx != hold_string_type::npos) {
            if ( yyyy_idx  != hold_string_type::npos)
                indexes.push_back( index_info(yyyy_idx, &m_yyyy, 4) );
            else
                indexes.push_back( index_info(yy_idx, &m_yy) );
        }

        if ( hour_idx != hold_string_type::npos)
            indexes.push_back( index_info(hour_idx, &m_hour ) );
        if ( min_idx != hold_string_type::npos)
            indexes.push_back( index_info(min_idx, &m_min) );
        if ( sec_idx != hold_string_type::npos)
            indexes.push_back( index_info(sec_idx, &m_sec) );
        if ( millisec_idx != hold_string_type::npos)
            indexes.push_back( index_info(millisec_idx, &m_millisec, 4, 3) );
        if ( microsec_idx != hold_string_type::npos)
            indexes.push_back( index_info(microsec_idx, &m_microsec, 5, 6) );
        if ( nanosec_idx != hold_string_type::npos)
            indexes.push_back( index_info(nanosec_idx, &m_nanosec, 4, 9) );

        std::sort( indexes.begin(), indexes.end(), index_info::by_index);
        
        // create the format string, that we can actually pass to sprintf 
        uint prev_idx = 0;
        int idx = 0;
        for ( array::iterator begin = indexes.begin(), end = indexes.end(); begin != end; ++begin) {
            m_format += format.substr( prev_idx, begin->src_idx - prev_idx);
            *begin->format_idx = idx;
            std::basic_ostringstream<char_type> cur_sprintf_format;
            cur_sprintf_format << BOOST_LOG_STR("%0") << begin->size << BOOST_LOG_STR("d");
            m_format += cur_sprintf_format.str();
            prev_idx = begin->src_idx + begin->advance_size + 1;
            ++idx;
        }

        m_format += format.substr(prev_idx);
    }
Ejemplo n.º 5
0
 stream_type & get() {
     stream_type & val = *(m_cache.get());
     val.str( BOOST_LOG_STR("") );
     return val;
 }
Ejemplo n.º 6
0
    void init() {
        m_format_before
            .add( BOOST_LOG_STR("idx"), formatter::idx() )
            .add( BOOST_LOG_STR("time"), ::boost::logging::detail::formatter_time_type( BOOST_LOG_STR("$hh:$mm:$ss") ) )
            .add( BOOST_LOG_STR("thread_id"), formatter::thread_id() );

        m_format_after
            .add( BOOST_LOG_STR("idx"), formatter::idx_t<formatter::do_convert_format::append>() )
            .add( BOOST_LOG_STR("time"), ::boost::logging::detail::formatter_time_type_append( BOOST_LOG_STR("$hh:$mm:$ss") ) )
            .add( BOOST_LOG_STR("thread_id"), formatter::thread_id_t<formatter::do_convert_format::append>() );

        m_destination
            .add( BOOST_LOG_STR("file"), destination::file("out.txt") )
            .add( BOOST_LOG_STR("file2"), destination::file("out.txt") )
            .add( BOOST_LOG_STR("rol_file"), destination::rolling_file("out.txt") )
            .add( BOOST_LOG_STR("rol_file2"), destination::rolling_file("out.txt") )
            .add( BOOST_LOG_STR("cout"), destination::cout() )
            .add( BOOST_LOG_STR("cerr"), destination::cerr() )
            .add( BOOST_LOG_STR("debug"), destination::dbg_window() );
    }