From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/log/example/basic_usage/Jamfile.v2 | 58 ++++++++++ src/boost/libs/log/example/basic_usage/main.cpp | 129 ++++++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 src/boost/libs/log/example/basic_usage/Jamfile.v2 create mode 100644 src/boost/libs/log/example/basic_usage/main.cpp (limited to 'src/boost/libs/log/example/basic_usage') diff --git a/src/boost/libs/log/example/basic_usage/Jamfile.v2 b/src/boost/libs/log/example/basic_usage/Jamfile.v2 new file mode 100644 index 00000000..56a9d5eb --- /dev/null +++ b/src/boost/libs/log/example/basic_usage/Jamfile.v2 @@ -0,0 +1,58 @@ +# +# Copyright Andrey Semashev 2007 - 2015. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) +# + +import ../../build/log-platform-config ; + +project + : requirements + @log-platform-config.set-platform-defines + + shared:BOOST_ALL_DYN_LINK + msvc:_SCL_SECURE_NO_WARNINGS + msvc:_SCL_SECURE_NO_DEPRECATE + msvc:_CRT_SECURE_NO_WARNINGS + msvc:_CRT_SECURE_NO_DEPRECATE + msvc:/bigobj + msvc:/wd4503 # decorated name length exceeded, name was truncated + msvc:/wd4456 # declaration of 'A' hides previous local declaration + msvc:/wd4459 # declaration of 'A' hides global declaration + msvc:/wd4003 # not enough actual parameters for macro 'X' - caused by BOOST_PP_IS_EMPTY and BOOST_PP_IS_BEGIN_PARENS which are used by Fusion + intel-win:_SCL_SECURE_NO_WARNINGS + intel-win:_SCL_SECURE_NO_DEPRECATE + intel-win:_CRT_SECURE_NO_WARNINGS + intel-win:_CRT_SECURE_NO_DEPRECATE + darwin:-ftemplate-depth-1024 + gcc:-ftemplate-depth-1024 + gcc:-fno-strict-aliasing # avoids strict aliasing violations in other Boost components + + # Disable Intel warnings: + # warning #177: function "X" was declared but never referenced + # warning #780: using-declaration ignored -- it refers to the current namespace + # warning #2196: routine is both "inline" and "noinline" + # remark #1782: #pragma once is obsolete. Use #ifndef guard instead. + # remark #193: zero used for undefined preprocessing identifier "X" + # remark #304: access control not specified ("public" by default) + # remark #981: operands are evaluated in unspecified order + # remark #1418: external function definition with no prior declaration + # Mostly comes from Boost.Phoenix: warning #411: class "X" defines no constructor to initialize the following: reference member "Y"... + # warning #734: "X" (declared at line N of "file.hpp"), required for copy that was eliminated, is inaccessible + # warning #279: controlling expression is constant + intel-win:"/Qwd177,780,2196,1782,193,304,981,1418,411,734,279" + intel-linux:"-wd177,780,2196,1782,193,304,981,1418,411,734,279" + intel-darwin:"-wd177,780,2196,1782,193,304,981,1418,411,734,279" + + /boost/log//boost_log + /boost/log//boost_log_setup + /boost/date_time//boost_date_time + /boost/filesystem//boost_filesystem + single:BOOST_LOG_NO_THREADS + multi:/boost/thread//boost_thread + ; + +exe basic_usage + : main.cpp + ; diff --git a/src/boost/libs/log/example/basic_usage/main.cpp b/src/boost/libs/log/example/basic_usage/main.cpp new file mode 100644 index 00000000..3dc8a5af --- /dev/null +++ b/src/boost/libs/log/example/basic_usage/main.cpp @@ -0,0 +1,129 @@ +/* + * Copyright Andrey Semashev 2007 - 2015. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + */ +/*! + * \file main.cpp + * \author Andrey Semashev + * \date 11.11.2007 + * + * \brief An example of basic library usage. See the library tutorial for expanded + * comments on this code. It may also be worthwhile reading the Wiki requirements page: + * http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Boost.Logging + */ + +// #define BOOST_LOG_USE_CHAR +// #define BOOST_ALL_DYN_LINK 1 +// #define BOOST_LOG_DYN_LINK 1 + +#include + +#include +#include + +#include +#include +#include + +#include +#include + +#include + +#include + +namespace logging = boost::log; +namespace sinks = boost::log::sinks; +namespace attrs = boost::log::attributes; +namespace src = boost::log::sources; +namespace expr = boost::log::expressions; +namespace keywords = boost::log::keywords; + +using boost::shared_ptr; + +// Here we define our application severity levels. +enum severity_level +{ + normal, + notification, + warning, + error, + critical +}; + +// The formatting logic for the severity level +template< typename CharT, typename TraitsT > +inline std::basic_ostream< CharT, TraitsT >& operator<< ( + std::basic_ostream< CharT, TraitsT >& strm, severity_level lvl) +{ + static const char* const str[] = + { + "normal", + "notification", + "warning", + "error", + "critical" + }; + if (static_cast< std::size_t >(lvl) < (sizeof(str) / sizeof(*str))) + strm << str[lvl]; + else + strm << static_cast< int >(lvl); + return strm; +} + +int main(int argc, char* argv[]) +{ + // This is a simple tutorial/example of Boost.Log usage + + // The first thing we have to do to get using the library is + // to set up the logging sinks - i.e. where the logs will be written to. + logging::add_console_log(std::clog, keywords::format = "%TimeStamp%: %Message%"); + + // One can also use lambda expressions to setup filters and formatters + logging::add_file_log + ( + "sample.log", + keywords::filter = expr::attr< severity_level >("Severity") >= warning, + keywords::format = expr::stream + << expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d, %H:%M:%S.%f") + << " [" << expr::format_date_time< attrs::timer::value_type >("Uptime", "%O:%M:%S") + << "] [" << expr::format_named_scope("Scope", keywords::format = "%n (%f:%l)") + << "] <" << expr::attr< severity_level >("Severity") + << "> " << expr::message +/* + keywords::format = expr::format("%1% [%2%] [%3%] <%4%> %5%") + % expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d, %H:%M:%S.%f") + % expr::format_date_time< attrs::timer::value_type >("Uptime", "%O:%M:%S") + % expr::format_named_scope("Scope", keywords::format = "%n (%f:%l)") + % expr::attr< severity_level >("Severity") + % expr::message +*/ + ); + + // Also let's add some commonly used attributes, like timestamp and record counter. + logging::add_common_attributes(); + logging::core::get()->add_thread_attribute("Scope", attrs::named_scope()); + + BOOST_LOG_FUNCTION(); + + // Now our logs will be written both to the console and to the file. + // Let's do a quick test and output something. We have to create a logger for this. + src::logger lg; + + // And output... + BOOST_LOG(lg) << "Hello, World!"; + + // Now, let's try logging with severity + src::severity_logger< severity_level > slg; + + // Let's pretend we also want to profile our code, so add a special timer attribute. + slg.add_attribute("Uptime", attrs::timer()); + + BOOST_LOG_SEV(slg, normal) << "A normal severity message, will not pass to the file"; + BOOST_LOG_SEV(slg, warning) << "A warning severity message, will pass to the file"; + BOOST_LOG_SEV(slg, error) << "An error severity message, will pass to the file"; + + return 0; +} -- cgit v1.2.3