Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:45:12

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2015.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   log/trivial.hpp
0009  * \author Andrey Semashev
0010  * \date   07.11.2009
0011  *
0012  * This header defines tools for trivial logging support
0013  */
0014 
0015 #ifndef BOOST_LOG_TRIVIAL_HPP_INCLUDED_
0016 #define BOOST_LOG_TRIVIAL_HPP_INCLUDED_
0017 
0018 #include <cstddef>
0019 #include <iosfwd>
0020 #include <ostream>
0021 #include <boost/log/detail/config.hpp>
0022 #include <boost/log/keywords/severity.hpp>
0023 #include <boost/log/sources/severity_logger.hpp>
0024 #include <boost/log/sources/record_ostream.hpp>
0025 #include <boost/log/detail/header.hpp>
0026 
0027 #ifdef BOOST_HAS_PRAGMA_ONCE
0028 #pragma once
0029 #endif
0030 
0031 #if !defined(BOOST_LOG_USE_CHAR)
0032 #error Boost.Log: Trivial logging is available for narrow-character builds only. Use advanced initialization routines to setup wide-character logging.
0033 #endif
0034 
0035 namespace boost {
0036 
0037 BOOST_LOG_OPEN_NAMESPACE
0038 
0039 namespace trivial {
0040 
0041 //! Trivial severity levels
0042 enum severity_level
0043 {
0044     trace,
0045     debug,
0046     info,
0047     warning,
0048     error,
0049     fatal
0050 };
0051 
0052 //! Returns stringized enumeration value or \c NULL, if the value is not valid
0053 template< typename CharT >
0054 BOOST_LOG_API const CharT* to_string(severity_level lvl);
0055 
0056 //! Returns stringized enumeration value or \c NULL, if the value is not valid
0057 inline const char* to_string(severity_level lvl)
0058 {
0059     return boost::log::trivial::to_string< char >(lvl);
0060 }
0061 
0062 //! Parses enumeration value from string and returns \c true on success and \c false otherwise
0063 template< typename CharT >
0064 BOOST_LOG_API bool from_string(const CharT* str, std::size_t len, severity_level& lvl);
0065 
0066 //! Outputs stringized representation of the severity level to the stream
0067 template< typename CharT, typename TraitsT >
0068 inline std::basic_ostream< CharT, TraitsT >& operator<< (
0069     std::basic_ostream< CharT, TraitsT >& strm, severity_level lvl)
0070 {
0071     const CharT* str = boost::log::trivial::to_string< CharT >(lvl);
0072     if (BOOST_LIKELY(!!str))
0073         strm << str;
0074     else
0075         strm << static_cast< int >(lvl);
0076     return strm;
0077 }
0078 
0079 //! Reads stringized representation of the severity level from the stream
0080 template< typename CharT, typename TraitsT >
0081 BOOST_LOG_API std::basic_istream< CharT, TraitsT >& operator>> (
0082     std::basic_istream< CharT, TraitsT >& strm, severity_level& lvl);
0083 
0084 //! Trivial logger type
0085 #if !defined(BOOST_LOG_NO_THREADS)
0086 typedef sources::severity_logger_mt< severity_level > logger_type;
0087 #else
0088 typedef sources::severity_logger< severity_level > logger_type;
0089 #endif
0090 
0091 /*!
0092  * \brief Trivial logger tag
0093  *
0094  * This tag can be used to acquire the logger that is used with trivial logging macros.
0095  * This may be useful when the logger is used with other macros which require a logger.
0096  */
0097 struct logger
0098 {
0099     //! Logger type
0100     typedef trivial::logger_type logger_type;
0101 
0102     /*!
0103      * Returns a reference to the trivial logger instance
0104      */
0105     static BOOST_LOG_API logger_type& get();
0106 
0107     // Implementation details - never use these
0108 #if !defined(BOOST_LOG_DOXYGEN_PASS)
0109     enum registration_line_t { registration_line = __LINE__ };
0110     static const char* registration_file() { return __FILE__; }
0111     static BOOST_LOG_API logger_type construct_logger();
0112 #endif
0113 };
0114 
0115 /*!
0116  * The macro is used to initiate logging. The \c lvl argument of the macro specifies one of the following
0117  * severity levels: \c trace, \c debug, \c info, \c warning, \c error or \c fatal (see \c severity_level enum).
0118  * Following the macro, there may be a streaming expression that composes the record message string. For example:
0119  *
0120  * \code
0121  * BOOST_LOG_TRIVIAL(info) << "Hello, world!";
0122  * \endcode
0123  */
0124 #define BOOST_LOG_TRIVIAL(lvl)\
0125     BOOST_LOG_STREAM_WITH_PARAMS(::boost::log::trivial::logger::get(),\
0126         (::boost::log::keywords::severity = ::boost::log::trivial::lvl))
0127 
0128 } // namespace trivial
0129 
0130 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0131 
0132 } // namespace boost
0133 
0134 #include <boost/log/detail/footer.hpp>
0135 #if defined(BOOST_LOG_EXPRESSIONS_KEYWORD_HPP_INCLUDED_)
0136 #include <boost/log/detail/trivial_keyword.hpp>
0137 #endif
0138 
0139 #endif // BOOST_LOG_TRIVIAL_HPP_INCLUDED_