Boost Logging library

Related tags

Logging log
Overview

Boost.Log

Boost.Log, part of collection of the Boost C++ Libraries, provides tools for adding logging to libraries and applications.

Directories

  • build - Boost.Log build scripts
  • config - Boost.Log build configuration code and scripts
  • doc - QuickBook documentation sources
  • example - Boost.Log examples
  • include - Interface headers of Boost.Log
  • src - Compilable source code of Boost.Log
  • test - Boost.Log unit tests

More information

Build status

Branch GitHub Actions AppVeyor Test Matrix Dependencies
master GitHub Actions AppVeyor Tests Dependencies
develop GitHub Actions AppVeyor Tests Dependencies

License

Distributed under the Boost Software License, Version 1.0.

Comments
  • Combining expressions with parse_filter

    Combining expressions with parse_filter

    I am working with a filter that consists of two parts.

    The first part is known and can be written using the expression language. The second part is a user-provided string, so I need to use parse_filter.

    Is it possible to combine an expression with the result of parse_filter?

    opened by fsimonis 0
  • Optional std::filesystem

    Optional std::filesystem

    It would be nice if there would be some magic option that will allow to build boost::log with std::filesystem instead of boost::filesystem. This will help with symbol problems in static configuration caused by BOOST_FILESYSTEM_VERSION define.

    opened by Nekto89 2
  • Add support for querying and visiting sinks

    Add support for querying and visiting sinks

    Hi, I would need to allow my application to provide to the end user with a dynamic control on sinks configured in settings file (typically, change the filtering at runtime). For that, I would need to have to list of the configured sinks, but from my searches results on the web, it looks like there is no such a support.

    Would it be possible to add the support for querying and visiting the sinks? If not, what alternative solution would you suggest (if possible, without having to reimplement setup file parser)?

    Thanx in advance

    opened by ropieur 3
  • Unable to see messages properly in event viewer

    Unable to see messages properly in event viewer

    Hi,

    Following are my environment details: I am using Boost Library version 1.77.0 I am using Windows 10 operating system. I am using Visual Studio 2019. The platform toolset is v142 C++ language standard: ISO C++ 17 (/std:c++17) C Language standard: ISO C 17 (2018) (/std:c17) My project is a DLL project where I am using event logging I am also using the following macro: #define BOOST_ALL_DYN_LINK

    I am using custom event logging as described in the following link: https://www.boost.org/doc/libs/1_77_0/libs/log/example/event_log/main.cpp

    I have created a custom message configuration file with the following content: ` ; /* -------------------------------------------------------- ; HEADER SECTION ; */ SeverityNames=(Debug=0x0:AUTO_SCORE_SEVERITY_DEBUG Info=0x0:AUTO_SCORE_SEVERITY_INFO Warning=0x2:AUTO_SCORE_SEVERITY_WARNING Error=0x1:AUTO_SCORE_SEVERITY_ERROR )

    ; /* -------------------------------------------------------- ; MESSAGE DEFINITION SECTION ; */

    MessageIdTypedef=WORD

    MessageId=0x1 SymbolicName=CATEGORY_DEBUG Language=English Debug Message .

    MessageId=0x2 SymbolicName=CATEGORY_INFO Language=English Info Message .

    MessageId=0x3 SymbolicName=CATEGORY_WARNING Language=English Warning Message .

    MessageId=0x4 SymbolicName=CATEGORY_ERROR Language=English Error Message .

    MessageIdTypedef=DWORD

    MessageId=0x100 Severity=Debug Facility=Application SymbolicName=DEBUG_MSG Language=English [%1][%2]: %3 .

    MessageId=0x101 Severity=Info Facility=Application SymbolicName=INFO_MSG Language=English .

    MessageId=0x102 Severity=Warning Facility=Application SymbolicName=WARNING_MSG Language=English [%1][%2]: %3 .

    MessageId=0x103 Severity=Error Facility=Application SymbolicName=ERROR_MSG Language=English [%1][%2]: %3 .

    `

    The logging header file looks like this: ` #pragma once #include #include #include #include <boost/smart_ptr/shared_ptr.hpp> #include <boost/date_time/posix_time/posix_time_types.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time_io.hpp>

    #include <boost/log/common.hpp> #include <boost/log/attributes.hpp> #include <boost/log/expressions.hpp> #include <boost/log/sinks/sync_frontend.hpp> #include <boost/log/sinks/event_log_backend.hpp> #include "autoscore_eventlog_provider/autoscore_eventlog_provider.h"

    // Check windows #if _WIN32 || _WIN64 #if _WIN64 #define ENVIRONMENT64 #else #define ENVIRONMENT32 #endif #endif

    // Check GCC #if GNUC #if x86_64 || ppc64 #define ENVIRONMENT64 #else #define ENVIRONMENT32 #endif #endif

    #if !defined(WIN32_LEAN_AND_MEAN) #define WIN32_LEAN_AND_MEAN #endif

    #include <windows.h>

    namespace autoscore::log { namespace logging = boost::log; namespace attrs = boost::log::attributes; namespace src = boost::log::sources; namespace sinks = boost::log::sinks; namespace expr = boost::log::expressions; namespace keywords = boost::log::keywords;

    // Define application-specific severity levels
    enum severity_level
    {
    	debug,
    	info,
    	warning,
    	error
    };
    
    //Define AutoScore Logging Config
    struct config
    {
    	severity_level min_logging_level;
    	std::string message_file;
    	std::string log_name;
    	std::string log_source;
    	bool enable_win_event_log;
    };
    
    void init_logging(config logging_config);
    
    //[ example_sinks_event_log_facilities
    BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(event_logger, src::severity_logger_mt< severity_level >)
    
    
    /// <summary>
    /// The function raises an event with a debug message
    /// </summary>
    /// <param name="message"></param>
    /// <param name="session_id"></param>
    void log_debug(std::string const& message, std::string const& session_id = "N/A");
    
    /// <summary>
    /// The function raises an event with a info message
    /// </summary>
    /// <param name="message"></param>
    /// <param name="session_id"></param>
    void log_info(std::string const& message, std::string const& session_id = "N/A");
    
    
    /// <summary>
    /// The function raises an event with a warning message
    /// </summary>
    /// <param name="message"></param>
    /// <param name="session_id"></param>
    void log_warning(std::string const& message, std::string const& session_id = "N/A");
    
    
    /// <summary>
    /// The function raises an event with a error message
    /// </summary>
    /// <param name="message"></param>
    /// <param name="session_id"></param>
    void log_error(std::string const& message, std::string const& session_id = "N/A");
    

    } `

    The logging implementation file looks like this: ` #include "pch.h" #include "autoscore_log.h"

    namespace autoscore::log { void init_win_event_log(config const logging_config) { // Create an event log sink boost::shared_ptr< sinks::event_log_backend > backend( new sinks::event_log_backend(( keywords::message_file = logging_config.message_file, //%APPDATA%\Holberg EEG AS\autoSCORE\Logs\autoscore_eventlog_provider.dll keywords::log_name = logging_config.log_name, //Holberg EEG AS keywords::log_source = logging_config.log_source //autoSCORE )) );

        // Create an event composer. It is initialized with the event identifier mapping.
        sinks::event_log::event_composer composer(
            sinks::event_log::direct_event_id_mapping< int >("EventID"));
    
        // For each event described in the message file, set up the insertion string formatters
        composer[DEBUG_MSG]
            % expr::attr< std::string >("TimeStamp")
            % expr::attr< std::string >("SessionID")
            % expr::attr< std::string >("Message");
    
        composer[WARNING_MSG]
            % expr::attr< std::string >("TimeStamp")
            % expr::attr< std::string >("SessionID");
        composer[ERROR_MSG]
            % expr::attr< std::string >("TimeStamp")
            % expr::attr< std::string >("SessionID");
    
        // Then put the composer to the backend
        backend->set_event_composer(composer);
    
        auto severity = boost::log::expressions::attr<severity_level>("Severity");
    
        // We'll have to map our custom levels to the event log event types
        sinks::event_log::custom_event_type_mapping< severity_level > type_mapping("Severity");
        type_mapping[debug] = sinks::event_log::make_event_type(AUTO_SCORE_SEVERITY_DEBUG);
        type_mapping[info] = sinks::event_log::make_event_type(AUTO_SCORE_SEVERITY_INFO);
        type_mapping[warning] = sinks::event_log::make_event_type(AUTO_SCORE_SEVERITY_WARNING);
        type_mapping[error] = sinks::event_log::make_event_type(AUTO_SCORE_SEVERITY_ERROR);
    
        backend->set_event_type_mapper(type_mapping);
    
        // Usually event categories can be restored by the event identifier.
        sinks::event_log::custom_event_category_mapping< int > cat_mapping("EventID");
        cat_mapping[DEBUG_MSG] = sinks::event_log::make_event_category(CATEGORY_DEBUG);
        cat_mapping[INFO_MSG] = sinks::event_log::make_event_category(CATEGORY_INFO);
        cat_mapping[WARNING_MSG] = sinks::event_log::make_event_category(CATEGORY_WARNING);
        cat_mapping[ERROR_MSG] = sinks::event_log::make_event_category(CATEGORY_ERROR);
    
        backend->set_event_category_mapper(cat_mapping);
    
        // Create the frontend for the sink
        boost::shared_ptr< sinks::synchronous_sink< sinks::event_log_backend > > sink(
            new sinks::synchronous_sink< sinks::event_log_backend >(backend));
    
        // Set up filter to pass only records that have the necessary attribute
        sink->set_filter(expr::has_attr< int >("EventID"));
        sink->set_filter(severity >= logging_config.min_logging_level);
    
        logging::core::get()->add_sink(sink);
    }
    
    void init_logging(config const logging_config)
    {
        if (logging_config.enable_win_event_log)
        {
            init_win_event_log(logging_config);
        }
    }
    
    void log_debug(std::string const& message, std::string const& session_id)
    {
        auto time_stamp = boost::posix_time::to_simple_string(boost::posix_time::microsec_clock::local_time());
        BOOST_LOG_SCOPED_THREAD_TAG("EventID", (int)DEBUG_MSG);
        BOOST_LOG_SCOPED_THREAD_TAG("SessionID", session_id);
        BOOST_LOG_SCOPED_THREAD_TAG("TimeStamp", time_stamp);
        BOOST_LOG_SCOPED_THREAD_TAG("Message", message);
        BOOST_LOG_SEV(event_logger::get(), debug) << "[" << time_stamp << "][" << session_id << "]: " << message;
    }
    
    void log_info(std::string const& message, std::string const& session_id)
    {
        auto time_stamp = boost::posix_time::to_simple_string(boost::posix_time::microsec_clock::local_time());
        BOOST_LOG_SCOPED_THREAD_TAG("EventID", (int)INFO_MSG);
        BOOST_LOG_SCOPED_THREAD_TAG("SessionID", session_id);
        BOOST_LOG_SCOPED_THREAD_TAG("TimeStamp", time_stamp);
        BOOST_LOG_SCOPED_THREAD_TAG("Message", message);
        BOOST_LOG_SEV(event_logger::get(), info) << message;
    }
    
    void log_warning(std::string const& message, std::string const& session_id)
    {
        auto time_stamp = boost::posix_time::to_simple_string(boost::posix_time::microsec_clock::local_time());
        BOOST_LOG_SCOPED_THREAD_TAG("EventID", (int)WARNING_MSG);
        BOOST_LOG_SCOPED_THREAD_TAG("SessionID", session_id);
        BOOST_LOG_SCOPED_THREAD_TAG("TimeStamp", time_stamp);
        BOOST_LOG_SEV(event_logger::get(), warning) << message;
    }
    
    void log_error(std::string const& message, std::string const& session_id)
    {
        auto time_stamp = boost::posix_time::to_simple_string(boost::posix_time::microsec_clock::local_time());
        BOOST_LOG_SCOPED_THREAD_TAG("EventID", (int)ERROR_MSG);
        BOOST_LOG_SCOPED_THREAD_TAG("SessionID", session_id);
        BOOST_LOG_SCOPED_THREAD_TAG("TimeStamp", time_stamp);
        BOOST_LOG_SEV(event_logger::get(), error) << message;
    }
    

    }

    `

    I have created the header file and definitions DLL based on the *.mc file and created the registry keys by running the DLL consumer application as administrator.

    I am able to see the events in the event viewer but without any content. I am attaching screen shots of how it looks like.

    I am not sure what is my mistake. Can some one help m event_log_error e?

    opened by humayunkhan 5
  • Rotating log files -- the wrong files are being deleted

    Rotating log files -- the wrong files are being deleted

    When I run the following code https://paste.debian.net/1190133/ the second time, the wrong 00008.log file is deleted.

    After run 1: (I copied the folder ...)

    $ ls -ort logs-first-run/
    -rw-r--r-- 1 mak 16363 20. Mär 11:33 file_00001.log
    -rw-r--r-- 1 mak 16359 20. Mär 11:33 file_00002.log
    -rw-r--r-- 1 mak 16359 20. Mär 11:33 file_00003.log
    -rw-r--r-- 1 mak 16335 20. Mär 11:33 file_00004.log
    -rw-r--r-- 1 mak 16356 20. Mär 11:33 file_00005.log
    -rw-r--r-- 1 mak 16356 20. Mär 11:33 file_00006.log
    -rw-r--r-- 1 mak 16356 20. Mär 11:33 file_00007.log
    -rw-r--r-- 1 mak 16356 20. Mär 11:33 file_00008.log
    

    After run 2:

    $ ls -ort logs/
    -rw-r--r-- 1 mak 16356 20. Mär 11:33 file_00007.log
    -rw-r--r-- 1 mak 16344 20. Mär 11:34 file_00010.log
    -rw-r--r-- 1 mak 16375 20. Mär 11:34 file_00011.log
    -rw-r--r-- 1 mak 16359 20. Mär 11:34 file_00012.log
    -rw-r--r-- 1 mak 16359 20. Mär 11:34 file_00013.log
    -rw-r--r-- 1 mak 16335 20. Mär 11:34 file_00014.log
    -rw-r--r-- 1 mak 16356 20. Mär 11:34 file_00015.log
    -rw-r--r-- 1 mak 16356 20. Mär 11:34 file_00016.log
    -rw-r--r-- 1 mak 16356 20. Mär 11:34 file_00017.log
    -rw-r--r-- 1 mak 16356 20. Mär 11:34 file_00018.log
    

    I am using Boost 1.74.0 from Debian bullseye.

    opened by matthiasklein 1
  • Is `-fno-strict-aliasing` really necessary?

    Is `-fno-strict-aliasing` really necessary?

    The library builds with -fno-strict-aliasing on GCC: https://github.com/boostorg/log/blob/8a880720be5a990fdd0f864244bfff1a39a69d83/build/Jamfile.v2#L202 The comment says that it is because of other Boost libraries but does not name them or link bug reports, making it hard to justify the flag. It should be a good thing to re-raise the issue on the libraries that still had not fixed it, as strict aliasing is a severe violation.

    opened by Kojoley 3
Owner
Boost.org
Boost provides free peer-reviewed portable C++ source libraries.
Boost.org
Reckless logging. Low-latency, high-throughput, asynchronous logging library for C++.

Introduction Reckless is an extremely low-latency, high-throughput logging library. It was created because I needed to perform extensive diagnostic lo

Mattias Flodin 445 Dec 20, 2022
Colorful Logging is a simple and efficient library allowing for logging and benchmarking.

Colorful-Logging "Colorful Logging" is a library allowing for simple and efficient logging as well for benchmarking. What can you use it for? -Obvious

Mateusz Antkiewicz 1 Feb 17, 2022
Yet another logging library.

Blackhole - eating your logs with pleasure Blackhole is an attribute-based logger with strong focus on gaining maximum performance as possible for suc

Evgeny Safronov 191 Dec 20, 2022
A lightweight C++ logging library

Loguru: a lightweight and flexible C++ logging library. At a glance Documentation Documentation can be found at https://emilk.github.io/loguru/index.h

Emil Ernerfeldt 1.5k Jan 7, 2023
Portable, simple and extensible C++ logging library

Plog - portable, simple and extensible C++ logging library Pretty powerful logging library in about 1000 lines of code Introduction Hello log! Feature

Sergey Podobry 1.6k Dec 29, 2022
Fast C++ logging library.

spdlog Very fast, header-only/compiled, C++ logging library. Install Header only version Copy the source folder to your build tree and use a C++11 com

Gabi Melman 16.6k Jan 1, 2023
Asynchronous Low Latency C++ Logging Library

Quill Asynchronous Low Latency C++ Logging Library Introduction Features Performance Supported Platforms And Compilers Basic Usage CMake Integration D

Odysseas Georgoudis 677 Dec 20, 2022
Cute Log is a C++ Library that competes to be a unique logging tool.

Cute Log Cute Log is a C++ Library that competes to be a unique logging tool. Version: 2 Installation Click "Code" on the main repo page (This one.).

null 3 Oct 13, 2022
fmtlog is a performant fmtlib-style logging library with latency in nanoseconds.

fmtlog fmtlog is a performant asynchronous logging library using fmt library format. Features Faster - lower runtime latency than NanoLog and higher t

Meng Rao 443 Jan 6, 2023
Minimalistic logging library with threads and manual callstacks

Minimalistic logging library with threads and manual callstacks

Sergey Kosarevsky 20 Dec 5, 2022
A Fast and Convenient C++ Logging Library for Low-latency or Real-time Environments

xtr What is it? XTR is a C++ logging library aimed at applications with low-latency or real-time requirements. The cost of log statements is minimised

null 10 Jul 17, 2022
logog is a portable C++ library to facilitate logging of real-time events in performance-oriented applications

logog is a portable C++ library to facilitate logging of real-time events in performance-oriented applications, such as games. It is especially appropriate for projects that have constrained memory and constrained CPU requirements.

John Byrd 46 Oct 21, 2020
C++ implementation of the Google logging module

Google Logging Library The Google Logging Library (glog) implements application-level logging. The library provides logging APIs based on C++-style st

Google 5.9k Jan 9, 2023
log4cplus is a simple to use C++ logging API providing thread-safe, flexible, and arbitrarily granular control over log management and configuration. It is modelled after the Java log4j API.

% log4cplus README Short Description log4cplus is a simple to use C++17 logging API providing thread--safe, flexible, and arbitrarily granular control

null 1.4k Jan 4, 2023
Uberlog - Cross platform multi-process C++ logging system

uberlog uberlog is a cross platform C++ logging system that is: Small Fast Robust Runs on Linux, Windows, OSX MIT License Small Two headers, and three

IMQS Software 15 Sep 29, 2022
Boost Logging library

Boost.Log, part of collection of the Boost C++ Libraries, provides tools for adding logging to libraries and applications. Directories build - Boost.L

Boost.org 157 Dec 22, 2022
Reckless logging. Low-latency, high-throughput, asynchronous logging library for C++.

Introduction Reckless is an extremely low-latency, high-throughput logging library. It was created because I needed to perform extensive diagnostic lo

Mattias Flodin 445 Dec 20, 2022