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_
21 #include <boost/log/detail/config.hpp>
22 #include <boost/log/keywords/severity.hpp>
23 #include <boost/log/sources/severity_logger.hpp>
24 #include <boost/log/sources/record_ostream.hpp>
25 #include <boost/log/detail/header.hpp>
27 #ifdef BOOST_HAS_PRAGMA_ONCE
31 #if !defined(BOOST_LOG_USE_CHAR)
32 #error Boost.Log: Trivial logging is available for narrow-character builds only. Use advanced initialization routines to setup wide-character logging.
37 BOOST_LOG_OPEN_NAMESPACE
41 //! Trivial severity levels
52 //! Returns stringized enumeration value or \c NULL, if the value is not valid
53 template< typename CharT >
54 BOOST_LOG_API const CharT* to_string(severity_level lvl);
56 //! Returns stringized enumeration value or \c NULL, if the value is not valid
57 inline const char* to_string(severity_level lvl)
59 return boost::log::trivial::to_string< char >(lvl);
62 //! Parses enumeration value from string and returns \c true on success and \c false otherwise
63 template< typename CharT >
64 BOOST_LOG_API bool from_string(const CharT* str, std::size_t len, severity_level& lvl);
66 //! Outputs stringized representation of the severity level to the stream
67 template< typename CharT, typename TraitsT >
68 inline std::basic_ostream< CharT, TraitsT >& operator<< (
69 std::basic_ostream< CharT, TraitsT >& strm, severity_level lvl)
71 const CharT* str = boost::log::trivial::to_string< CharT >(lvl);
72 if (BOOST_LIKELY(!!str))
75 strm << static_cast< int >(lvl);
79 //! Reads stringized representation of the severity level from the stream
80 template< typename CharT, typename TraitsT >
81 BOOST_LOG_API std::basic_istream< CharT, TraitsT >& operator>> (
82 std::basic_istream< CharT, TraitsT >& strm, severity_level& lvl);
84 //! Trivial logger type
85 #if !defined(BOOST_LOG_NO_THREADS)
86 typedef sources::severity_logger_mt< severity_level > logger_type;
88 typedef sources::severity_logger< severity_level > logger_type;
92 * \brief Trivial logger tag
94 * This tag can be used to acquire the logger that is used with lrivial logging macros.
95 * This may be useful when the logger is used with other macros which require a logger.
100 typedef trivial::logger_type logger_type;
103 * Returns a reference to the trivial logger instance
105 static BOOST_LOG_API logger_type& get();
107 // Implementation details - never use these
108 #if !defined(BOOST_LOG_DOXYGEN_PASS)
109 enum registration_line_t { registration_line = __LINE__ };
110 static const char* registration_file() { return __FILE__; }
111 static BOOST_LOG_API logger_type construct_logger();
116 * The macro is used to initiate logging. The \c lvl argument of the macro specifies one of the following
117 * severity levels: \c trace, \c debug, \c info, \c warning, \c error or \c fatal (see \c severity_level enum).
118 * Following the macro, there may be a streaming expression that composes the record message string. For example:
121 * BOOST_LOG_TRIVIAL(info) << "Hello, world!";
124 #define BOOST_LOG_TRIVIAL(lvl)\
125 BOOST_LOG_STREAM_WITH_PARAMS(::boost::log::trivial::logger::get(),\
126 (::boost::log::keywords::severity = ::boost::log::trivial::lvl))
128 } // namespace trivial
130 BOOST_LOG_CLOSE_NAMESPACE // namespace log
134 #include <boost/log/detail/footer.hpp>
135 #if defined(BOOST_LOG_EXPRESSIONS_KEYWORD_HPP_INCLUDED_)
136 #include <boost/log/detail/trivial_keyword.hpp>
139 #endif // BOOST_LOG_TRIVIAL_HPP_INCLUDED_