Project

General

Profile

Build and start messagefacility

MessageFacility is provided as a UPS product (messagefacility). It depends on two other libraries, FHiCL and cetlib, also provided as UPS products (fhiclcpp and cetlib). After setting up the necessary libraries, please include the following include paths to your build script

-I${MESSAGEFACILITY_INC} -I${FHICLCPP_INC} -I${CETLIB_INC}

, and the library paths

-L${MESSAGEFACILITY_LIB} -L${FHICLCPP_LIB} -L${CETLIB_LIB}

Also please don't forget to add following libraries,

-lMF_MessageLogger -lMF_Utilities -lfhiclcpp -lcetlib

Now your project is good to build with the message facility.

Header file

Please include the following header file before calling any MF methods,

#include "messagefacility/MessageLogger/MessageLogger.h" 

Start MessageFacility Service

In order to use message logging calls, the message facility service must be present. The service presence can be instantiated by,

void mf::StartMessageFacility( std::string const & mode
                             , fhicl::ParameterSet const & pset = MessageFacilityService::ConfigurationFile() );

Parameter mode

Call to start the service using mf::MessageFacilityService::MultiThread as the first parameter (mode) to make it capable of logging messages in a multi-thread application; mf::MessageFacilityService::SingleThread is to instantiate the service in the single thread mode, thus has some performance benefits as oppose to the multi-threaded service. But using single-thread mode in a multi-thread application is likely to cause the fragmentation of logging messages and other undetermined behavior.

Parameter pset

pset is a configuration object used to control the behavior of the message facility when logging messages. The detailed configuration file is written in a FHiCL file to control the threshold, categories, and throttling etc., of the messages. Please refer to {{ }} on how to write a configuration file.

The fhicl::ParameterSet object is then generated by parsing the configuration file using

static fhicl::ParameterSet mf::MessageFacilityService::ConfigurationFile(
           std::string const & filename = "MessageFacility.cfg",
           fhicl::ParameterSet const & def = logCF() );

To ease the pain of writing configuration files for each application, the message facility also provides 7 pre-defined configurations. They are,

// report messages to console
static fhicl::ParameterSet mf::MessageFacilityService::logConsole( );

// report messages to server
//   partition: partition of the server, default 0
static fhicl::ParameterSet mf::MessageFacilityService::logServer( int partition = 0 );

// report messages to file
//   filename: the name of the log file
//   append: whether to append to the existing file or create a new file
static fhicl::ParameterSet mf::MessageFacilityService::logFile(
                  std::string const & filename = "logfile",
                  bool append = false );

// report messages to both console and server
//   partition: server partition
static fhicl::ParameterSet mf::MessageFacilityService::logCS( int partition = 0 );

// report messages to both console and file
//   filename: the name of the log file
//   append: whether to append to the existing file or create a new file
static fhicl::ParameterSet mf::MessageFacilityService::logCF(
                   std::string const & filename = "logfile",
                   bool append = false );

// report messages to both file and server
//   filename: the name of the log file
//   append: whether to append to the existing file or create a new file
//   partition: partition of the server, default 0
static fhicl::ParameterSet mf::MessageFacilityService::logFS(
                   std::string const & filename = "logfile",
                   bool append = false,
                   int partition = 0 );

// report messages to console, file, and server
//   filename: the name of the log file
//   append: whether to append to the existing file or create a new file
//   partition: partition of the server, default 0
static fhicl::ParameterSet mf::MessageFacilityService::logCFS(
                   std::string const & filename = "logfile",
                   bool append = false,
                   int partition = 0 );

Examples

So to start the message facility service in multi-thread mode, and uses "myapp-mf.fcl" as the configuration file. If the configuration file does not exist, by default it will logging all messages to console and file:

fhicl::ParameterSet pset = 
    mf::MessageFacilityService::ConfigurationFile( "myapp-mf.fcl", MessageFacilityService::logCF() );
mf::MessageFacilityService::StartMessageFacility ( MessageFacilityService::MultiThread, pset );

Set up (optional) meta-data of log messages

Per-process application name

void mf::SetApplicationName( std::string const & application );

Per-thread module name

void mf::SetModuleName( std::string const & module );

Context within a module

void mf::SetContext( std::string const & context );