mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 17:41:45 +00:00
Configuration and DDS example/tools updates
- Update DDS example command UI and extract it from example. - Unify address handling via DDS properties for dynamic deployment. - Update DDS docs with the new approach. - Allow `--config-key` to be used to access common config in JSON. - Allow common channel properties to be specified for all sockets. - Update MQ examples and Tuto3 with new config options. - Add start scripts to MQ examples for easier use.
This commit is contained in:
@@ -27,17 +27,13 @@ typedef boost::null_deleter empty_deleter_t;
|
||||
#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)
|
||||
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());
|
||||
@@ -50,68 +46,72 @@ void init_log_console(bool color_format)
|
||||
// add a text sink
|
||||
typedef sinks::synchronous_sink<sinks::text_ostream_backend> text_sink;
|
||||
logging::core::get()->remove_all_sinks();
|
||||
|
||||
|
||||
// CONSOLE - all severity except error
|
||||
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::cout, empty_deleter_t()));
|
||||
|
||||
sink->locked_backend()->add_stream(boost::shared_ptr<std::ostream>(&std::clog, empty_deleter_t()));
|
||||
|
||||
// specify the format of the log message
|
||||
if(color_format)
|
||||
if (color_format)
|
||||
{
|
||||
sink->set_formatter(&init_log_formatter<tag_console>);
|
||||
}
|
||||
else
|
||||
{
|
||||
sink->set_formatter(&init_log_formatter<tag_file>);
|
||||
|
||||
}
|
||||
|
||||
sink->set_filter(severity != SEVERITY_ERROR && severity < SEVERITY_NOLOG);
|
||||
// add sink to the core
|
||||
logging::core::get()->add_sink(sink);
|
||||
|
||||
|
||||
|
||||
// CONSOLE - only severity error
|
||||
boost::shared_ptr<text_sink> sink_error = boost::make_shared<text_sink>();
|
||||
sink_error->locked_backend()->add_stream(boost::shared_ptr<std::ostream>(&std::cerr, empty_deleter_t()));
|
||||
|
||||
if(color_format)
|
||||
|
||||
if (color_format)
|
||||
{
|
||||
sink_error->set_formatter(&init_log_formatter<tag_console>);
|
||||
}
|
||||
else
|
||||
{
|
||||
sink_error->set_formatter(&init_log_formatter<tag_file>);
|
||||
|
||||
}
|
||||
|
||||
sink_error->set_filter(severity == SEVERITY_ERROR);
|
||||
logging::core::get()->add_sink(sink_error);
|
||||
}
|
||||
|
||||
void reinit_logger(bool color_format)
|
||||
{
|
||||
LOG(NOLOG)<<"";
|
||||
LOG(NOLOG) << "";
|
||||
logging::core::get()->remove_all_sinks();
|
||||
init_log_console(color_format);
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
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));
|
||||
|
||||
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>);
|
||||
|
||||
@@ -120,95 +120,78 @@ void init_log_file(const std::string& filename, custom_severity_level threshold,
|
||||
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 )
|
||||
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 )
|
||||
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;
|
||||
}
|
||||
@@ -218,52 +201,45 @@ void init_new_file(const std::string& filename, custom_severity_level threshold,
|
||||
{
|
||||
// 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
|
||||
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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
@@ -12,8 +12,7 @@
|
||||
* Created on August 21, 2015, 6:12 PM
|
||||
*/
|
||||
#ifndef LOGGER_H
|
||||
#define LOGGER_H
|
||||
|
||||
#define LOGGER_H
|
||||
|
||||
#define BOOST_LOG_DYN_LINK 1 // necessary when linking the boost_log library dynamically
|
||||
#define FUSION_MAX_VECTOR_SIZE 20
|
||||
@@ -39,10 +38,7 @@
|
||||
|
||||
// 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
|
||||
@@ -62,26 +58,22 @@ namespace log_op
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// declaration of the init function for the global logger
|
||||
|
||||
void init_log_console(bool color_format=true);
|
||||
void init_log_console(bool color_format = true);
|
||||
void reinit_logger(bool color_format);
|
||||
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_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 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 );
|
||||
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);
|
||||
|
||||
#if defined(__GNUC__) || defined(__GNUG__)
|
||||
#pragma GCC diagnostic push
|
||||
@@ -92,7 +84,7 @@ void set_global_log_level_operation( log_op::operation op=log_op::GREATER_EQ_TH
|
||||
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)
|
||||
BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", custom_severity_level)
|
||||
|
||||
#if defined(__GNUC__) || defined(__GNUG__)
|
||||
#pragma GCC diagnostic pop
|
||||
@@ -101,29 +93,29 @@ 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");
|
||||
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>();
|
||||
|
||||
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
|
||||
@@ -134,7 +126,7 @@ void init_log_formatter(const boost::log::record_view &view, boost::log::formatt
|
||||
#else
|
||||
#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)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#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)
|
||||
@@ -152,5 +144,4 @@ void init_log_formatter(const boost::log::record_view &view, boost::log::formatt
|
||||
// create new file without formatting
|
||||
#define INIT_NEW_FILE(filename,op,loglevel) init_new_file(filename,custom_severity_level::loglevel,log_op::op);
|
||||
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user