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)
9 * \author Andrey Semashev
12 * \brief This header is the Boost.Log library implementation, see the library documentation
13 * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
16 #include <boost/log/detail/config.hpp>
18 #if defined(BOOST_LOG_USE_CHAR)
22 #include <boost/log/trivial.hpp>
23 #include <boost/log/sources/global_logger_storage.hpp>
24 #include <boost/log/detail/header.hpp>
28 BOOST_LOG_OPEN_NAMESPACE
32 //! Initialization routine
33 BOOST_LOG_API logger::logger_type logger::construct_logger()
35 return logger_type(keywords::severity = info);
38 //! Returns a reference to the trivial logger instance
39 BOOST_LOG_API logger::logger_type& logger::get()
41 return log::sources::aux::logger_singleton< logger >::get();
44 BOOST_LOG_ANONYMOUS_NAMESPACE {
46 BOOST_CONSTEXPR_OR_CONST unsigned int names_count = 6;
48 template< typename CharT >
49 struct severity_level_names
51 static const CharT names[names_count][8];
54 template< typename CharT >
55 const CharT severity_level_names< CharT >::names[names_count][8] =
57 { 't', 'r', 'a', 'c', 'e', 0 },
58 { 'd', 'e', 'b', 'u', 'g', 0 },
59 { 'i', 'n', 'f', 'o', 0 },
60 { 'w', 'a', 'r', 'n', 'i', 'n', 'g', 0 },
61 { 'e', 'r', 'r', 'o', 'r', 0 },
62 { 'f', 'a', 't', 'a', 'l', 0 }
67 template< typename CharT >
68 BOOST_LOG_API const CharT* to_string(severity_level lvl)
70 typedef severity_level_names< CharT > level_names;
71 if (BOOST_LIKELY(static_cast< unsigned int >(lvl) < names_count))
72 return level_names::names[static_cast< unsigned int >(lvl)];
76 //! Parses enumeration value from string and returns \c true on success and \c false otherwise
77 template< typename CharT >
78 BOOST_LOG_API bool from_string(const CharT* str, std::size_t len, severity_level& lvl)
80 typedef severity_level_names< CharT > level_names;
81 typedef std::char_traits< CharT > char_traits;
85 if (char_traits::compare(str, level_names::names[0], len) == 0)
86 lvl = static_cast< severity_level >(0);
87 else if (char_traits::compare(str, level_names::names[1], len) == 0)
88 lvl = static_cast< severity_level >(1);
89 else if (char_traits::compare(str, level_names::names[4], len) == 0)
90 lvl = static_cast< severity_level >(4);
91 else if (char_traits::compare(str, level_names::names[5], len) == 0)
92 lvl = static_cast< severity_level >(5);
99 if (char_traits::compare(str, level_names::names[2], len) == 0)
100 lvl = static_cast< severity_level >(2);
107 if (char_traits::compare(str, level_names::names[3], len) == 0)
108 lvl = static_cast< severity_level >(3);
118 template< typename CharT, typename TraitsT >
119 BOOST_LOG_API std::basic_istream< CharT, TraitsT >& operator>> (
120 std::basic_istream< CharT, TraitsT >& strm, severity_level& lvl)
122 if (BOOST_LIKELY(strm.good()))
124 typedef std::basic_string< CharT, TraitsT > string_type;
127 if (BOOST_UNLIKELY(!boost::log::trivial::from_string(str.data(), str.size(), lvl)))
128 strm.setstate(std::ios_base::failbit);
134 template BOOST_LOG_API const char* to_string< char >(severity_level lvl);
135 template BOOST_LOG_API bool from_string< char >(const char* begin, std::size_t len, severity_level& lvl);
136 template BOOST_LOG_API std::basic_istream< char, std::char_traits< char > >&
137 operator>> < char, std::char_traits< char > > (
138 std::basic_istream< char, std::char_traits< char > >& strm, severity_level& lvl);
139 #ifdef BOOST_LOG_USE_WCHAR_T
140 template BOOST_LOG_API const wchar_t* to_string< wchar_t >(severity_level lvl);
141 template BOOST_LOG_API bool from_string< wchar_t >(const wchar_t* begin, std::size_t len, severity_level& lvl);
142 template BOOST_LOG_API std::basic_istream< wchar_t, std::char_traits< wchar_t > >&
143 operator>> < wchar_t, std::char_traits< wchar_t > > (
144 std::basic_istream< wchar_t, std::char_traits< wchar_t > >& strm, severity_level& lvl);
147 } // namespace trivial
149 BOOST_LOG_CLOSE_NAMESPACE // namespace log
153 #include <boost/log/detail/footer.hpp>
155 #endif // defined(BOOST_LOG_USE_CHAR)