mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-16 10:01:47 +00:00
- Replace the fairmq logger with one based on Boost.Log
- Adapt FairProgOptions to the new logger
This commit is contained in:
committed by
Mohammad Al-Turany
parent
bea05ea6c1
commit
e0ca1f62b3
43
fairmq/logger/CMakeLists.txt
Normal file
43
fairmq/logger/CMakeLists.txt
Normal file
@@ -0,0 +1,43 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence version 3 (LGPL) version 3, #
|
||||
# copied verbatim in the file "LICENSE" #
|
||||
################################################################################
|
||||
# Create a library
|
||||
|
||||
set(INCLUDE_DIRECTORIES
|
||||
${CMAKE_SOURCE_DIR}/fairmq/logger
|
||||
${CMAKE_SOURCE_DIR}/fairmq/logger/run
|
||||
)
|
||||
|
||||
include_directories(${INCLUDE_DIRECTORIES})
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
|
||||
set(LINK_DIRECTORIES ${Boost_LIBRARY_DIRS})
|
||||
|
||||
link_directories(${LINK_DIRECTORIES})
|
||||
|
||||
set(SRCS logger.cxx)
|
||||
|
||||
set(LIBRARY_NAME fairmq_logger)
|
||||
|
||||
set(DEPENDENCIES
|
||||
boost_log
|
||||
boost_log_setup
|
||||
boost_thread
|
||||
boost_date_time
|
||||
boost_filesystem
|
||||
boost_system
|
||||
pthread
|
||||
)
|
||||
|
||||
GENERATE_LIBRARY()
|
||||
|
||||
# generate test executable
|
||||
set(EXE_NAME runtestLogger)
|
||||
set(SRCS run/testLogger.cxx)
|
||||
set(DEPENDENCIES fairmq_logger)
|
||||
GENERATE_EXECUTABLE()
|
||||
|
234
fairmq/logger/logger.cxx
Normal file
234
fairmq/logger/logger.cxx
Normal file
@@ -0,0 +1,234 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
#include "logger.h"
|
||||
|
||||
#include <boost/log/core/core.hpp>
|
||||
#include <boost/log/expressions/formatters/date_time.hpp>
|
||||
#include <boost/log/expressions.hpp>
|
||||
#include <boost/log/sinks/sync_frontend.hpp>
|
||||
#include <boost/log/sinks/text_ostream_backend.hpp>
|
||||
#include <boost/log/sources/severity_logger.hpp>
|
||||
#include <boost/log/support/date_time.hpp>
|
||||
#include <boost/core/null_deleter.hpp>
|
||||
#include <boost/log/sinks/text_file_backend.hpp>
|
||||
#include <boost/log/utility/setup/common_attributes.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <fstream>
|
||||
#include <ostream>
|
||||
|
||||
|
||||
|
||||
namespace logging = boost::log;
|
||||
namespace src = boost::log::sources;
|
||||
namespace expr = boost::log::expressions;
|
||||
namespace sinks = boost::log::sinks;
|
||||
namespace attrs = boost::log::attributes;
|
||||
|
||||
|
||||
|
||||
BOOST_LOG_GLOBAL_LOGGER_INIT(global_logger, src::severity_logger_mt)
|
||||
{
|
||||
src::severity_logger_mt<custom_severity_level> global_logger;
|
||||
global_logger.add_attribute("TimeStamp", attrs::local_clock());
|
||||
init_log_console();
|
||||
return global_logger;
|
||||
}
|
||||
|
||||
void init_log_console()
|
||||
{
|
||||
// add a text sink
|
||||
typedef sinks::synchronous_sink<sinks::text_ostream_backend> text_sink;
|
||||
boost::shared_ptr<text_sink> sink = boost::make_shared<text_sink>();
|
||||
// add "console" output stream to our sink
|
||||
sink->locked_backend()->add_stream(boost::shared_ptr<std::ostream>(&std::clog, boost::null_deleter()));
|
||||
// specify the format of the log message
|
||||
sink->set_formatter(&init_log_formatter<tag_console>);
|
||||
// add sink to the core
|
||||
logging::core::get()->add_sink(sink);
|
||||
}
|
||||
|
||||
void init_log_file(const std::string& filename, custom_severity_level threshold, log_op::operation op, const std::string& id)
|
||||
{
|
||||
// add a text sink
|
||||
std::string formatted_filename(filename);
|
||||
formatted_filename+=id;
|
||||
formatted_filename+="_%Y-%m-%d_%H-%M-%S.%N.log";
|
||||
boost::shared_ptr< sinks::text_file_backend > backend =
|
||||
boost::make_shared< sinks::text_file_backend >
|
||||
(
|
||||
boost::log::keywords::file_name = formatted_filename,
|
||||
boost::log::keywords::rotation_size = 10 * 1024 * 1024,
|
||||
// rotate at midnight every day
|
||||
boost::log::keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
|
||||
// log collector,
|
||||
// -- maximum total size of the stored log files is 1GB.
|
||||
// -- minimum free space on the drive is 2GB
|
||||
boost::log::keywords::max_size = 1000 * 1024 * 1024,
|
||||
boost::log::keywords::min_free_space = 2000 * 1024 * 1024,
|
||||
boost::log::keywords::auto_flush = true
|
||||
//keywords::time_based_rotation = &is_it_time_to_rotate
|
||||
);
|
||||
typedef sinks::synchronous_sink< sinks::text_file_backend > sink_t;
|
||||
boost::shared_ptr< sink_t > sink(new sink_t(backend));
|
||||
|
||||
// specify the format of the log message
|
||||
sink->set_formatter(&init_log_formatter<tag_file>);
|
||||
|
||||
switch (op)
|
||||
{
|
||||
case log_op::operation::EQUAL :
|
||||
sink->set_filter(severity == threshold);
|
||||
break;
|
||||
|
||||
case log_op::operation::GREATER_THAN :
|
||||
sink->set_filter(severity > threshold);
|
||||
break;
|
||||
|
||||
case log_op::operation::GREATER_EQ_THAN :
|
||||
sink->set_filter(severity >= threshold);
|
||||
break;
|
||||
|
||||
case log_op::operation::LESS_THAN :
|
||||
sink->set_filter(severity < threshold);
|
||||
break;
|
||||
|
||||
case log_op::operation::LESS_EQ_THAN :
|
||||
sink->set_filter(severity <= threshold);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
logging::core::get()->add_sink(sink);
|
||||
}
|
||||
|
||||
// temporary : to be replaced with c++11 lambda
|
||||
void set_global_log_level(log_op::operation op, custom_severity_level threshold )
|
||||
{
|
||||
switch (threshold)
|
||||
{
|
||||
case custom_severity_level::TRACE :
|
||||
set_global_log_level_operation(op,custom_severity_level::TRACE);
|
||||
break;
|
||||
|
||||
case custom_severity_level::DEBUG :
|
||||
set_global_log_level_operation(op,custom_severity_level::DEBUG);
|
||||
break;
|
||||
|
||||
case custom_severity_level::RESULTS :
|
||||
set_global_log_level_operation(op,custom_severity_level::RESULTS);
|
||||
break;
|
||||
|
||||
case custom_severity_level::INFO :
|
||||
set_global_log_level_operation(op,custom_severity_level::INFO);
|
||||
break;
|
||||
|
||||
case custom_severity_level::WARN :
|
||||
set_global_log_level_operation(op,custom_severity_level::WARN);
|
||||
break;
|
||||
|
||||
case custom_severity_level::STATE :
|
||||
set_global_log_level_operation(op,custom_severity_level::STATE);
|
||||
break;
|
||||
|
||||
case custom_severity_level::ERROR :
|
||||
set_global_log_level_operation(op,custom_severity_level::ERROR);
|
||||
break;
|
||||
|
||||
case custom_severity_level::NOLOG :
|
||||
set_global_log_level_operation(op,custom_severity_level::NOLOG);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void set_global_log_level_operation(log_op::operation op, custom_severity_level threshold )
|
||||
{
|
||||
switch (op)
|
||||
{
|
||||
case log_op::operation::EQUAL :
|
||||
boost::log::core::get()->set_filter(severity == threshold);
|
||||
break;
|
||||
|
||||
case log_op::operation::GREATER_THAN :
|
||||
boost::log::core::get()->set_filter(severity > threshold);
|
||||
break;
|
||||
|
||||
case log_op::operation::GREATER_EQ_THAN :
|
||||
boost::log::core::get()->set_filter(severity >= threshold);
|
||||
break;
|
||||
|
||||
case log_op::operation::LESS_THAN :
|
||||
boost::log::core::get()->set_filter(severity < threshold);
|
||||
break;
|
||||
|
||||
case log_op::operation::LESS_EQ_THAN :
|
||||
boost::log::core::get()->set_filter(severity <= threshold);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void init_new_file(const std::string& filename, custom_severity_level threshold, log_op::operation op)
|
||||
{
|
||||
// add a file text sink with filters but without any formatting
|
||||
std::string formatted_filename(filename);
|
||||
formatted_filename+=".%N.txt";
|
||||
boost::shared_ptr< sinks::text_file_backend > backend =
|
||||
boost::make_shared< sinks::text_file_backend >
|
||||
(
|
||||
boost::log::keywords::file_name = formatted_filename,
|
||||
boost::log::keywords::rotation_size = 10 * 1024 * 1024,
|
||||
// rotate at midnight every day
|
||||
boost::log::keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
|
||||
// log collector,
|
||||
// -- maximum total size of the stored log files is 1GB.
|
||||
// -- minimum free space on the drive is 2GB
|
||||
boost::log::keywords::max_size = 1000 * 1024 * 1024,
|
||||
boost::log::keywords::min_free_space = 2000 * 1024 * 1024,
|
||||
boost::log::keywords::auto_flush = true
|
||||
//keywords::time_based_rotation = &is_it_time_to_rotate
|
||||
);
|
||||
typedef sinks::synchronous_sink< sinks::text_file_backend > sink_t;
|
||||
boost::shared_ptr< sink_t > sink(new sink_t(backend));
|
||||
|
||||
//sink->set_formatter(&init_file_formatter);
|
||||
|
||||
switch (op)
|
||||
{
|
||||
case log_op::operation::EQUAL :
|
||||
sink->set_filter(severity == threshold);
|
||||
break;
|
||||
|
||||
case log_op::operation::GREATER_THAN :
|
||||
sink->set_filter(severity > threshold);
|
||||
break;
|
||||
|
||||
case log_op::operation::GREATER_EQ_THAN :
|
||||
sink->set_filter(severity >= threshold);
|
||||
break;
|
||||
|
||||
case log_op::operation::LESS_THAN :
|
||||
sink->set_filter(severity < threshold);
|
||||
break;
|
||||
|
||||
case log_op::operation::LESS_EQ_THAN :
|
||||
sink->set_filter(severity <= threshold);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
logging::core::get()->add_sink(sink);
|
||||
}
|
||||
|
129
fairmq/logger/logger.h
Normal file
129
fairmq/logger/logger.h
Normal file
@@ -0,0 +1,129 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
/*
|
||||
* File: logger.h
|
||||
* Author: winckler
|
||||
*
|
||||
* Created on August 21, 2015, 6:12 PM
|
||||
*/
|
||||
#ifndef LOGGER_H
|
||||
#define LOGGER_H
|
||||
|
||||
#define BOOST_LOG_DYN_LINK 1 // necessary when linking the boost_log library dynamically
|
||||
|
||||
// std
|
||||
#include <type_traits>
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
|
||||
// boost
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_io.hpp>
|
||||
#include <boost/log/sources/global_logger_storage.hpp>
|
||||
#include <boost/log/sources/severity_logger.hpp>
|
||||
#include <boost/log/utility/formatting_ostream.hpp>
|
||||
#include <boost/log/expressions.hpp>
|
||||
#include <boost/log/expressions/attr_fwd.hpp>
|
||||
#include <boost/log/expressions/attr.hpp>
|
||||
|
||||
// fairmq
|
||||
#include "logger_def.h"
|
||||
|
||||
// Note : the following types and values must be defined in the included logger_def.h :
|
||||
// 1- custom_severity_level
|
||||
// 2- SEVERITY_THRESHOLD
|
||||
// 3- tag_console
|
||||
// 4- tag_file
|
||||
|
||||
// Note : operation enum temporary : (until we replace it with c++11 lambda expression)
|
||||
namespace log_op
|
||||
{
|
||||
enum operation
|
||||
{
|
||||
EQUAL,
|
||||
GREATER_THAN,
|
||||
GREATER_EQ_THAN,
|
||||
LESS_THAN,
|
||||
LESS_EQ_THAN
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// declaration of the init function for the global logger
|
||||
void init_log_console();
|
||||
void init_log_file( const std::string& filename,
|
||||
custom_severity_level threshold=SEVERITY_THRESHOLD,
|
||||
log_op::operation=log_op::GREATER_EQ_THAN,
|
||||
const std::string& id=""
|
||||
);
|
||||
|
||||
void init_new_file( const std::string& filename,
|
||||
custom_severity_level threshold,
|
||||
log_op::operation op
|
||||
);
|
||||
|
||||
void set_global_log_level( log_op::operation op=log_op::GREATER_EQ_THAN,
|
||||
custom_severity_level threshold=SEVERITY_THRESHOLD );
|
||||
void set_global_log_level_operation( log_op::operation op=log_op::GREATER_EQ_THAN,
|
||||
custom_severity_level threshold=SEVERITY_THRESHOLD );
|
||||
// register a global logger (declaration)
|
||||
BOOST_LOG_GLOBAL_LOGGER(global_logger, boost::log::sources::severity_logger_mt<custom_severity_level>)
|
||||
|
||||
BOOST_LOG_ATTRIBUTE_KEYWORD(fairmq_logger_timestamp, "TimeStamp", boost::posix_time::ptime)
|
||||
BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", custom_severity_level)
|
||||
|
||||
|
||||
template<typename T>
|
||||
void init_log_formatter(const boost::log::record_view &view, boost::log::formatting_ostream &os)
|
||||
{
|
||||
os << "[" ;
|
||||
|
||||
if(std::is_same<T,tag_console>::value)
|
||||
os<<"\033[01;36m";
|
||||
|
||||
auto date_time_formatter =
|
||||
boost::log::expressions::stream
|
||||
<< boost::log::expressions::format_date_time< boost::posix_time::ptime >("TimeStamp", "%H:%M:%S");
|
||||
date_time_formatter(view, os);
|
||||
|
||||
if(std::is_same<T,tag_console>::value)
|
||||
os<<"\033[0m";
|
||||
|
||||
os << "]"
|
||||
<< "["
|
||||
<< view.attribute_values()["Severity"].extract<custom_severity_level,T>()
|
||||
<< "] "
|
||||
//<< " - "
|
||||
<< view.attribute_values()["Message"].extract<std::string>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// helper macros
|
||||
|
||||
// global macros (core). Level filters are set globally here, that is to all register sinks
|
||||
#define LOG(severity) BOOST_LOG_SEV(global_logger::get(),custom_severity_level::severity)
|
||||
#define MQLOG(severity) BOOST_LOG_SEV(global_logger::get(),custom_severity_level::severity)
|
||||
#define SET_LOG_LEVEL(loglevel) boost::log::core::get()->set_filter(severity >= custom_severity_level::loglevel);
|
||||
#define SET_LOG_FILTER(op,loglevel) set_global_log_level(log_op::op,custom_severity_level::loglevel)
|
||||
|
||||
// local init macros (sinks)
|
||||
// Notes : when applying a filter to the sink, and then to the core, the resulting filter will
|
||||
// be the intersection of the two sets defined by the two filters, i.e., core and sinks
|
||||
// filename : path to file name without extension
|
||||
#define INIT_LOG_FILE(filename) init_log_file(filename);
|
||||
#define INIT_LOG_FILE_LVL(filename,loglevel) init_log_file(filename,custom_severity_level::loglevel);
|
||||
#define INIT_LOG_FILE_FILTER(filename,op,loglevel) init_log_file(filename,custom_severity_level::loglevel,log_op::op);
|
||||
//INIT_LOG_FILE_FILTER_MP : add id to log filename for multiprocess
|
||||
#define INIT_LOG_FILE_FILTER_MP(filename,op,loglevel,id) init_log_file(filename,custom_severity_level::loglevel,log_op::GREATER_EQ_THAN,id);
|
||||
|
||||
// create new file without formatting
|
||||
#define INIT_NEW_FILE(filename,op,loglevel) init_new_file(filename,custom_severity_level::loglevel,log_op::op);
|
||||
|
||||
|
||||
#endif
|
183
fairmq/logger/logger_def.h
Normal file
183
fairmq/logger/logger_def.h
Normal file
@@ -0,0 +1,183 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
/*
|
||||
* File: logger_def.h
|
||||
* Author: winckler
|
||||
*
|
||||
* Created on September 2, 2015, 11:58 AM
|
||||
*/
|
||||
|
||||
#ifndef LOGGER_DEF_H
|
||||
#define LOGGER_DEF_H
|
||||
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include <boost/log/utility/manipulators/to_log.hpp>
|
||||
#include <boost/log/sources/record_ostream.hpp>
|
||||
|
||||
namespace fairmq
|
||||
{
|
||||
enum severity_level
|
||||
{
|
||||
TRACE,
|
||||
DEBUG,
|
||||
RESULTS,
|
||||
INFO,
|
||||
WARN,
|
||||
ERROR,
|
||||
STATE,
|
||||
NOLOG
|
||||
};
|
||||
|
||||
|
||||
static const std::array<std::string, 8> g_LogSeverityLevelString
|
||||
{
|
||||
{
|
||||
"TRACE",
|
||||
"DEBUG",
|
||||
"RESULTS",
|
||||
"INFO",
|
||||
"WARN",
|
||||
"ERROR",
|
||||
"STATE",
|
||||
"NOLOG"
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
namespace color
|
||||
{
|
||||
enum code
|
||||
{
|
||||
FG_BLACK = 30,
|
||||
FG_RED = 31,
|
||||
FG_GREEN = 32,
|
||||
FG_YELLOW = 33,
|
||||
FG_BLUE = 34,
|
||||
FG_MAGENTA = 35,
|
||||
FG_CYAN = 36,
|
||||
FG_WHITE = 37,
|
||||
FG_DEFAULT = 39,
|
||||
BG_RED = 41,
|
||||
BG_GREEN = 42,
|
||||
BG_BLUE = 44,
|
||||
BG_DEFAULT = 49
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// helper function to format in color console output
|
||||
template <fairmq::color::code color>
|
||||
inline std::string write_in(const std::string& text_in_bold)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "\033[01;" << color << "m" << text_in_bold << "\033[0m";
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
// typedef
|
||||
typedef fairmq::severity_level custom_severity_level;
|
||||
#define SEVERITY_THRESHOLD custom_severity_level::TRACE
|
||||
|
||||
// tags used for log console or file formatting
|
||||
struct tag_console;
|
||||
struct tag_file;
|
||||
|
||||
|
||||
// overload operator for console output
|
||||
inline boost::log::formatting_ostream& operator<<
|
||||
(
|
||||
boost::log::formatting_ostream& strm,
|
||||
boost::log::to_log_manip< custom_severity_level, tag_console > const& manip
|
||||
)
|
||||
{
|
||||
custom_severity_level level = manip.get();
|
||||
std::size_t idx=static_cast< std::size_t >(level);
|
||||
if ( idx < fairmq::g_LogSeverityLevelString.size() )
|
||||
{
|
||||
//strm <<" idx = "<<idx <<" ";
|
||||
switch (level)
|
||||
{
|
||||
case custom_severity_level::TRACE :
|
||||
strm << write_in<fairmq::color::FG_BLUE>(fairmq::g_LogSeverityLevelString.at(idx));
|
||||
break;
|
||||
|
||||
case custom_severity_level::DEBUG :
|
||||
strm << write_in<fairmq::color::FG_BLUE>(fairmq::g_LogSeverityLevelString.at(idx));
|
||||
break;
|
||||
|
||||
case custom_severity_level::RESULTS :
|
||||
strm << write_in<fairmq::color::FG_MAGENTA>(fairmq::g_LogSeverityLevelString.at(idx));
|
||||
break;
|
||||
|
||||
case custom_severity_level::INFO :
|
||||
strm << write_in<fairmq::color::FG_GREEN>(fairmq::g_LogSeverityLevelString.at(idx));
|
||||
break;
|
||||
|
||||
case custom_severity_level::WARN :
|
||||
strm << write_in<fairmq::color::FG_YELLOW>(fairmq::g_LogSeverityLevelString.at(idx));
|
||||
break;
|
||||
|
||||
case custom_severity_level::STATE :
|
||||
strm << write_in<fairmq::color::FG_MAGENTA>(fairmq::g_LogSeverityLevelString.at(idx));
|
||||
break;
|
||||
|
||||
case custom_severity_level::ERROR :
|
||||
strm << write_in<fairmq::color::FG_RED>(fairmq::g_LogSeverityLevelString.at(idx));
|
||||
break;
|
||||
|
||||
case custom_severity_level::NOLOG :
|
||||
strm << write_in<fairmq::color::FG_DEFAULT>(fairmq::g_LogSeverityLevelString.at(idx));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
strm << write_in<fairmq::color::FG_RED>("Unknown log level ")
|
||||
<< "(int level = "<<static_cast< int >(level)
|
||||
<<")";
|
||||
}
|
||||
return strm;
|
||||
}
|
||||
|
||||
// overload operator for file output
|
||||
inline boost::log::formatting_ostream& operator<<
|
||||
(
|
||||
boost::log::formatting_ostream& strm,
|
||||
boost::log::to_log_manip< custom_severity_level, tag_file > const& manip
|
||||
)
|
||||
{
|
||||
custom_severity_level level = manip.get();
|
||||
std::size_t idx=static_cast< std::size_t >(level);
|
||||
if ( idx < fairmq::g_LogSeverityLevelString.size() )
|
||||
strm << fairmq::g_LogSeverityLevelString.at(idx);
|
||||
else
|
||||
{
|
||||
strm << write_in<fairmq::color::FG_RED>("Unknown log level ")
|
||||
<< "(int level = "<<static_cast< int >(level)
|
||||
<<")";
|
||||
}
|
||||
return strm;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* LOGGER_DEF_H */
|
||||
|
66
fairmq/logger/run/testLogger.cxx
Normal file
66
fairmq/logger/run/testLogger.cxx
Normal file
@@ -0,0 +1,66 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
void test_logger()
|
||||
{
|
||||
LOG(TRACE) << "this is a trace message";
|
||||
LOG(DEBUG) << "this is a debug message";
|
||||
LOG(RESULTS) << "this is a results message";
|
||||
LOG(INFO) << "this is a info message";
|
||||
LOG(WARN) << "this is a warning message";
|
||||
LOG(ERROR) << "this is an error message";
|
||||
LOG(STATE) << "this is a state message";
|
||||
}
|
||||
|
||||
void test_set_level()
|
||||
{
|
||||
std::cout<<"********* test logger : SET_LOG_LEVEL(lvl) *********"<<std::endl;
|
||||
SET_LOG_LEVEL(TRACE);
|
||||
test_logger();
|
||||
std::cout << "----------------------------"<<std::endl;
|
||||
|
||||
SET_LOG_LEVEL(DEBUG);
|
||||
test_logger();
|
||||
std::cout << "----------------------------"<<std::endl;
|
||||
|
||||
SET_LOG_LEVEL(RESULTS);
|
||||
test_logger();
|
||||
std::cout << "----------------------------"<<std::endl;
|
||||
|
||||
SET_LOG_LEVEL(INFO);
|
||||
test_logger();
|
||||
std::cout << "----------------------------"<<std::endl;
|
||||
|
||||
SET_LOG_LEVEL(WARN);
|
||||
test_logger();
|
||||
std::cout << "----------------------------"<<std::endl;
|
||||
|
||||
SET_LOG_LEVEL(ERROR);
|
||||
test_logger();
|
||||
std::cout << "----------------------------"<<std::endl;
|
||||
|
||||
SET_LOG_LEVEL(STATE);
|
||||
test_logger();
|
||||
std::cout << "----------------------------"<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
INIT_LOG_FILE_FILTER("test_log_file",GREATER_EQ_THAN,ERROR);// init and add one sink to the core
|
||||
test_set_level();
|
||||
INIT_LOG_FILE_FILTER("test_another_log_file",EQUAL,INFO);// init and add another sink to the core
|
||||
test_set_level();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user