LDMX Software
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 Formatter & get ()
 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 90 of file Logger.h.

Member Function Documentation

◆ get()

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

get reference to the current single Formatter

Definition at line 168 of file Logger.cxx.

168 {
169 static Formatter the_formatter;
170 return the_formatter;
171}

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 175 of file Logger.cxx.

176 {
177 os << "[ " << log::extract<std::string>("Channel", view) << " ] "
178 << event_number_ << " ";
183 const level msg_level{safeExtract<level>(view["Severity"])};
184 switch (msg_level) {
185 case level::trace:
186 os << "trace";
187 break;
188 case level::debug:
189 os << "debug";
190 break;
191 case level::info:
192 os << " info";
193 break;
194 case level::warn:
195 os << " warn";
196 break;
197 case level::error:
198 os << "error";
199 break;
200 case level::fatal:
201 os << "fatal";
202 break;
203 default:
204 // this should never happen since the loggers created
205 // with makeLogger use the level enum and thus check
206 // at compile time that the given level is an good option.
207 // That being said, we leave this in case someone creates
208 // their own logger circumventing makeLogger for whatever
209 // reason and changes the enum defining the severity.
210 os << "?????";
211 break;
212 }
213 os << ": " << view[log::expressions::smessage];
214}

◆ set()

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

set the event number in the current Formatter

Definition at line 173 of file Logger.cxx.

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

References get().

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

Member Data Documentation

◆ event_number_

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

Definition at line 91 of file Logger.h.

91{0};

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