Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Private Attributes | List of all members
StructuredLogger Class Reference

#include <ored/utilities/log.hpp>

+ Inheritance diagram for StructuredLogger:
+ Collaboration diagram for StructuredLogger:

Public Member Functions

 StructuredLogger ()
 Constructors. More...
 
const QuantLib::ext::shared_ptr< file_sink > & fileSink ()
 
const QuantLib::ext::shared_ptr< text_sink > & cacheSink ()
 
virtual void removeSinks () override
 Destructor. More...
 
void setFileLog (const std::string &filepath, const boost::filesystem::path &dir, QuantLib::Size rotationSize=0)
 
- Public Member Functions inherited from IndependentLogger
virtual ~IndependentLogger ()
 Destructor. More...
 
virtual void removeSinks ()=0
 
std::vector< std::string > & messages ()
 
void clear ()
 
const std::string & name () const
 Returns the Logger name. More...
 

Static Public Attributes

static const std::string name = "StructuredLogger"
 the name "StructuredLogger" More...
 

Private Attributes

QuantLib::ext::shared_ptr< file_sinkfileSink_
 
QuantLib::ext::shared_ptr< text_sinkcacheSink_
 

Additional Inherited Members

- Protected Member Functions inherited from IndependentLogger
 IndependentLogger (const std::string &name)
 Constructor. More...
 
- Protected Attributes inherited from IndependentLogger
std::vector< std::string > messages_
 

Detailed Description

StructuredLogger //! This logger stores each structured error/warning message in a separate location

Definition at line 314 of file log.hpp.

Constructor & Destructor Documentation

◆ StructuredLogger()

Constructors.

Definition at line 185 of file log.cpp.

186 // Create backend and initialize it with a stream
187 QuantLib::ext::shared_ptr<lsinks::text_ostream_backend> backend = QuantLib::ext::make_shared<lsinks::text_ostream_backend>();
188
189 // Wrap it into the frontend and register in the core
190 QuantLib::ext::shared_ptr<text_sink> sink(new text_sink(backend));
191 sink->set_filter(messageType == StructuredMessage::name);
192
193 // Use formatter to intercept and store the message.
194 auto formatter = [this](const logging::record_view& rec, logging::formatting_ostream& strm) {
195 const string& msg = rec[lexpr::smessage]->c_str();
196
197 // Emit log record if it has not been logged before
198 if (this->messages().empty() ||
199 std::find(this->messages().begin(), this->messages().end(), msg) == this->messages().end()) {
200 // Store the message
201 this->messages().push_back(msg);
202
203 oreSeverity logSeverity = boost::log::extract<oreSeverity>(severity.get_name(), rec).get();
204 // If a file sink has been defined, then send the log record to it.
205 if (this->fileSink()) {
206 // Send to structured log file
207 lsrc::severity_logger_mt<oreSeverity> lg;
208 lg.add_attribute(messageType.get_name(), lattr::constant<string>(name));
209 BOOST_LOG_SEV(lg, logSeverity) << rec[lexpr::smessage];
210 }
211
212 // Also send to full log file
213 MLOG(logSeverity, StructuredMessage::name << " " << rec[lexpr::smessage]);
214 }
215 };
216 sink->set_formatter(formatter);
217 logging::core::get()->add_sink(sink);
218 cacheSink_ = sink;
219}
IndependentLogger(const std::string &name)
Constructor.
Definition: log.hpp:281
std::vector< std::string > & messages()
Definition: log.hpp:269
static const std::string name
the name "StructuredLogger"
Definition: log.hpp:318
const QuantLib::ext::shared_ptr< file_sink > & fileSink()
Definition: log.hpp:321
QuantLib::ext::shared_ptr< text_sink > cacheSink_
Definition: log.hpp:329
static constexpr const char * name
Definition: log.hpp:692
oreSeverity
Definition: log.hpp:70
#define MLOG(mask, text)
Definition: log.hpp:529
boost::log::sinks::synchronous_sink< boost::log::sinks::text_ostream_backend > text_sink
Definition: log.hpp:121
+ Here is the call graph for this function:

Member Function Documentation

◆ fileSink()

const QuantLib::ext::shared_ptr< file_sink > & fileSink ( )

Definition at line 321 of file log.hpp.

321{ return fileSink_; }
QuantLib::ext::shared_ptr< file_sink > fileSink_
Definition: log.hpp:328
+ Here is the caller graph for this function:

◆ cacheSink()

const QuantLib::ext::shared_ptr< text_sink > & cacheSink ( )

Definition at line 322 of file log.hpp.

322{ return cacheSink_; }

◆ removeSinks()

void removeSinks ( )
overridevirtual

Destructor.

Implements IndependentLogger.

Definition at line 221 of file log.cpp.

221 {
222 if (fileSink_) {
223 logging::core::get()->remove_sink(fileSink_);
224 fileSink_ = nullptr;
225 }
226}

◆ setFileLog()

void setFileLog ( const std::string &  filepath,
const boost::filesystem::path &  dir,
QuantLib::Size  rotationSize = 0 
)

Definition at line 228 of file log.cpp.

228 {
229 if (rotationSize == 0) {
230 fileSink_ = logging::add_file_log(
231 lkeywords::target = dir,
232 lkeywords::file_name = filepath,
233 lkeywords::filter = messageType == StructuredLogger::name,
234 lkeywords::auto_flush = true
235 );
236 } else {
237 fileSink_ = logging::add_file_log(
238 lkeywords::target = dir,
239 lkeywords::file_name = filepath,
240 lkeywords::filter = messageType == StructuredLogger::name,
241 lkeywords::scan_method = lsinks::file::scan_matching,
242 lkeywords::rotation_size = rotationSize,
243 lkeywords::auto_flush = true
244 );
245 }
246}

Member Data Documentation

◆ name

const string name = "StructuredLogger"
static

the name "StructuredLogger"

Definition at line 318 of file log.hpp.

◆ fileSink_

QuantLib::ext::shared_ptr<file_sink> fileSink_
private

Definition at line 328 of file log.hpp.

◆ cacheSink_

QuantLib::ext::shared_ptr<text_sink> cacheSink_
private

Definition at line 329 of file log.hpp.