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 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 94 of file Logger.h.

Member Function Documentation

◆ get()

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

get reference to the current single Formatter

Definition at line 153 of file Logger.cxx.

153 {
154 static Formatter the_formatter;
155 return the_formatter;
156}

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

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

◆ set()

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

set the event number in the current Formatter

Definition at line 158 of file Logger.cxx.

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

References get().

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

Member Data Documentation

◆ event_number_

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

Definition at line 95 of file Logger.h.

95{0};

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