LDMX Software
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
framework::logging::Formatter Class Reference

Our logging formatter. More...

#include <Logger.h>

Public Member Functions

 Formatter (Formatter const &)=delete
 delete the copy constructor
 
void operator= (Formatter const &)=delete
 delete the assignment operator
 
void operator() (const log::record_view &view, log::formatting_ostream &os)
 format the passed record view into the output stream
 

Static Public Member Functions

static Formatterget ()
 get reference to the current single Formatter
 
static void set (int n)
 set the event number in the current Formatter
 

Private Attributes

int event_number_ {0}
 

Detailed Description

Our logging formatter.

We use a singleton formatter so that it can hold the current event index as an attribute and include it within the logs. This is easier than attempting to update the event number in all of the different logging sources floating around ldmx-sw.

Definition at line 93 of file Logger.h.

Member Function Documentation

◆ get()

Formatter & framework::logging::Formatter::get ( )
static

get reference to the current single Formatter

Definition at line 155 of file Logger.cxx.

155 {
156 static Formatter the_formatter;
157 return the_formatter;
158}

Referenced by set().

◆ operator()()

void framework::logging::Formatter::operator() ( const log::record_view &  view,
log::formatting_ostream &  os 
)

format the passed record view into the output stream

The format is

[ channel ] severity : message

We de-reference the value out of the log into our own type so that we can compare and convert it into a string.

Definition at line 162 of file Logger.cxx.

163 {
164 os << "[ " << log::extract<std::string>("Channel", view) << " ] "
165 << event_number_ << " ";
170 const level& msg_level{safe_extract<level>(view["Severity"])};
171 switch (msg_level) {
172 case level::debug:
173 os << "debug";
174 break;
175 case level::info:
176 os << " info";
177 break;
178 case level::warn:
179 os << " warn";
180 break;
181 case level::error:
182 os << "error";
183 break;
184 case level::fatal:
185 os << "fatal";
186 break;
187 default:
188 // this should never happen since the loggers created
189 // with makeLogger use the level enum and thus check
190 // at compile time that the given level is an good option.
191 // That being said, we leave this in case someone creates
192 // their own logger circumventing makeLogger for whatever
193 // reason and changes the enum defining the severity.
194 os << "?????";
195 break;
196 }
197 os << ": " << view[log::expressions::smessage];
198}

◆ set()

void framework::logging::Formatter::set ( int  n)
static

set the event number in the current Formatter

Definition at line 160 of file Logger.cxx.

160{ Formatter::get().event_number_ = n; }
static Formatter & get()
get reference to the current single Formatter
Definition Logger.cxx:155

References get().

Referenced by framework::Process::run().

Member Data Documentation

◆ event_number_

int framework::logging::Formatter::event_number_ {0}
private

Definition at line 94 of file Logger.h.

94{0};

The documentation for this class was generated from the following files: