2 * Copyright Andrey Semashev 2007 - 2015.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
8 * \file log/trivial.hpp
9 * \author Andrey Semashev
12 * This header defines tools for trivial logging support
15 #ifndef BOOST_LOG_TRIVIAL_HPP_INCLUDED_
16 #define BOOST_LOG_TRIVIAL_HPP_INCLUDED_
20 #include <boost/log/detail/config.hpp>
21 #include <boost/log/keywords/severity.hpp>
22 #include <boost/log/sources/severity_logger.hpp>
23 #include <boost/log/sources/record_ostream.hpp>
24 #include <boost/log/detail/header.hpp>
26 #ifdef BOOST_HAS_PRAGMA_ONCE
30 #if !defined(BOOST_LOG_USE_CHAR)
31 #error Boost.Log: Trivial logging is available for narrow-character builds only. Use advanced initialization routines to setup wide-character logging.
36 BOOST_LOG_OPEN_NAMESPACE
40 //! Trivial severity levels
51 //! Returns stringized enumeration value or \c NULL, if the value is not valid
52 BOOST_LOG_API const char* to_string(severity_level lvl);
54 //! Outputs stringized representation of the severity level to the stream
55 template< typename CharT, typename TraitsT >
56 inline std::basic_ostream< CharT, TraitsT >& operator<< (
57 std::basic_ostream< CharT, TraitsT >& strm, severity_level lvl)
59 const char* str = boost::log::trivial::to_string(lvl);
63 strm << static_cast< int >(lvl);
67 //! Reads stringized representation of the severity level from the stream
68 template< typename CharT, typename TraitsT >
69 BOOST_LOG_API std::basic_istream< CharT, TraitsT >& operator>> (
70 std::basic_istream< CharT, TraitsT >& strm, severity_level& lvl);
72 //! Trivial logger type
73 #if !defined(BOOST_LOG_NO_THREADS)
74 typedef sources::severity_logger_mt< severity_level > logger_type;
76 typedef sources::severity_logger< severity_level > logger_type;
80 * \brief Trivial logger tag
82 * This tag can be used to acquire the logger that is used with lrivial logging macros.
83 * This may be useful when the logger is used with other macros which require a logger.
88 typedef trivial::logger_type logger_type;
91 * Returns a reference to the trivial logger instance
93 static BOOST_LOG_API logger_type& get();
95 // Implementation details - never use these
96 #if !defined(BOOST_LOG_DOXYGEN_PASS)
97 enum registration_line_t { registration_line = __LINE__ };
98 static const char* registration_file() { return __FILE__; }
99 static BOOST_LOG_API logger_type construct_logger();
104 * The macro is used to initiate logging. The \c lvl argument of the macro specifies one of the following
105 * severity levels: \c trace, \c debug, \c info, \c warning, \c error or \c fatal (see \c severity_level enum).
106 * Following the macro, there may be a streaming expression that composes the record message string. For example:
109 * BOOST_LOG_TRIVIAL(info) << "Hello, world!";
112 #define BOOST_LOG_TRIVIAL(lvl)\
113 BOOST_LOG_STREAM_WITH_PARAMS(::boost::log::trivial::logger::get(),\
114 (::boost::log::keywords::severity = ::boost::log::trivial::lvl))
116 } // namespace trivial
118 BOOST_LOG_CLOSE_NAMESPACE // namespace log
122 #include <boost/log/detail/footer.hpp>
123 #if defined(BOOST_LOG_EXPRESSIONS_KEYWORD_HPP_INCLUDED_)
124 #include <boost/log/detail/trivial_keyword.hpp>
127 #endif // BOOST_LOG_TRIVIAL_HPP_INCLUDED_