This repository has been archived by the owner on Jul 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/i90 add boost logging (#147)
* added log and log_setup to CMakeLists.txt and basic logging example in CodeGenerator.cpp * Example with line number and file name * example with global logger * test * Reworked logger * Added info logging * Changed log location * Added logging to StateMachine.cpp * Added more logging * Fixed doxygen folders * Added logging to perror * Added logging to perror * Added Error logging in CodeGenerator.cpp and Option.cpp * Added editors to logger * added justify class source url Co-authored-by: swolf2211 <[email protected]>
- Loading branch information
1 parent
1065308
commit ef212f6
Showing
15 changed files
with
503 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Editors: Tobias Goetz, Sebastian Wolf | ||
*/ | ||
|
||
#ifndef LOG_LOGGER_H | ||
#define LOG_LOGGER_H | ||
#pragma once | ||
|
||
#include <boost/log/trivial.hpp> | ||
#include <boost/log/sources/global_logger_storage.hpp> | ||
#include <boost/log/sources/severity_channel_logger.hpp> | ||
#include <boost/log/attributes/mutable_constant.hpp> | ||
#include <boost/log/utility/manipulators/add_value.hpp> | ||
#include <string> | ||
|
||
BOOST_LOG_GLOBAL_LOGGER(sysLogger, | ||
boost::log::sources::severity_channel_logger_mt<boost::log::trivial::severity_level>); | ||
BOOST_LOG_GLOBAL_LOGGER(dataLogger, | ||
boost::log::sources::severity_channel_logger_mt<boost::log::trivial::severity_level>); | ||
|
||
/** | ||
* @brief Custom logger class. | ||
* Custom logger according to https://objectcomputing.com/resources/publications/sett/may-2016-boostlog-library | ||
*/ | ||
class Logger { | ||
public: | ||
/// Init with default trivial logging | ||
static void init(); | ||
|
||
/// @param configFileName config ini file that contains boost logging properties. | ||
/// If configFileName.empty() then default initialization. | ||
static void initFromConfig(const std::string& configFileName); | ||
|
||
/// Disable logging | ||
static void disable(); | ||
|
||
/// Add a file sink for LOG_DATA_* for >= INFO. | ||
/// This file sink will be used along with any configured via Config in init(). | ||
static void addDataFileLog(const std::string& logFileName); | ||
}; | ||
|
||
#define LOG_LOG_LOCATION(LOGGER, LEVEL, ARG) \ | ||
BOOST_LOG_SEV(LOGGER, boost::log::trivial::LEVEL) \ | ||
<< boost::log::add_value("Line", __LINE__) \ | ||
<< boost::log::add_value("File", __FILE__) \ | ||
<< boost::log::add_value("Function", __FUNCTION__) << ARG; | ||
|
||
/// System Log macros. | ||
/// TRACE < DEBUG < INFO < WARN < ERROR < FATAL | ||
#define LOG_TRACE(ARG) LOG_LOG_LOCATION(sysLogger::get(), trace, ARG); | ||
#define LOG_DEBUG(ARG) LOG_LOG_LOCATION(sysLogger::get(), debug, ARG); | ||
#define LOG_INFO(ARG) LOG_LOG_LOCATION(sysLogger::get(), info, ARG); | ||
#define LOG_WARN(ARG) LOG_LOG_LOCATION(sysLogger::get(), warning, ARG); | ||
#define LOG_ERROR(ARG) LOG_LOG_LOCATION(sysLogger::get(), error, ARG); | ||
#define LOG_FATAL(ARG) LOG_LOG_LOCATION(sysLogger::get(), fatal, ARG); | ||
|
||
/// Data Log macros. Does not include LINE, FILE, FUNCTION. | ||
/// TRACE < DEBUG < INFO < WARN < ERROR < FATAL | ||
#define LOG_DATA_TRACE(ARG) BOOST_LOG_SEV(dataLogger::get(), boost::log::trivial::trace) << ARG | ||
#define LOG_DATA_DEBUG(ARG) BOOST_LOG_SEV(dataLogger::get(), boost::log::trivial::debug) << ARG | ||
#define LOG_DATA_INFO(ARG) BOOST_LOG_SEV(dataLogger::get(), boost::log::trivial::info) << ARG | ||
#define LOG_DATA_WARN(ARG) BOOST_LOG_SEV(dataLogger::get(), boost::log::trivial::warning) << ARG | ||
#define LOG_DATA_ERROR(ARG) BOOST_LOG_SEV(dataLogger::get(), boost::log::trivial::error) << ARG | ||
#define LOG_DATA_FATAL(ARG) BOOST_LOG_SEV(dataLogger::get(), boost::log::trivial::fatal) << ARG | ||
|
||
#endif /* LOG_LOGGER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# | ||
# See http://www.boost.org/doc/libs/1_60_0/libs/log/doc/html/log/detailed/utilities.html#log.detailed.utilities.setup.filter_formatter | ||
# | ||
# Many of the property values have to be in quotes, best to just use quotes for all of them. | ||
# | ||
# SYSLF is the System Log File for logging standard 'debug' type info. | ||
# DATALF is the Data log File for logging modification to business data. | ||
# | ||
[Core] | ||
# Set DisableLogging to true to disable all logging. | ||
DisableLogging="false" | ||
|
||
# SYSLF - system log | ||
[Sinks.SYSLF] | ||
Destination="TextFile" | ||
# If Asynchronous true then thread dedicated to writing to log, otherwise blocks main thread to write. | ||
Asynchronous="true" | ||
# If AutoFlush is true then non-buffered output | ||
AutoFlush="true" | ||
# Line Formats available: TimeStamp, Uptime, Severity, LineID (counter), ProcessID, ThreadID, Line, File, Function | ||
# TimeStamp and Uptime support boost date time format: | ||
# http://www.boost.org/doc/libs/1_60_0/doc/html/date_time/date_time_io.html#date_time.format_flags | ||
Format="[%TimeStamp(format=\"%Y-%m-%d %H:%M:%S.%f\")%][%Uptime(format=\"%O:%M:%S.%f\")%][%Severity%] %File%(%Line%) %Function%: %Message%" | ||
# Target directory in which rotated files will be stored. | ||
Target="./logs" | ||
# FileName pattern to use. %N is a counter for files. | ||
FileName="app_syslog_%N.log" | ||
# RotationSize in bytes, File size, in bytes, upon which file rotation will be performed. | ||
# Time based rotation also available via RotationInterval and RotationTimePoint see boost log docs. | ||
RotationSize="10485760" | ||
# Matching used so that only files matching FileName pattern are deleted. | ||
ScanForFiles="Matching" | ||
# MaxSize - Total size of files in the target directory in bytes upon which the oldest file will be deleted. | ||
#MaxSize=100485760 | ||
# MinFreeSpace - Minimum free space in the Target directory in bytes. Above this value oldest file is deleted. | ||
#MinFreeSpace=1485760 | ||
# Specify level of log, options are: trace, debug, info, warning, error, fatal | ||
# Since Channel not part of filter all log output will be included. | ||
# If only SYSLF logging desired, change to: Filter="%Severity% >= trace & %Channel% matches \"SYSLF\"" | ||
Filter="%Severity% >= trace" | ||
|
||
# DATALF - data log | ||
[Sinks.DATALF] | ||
Destination="TextFile" | ||
# If Asynchronous true then thread dedicated to writing to log, otherwise blocks main thread to write. | ||
Asynchronous="false" | ||
# If AutoFlush is true then non-buffered output | ||
AutoFlush="true" | ||
# Line Formats available: TimeStamp, Uptime, Severity, LineID (counter), ProcessID, ThreadID | ||
# TimeStamp and Uptime support boost date time format: | ||
# http://www.boost.org/doc/libs/1_60_0/doc/html/date_time/date_time_io.html#date_time.format_flags | ||
Format="[%TimeStamp(format=\"%Y-%m-%d %H:%M:%S.%f\")%][%Uptime(format=\"%O:%M:%S.%f\")%][%Severity%] %Message%" | ||
# Target directory in which rotated files will be stored. | ||
Target="./logs" | ||
# FileName pattern to use. %N is a counter for files. | ||
FileName="app_datalog_%N.log" | ||
# RotationSize in bytes, File size, in bytes, upon which file rotation will be performed. | ||
# Time based rotation also available via RotationInterval and RotationTimePoint see boost log docs. | ||
RotationSize="10485760" | ||
# Matching used so that only files matching FileName pattern are deleted. | ||
ScanForFiles="Matching" | ||
# MaxSize - Total size of files in the target directory in bytes upon which the oldest file will be deleted. | ||
#MaxSize=100485760 | ||
# MinFreeSpace - Minimum free space in the Target directory in bytes. Above this value oldest file is deleted. | ||
#MinFreeSpace=1485760 | ||
# Specify level of log, options are: trace, debug, info, warning, error, fatal | ||
# Specify Channel otherwise all log output will be included. | ||
Filter="%Severity% >= trace & %Channel% matches \"DATALF\"" | ||
|
||
# Console log, logs both DATALF and SYSLF | ||
[Sinks.Console] | ||
# Remove the following lines to disable console logging | ||
Destination="Console" | ||
# If AutoFlush is true then non-buffered output | ||
AutoFlush="true" | ||
# Line Formats available: TimeStamp, Uptime, Severity, LineID (counter), ProcessID, ThreadID | ||
# TimeStamp and Uptime support boost date time format: | ||
# http://www.boost.org/doc/libs/1_60_0/doc/html/date_time/date_time_io.html#date_time.format_flags | ||
Format="[%TimeStamp(format=\"%Y-%m-%d %H:%M:%S.%f\")%][%Uptime(format=\"%O:%M:%S.%f\")%][%Severity%] - %Message%" | ||
# Specify level of log, options are: trace, debug, info, warning, error, fatal | ||
Filter="%Severity% >= info" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.