Chris@16: /* Chris@101: * Copyright Andrey Semashev 2007 - 2015. Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: /*! Chris@16: * \file log/trivial.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 07.11.2009 Chris@16: * Chris@16: * This header defines tools for trivial logging support Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_TRIVIAL_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_TRIVIAL_HPP_INCLUDED_ Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: #if !defined(BOOST_LOG_USE_CHAR) Chris@16: #error Boost.Log: Trivial logging is available for narrow-character builds only. Use advanced initialization routines to setup wide-character logging. Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: BOOST_LOG_OPEN_NAMESPACE Chris@16: Chris@16: namespace trivial { Chris@16: Chris@16: //! Trivial severity levels Chris@16: enum severity_level Chris@16: { Chris@16: trace, Chris@16: debug, Chris@16: info, Chris@16: warning, Chris@16: error, Chris@16: fatal Chris@16: }; Chris@16: Chris@16: //! Returns stringized enumeration value or \c NULL, if the value is not valid Chris@16: BOOST_LOG_API const char* to_string(severity_level lvl); Chris@16: Chris@16: //! Outputs stringized representation of the severity level to the stream Chris@16: template< typename CharT, typename TraitsT > Chris@16: inline std::basic_ostream< CharT, TraitsT >& operator<< ( Chris@16: std::basic_ostream< CharT, TraitsT >& strm, severity_level lvl) Chris@16: { Chris@16: const char* str = boost::log::trivial::to_string(lvl); Chris@16: if (str) Chris@16: strm << str; Chris@16: else Chris@16: strm << static_cast< int >(lvl); Chris@16: return strm; Chris@16: } Chris@16: Chris@16: //! Reads stringized representation of the severity level from the stream Chris@16: template< typename CharT, typename TraitsT > Chris@16: BOOST_LOG_API std::basic_istream< CharT, TraitsT >& operator>> ( Chris@16: std::basic_istream< CharT, TraitsT >& strm, severity_level& lvl); Chris@16: Chris@16: //! Trivial logger type Chris@16: #if !defined(BOOST_LOG_NO_THREADS) Chris@16: typedef sources::severity_logger_mt< severity_level > logger_type; Chris@16: #else Chris@16: typedef sources::severity_logger< severity_level > logger_type; Chris@16: #endif Chris@16: Chris@16: /*! Chris@16: * \brief Trivial logger tag Chris@16: * Chris@16: * This tag can be used to acquire the logger that is used with lrivial logging macros. Chris@16: * This may be useful when the logger is used with other macros which require a logger. Chris@16: */ Chris@16: struct logger Chris@16: { Chris@16: //! Logger type Chris@16: typedef trivial::logger_type logger_type; Chris@16: Chris@16: /*! Chris@16: * Returns a reference to the trivial logger instance Chris@16: */ Chris@16: static BOOST_LOG_API logger_type& get(); Chris@16: Chris@16: // Implementation details - never use these Chris@16: #if !defined(BOOST_LOG_DOXYGEN_PASS) Chris@16: enum registration_line_t { registration_line = __LINE__ }; Chris@16: static const char* registration_file() { return __FILE__; } Chris@16: static BOOST_LOG_API logger_type construct_logger(); Chris@16: #endif Chris@16: }; Chris@16: Chris@16: /*! Chris@16: * The macro is used to initiate logging. The \c lvl argument of the macro specifies one of the following Chris@16: * severity levels: \c trace, \c debug, \c info, \c warning, \c error or \c fatal (see \c severity_level enum). Chris@16: * Following the macro, there may be a streaming expression that composes the record message string. For example: Chris@16: * Chris@16: * \code Chris@16: * BOOST_LOG_TRIVIAL(info) << "Hello, world!"; Chris@16: * \endcode Chris@16: */ Chris@16: #define BOOST_LOG_TRIVIAL(lvl)\ Chris@16: BOOST_LOG_STREAM_WITH_PARAMS(::boost::log::trivial::logger::get(),\ Chris@16: (::boost::log::keywords::severity = ::boost::log::trivial::lvl)) Chris@16: Chris@16: } // namespace trivial Chris@16: Chris@16: BOOST_LOG_CLOSE_NAMESPACE // namespace log Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: #if defined(BOOST_LOG_EXPRESSIONS_KEYWORD_HPP_INCLUDED_) Chris@16: #include Chris@16: #endif Chris@16: Chris@16: #endif // BOOST_LOG_TRIVIAL_HPP_INCLUDED_