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
ProgressLogger Class Reference

#include <ored/utilities/log.hpp>

+ Inheritance diagram for ProgressLogger:
+ Collaboration diagram for ProgressLogger:

Public Member Functions

 ProgressLogger ()
 Constructors. More...
 
 ProgressLogger (const bool coutLog)
 
const QuantLib::ext::shared_ptr< file_sink > & fileSink ()
 
const QuantLib::ext::shared_ptr< text_sink > & coutSink ()
 
const QuantLib::ext::shared_ptr< text_sink > & cacheSink ()
 
virtual void removeSinks () override
 Destructor. More...
 
void setCoutLog (bool flag)
 
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 = "ProgressLogger"
 the name "ProgressLogger" More...
 

Private Attributes

QuantLib::ext::shared_ptr< file_sinkfileSink_
 
QuantLib::ext::shared_ptr< text_sinkcoutSink_
 
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

ProgressLogger //! This logger stores each log message in a separate location indicating progress of analytic runs.

Definition at line 290 of file log.hpp.

Constructor & Destructor Documentation

◆ ProgressLogger() [1/2]

Constructors.

Definition at line 103 of file log.cpp.

104 // Create backend and initialize it with a stream
105 QuantLib::ext::shared_ptr<lsinks::text_ostream_backend> backend = QuantLib::ext::make_shared<lsinks::text_ostream_backend>();
106
107 // Wrap it into the frontend and register in the core
108 QuantLib::ext::shared_ptr<text_sink> sink(new text_sink(backend));
109
110 // This logger should only receive/process logs that were emitted by a ProgressMessage
111 sink->set_filter(messageType == ProgressMessage::name);
112
113 // Use formatter to intercept and store the message.
114 auto formatter = [this](const logging::record_view& rec, logging::formatting_ostream& strm) {
115 this->messages().push_back(rec[lexpr::smessage]->c_str());
116
117 // If a file sink exists, then send the log record to it.
118 if (this->fileSink()) {
119 // Send to progress log file
120 lsrc::severity_logger_mt<oreSeverity> lg;
121 lg.add_attribute(messageType.get_name(), lattr::constant<string>(name));
122 BOOST_LOG_SEV(lg, oreSeverity::notice) << rec[lexpr::smessage];
123 }
124
125 // Also send to full log file
126 LOG(ProgressMessage::name << " " << rec[lexpr::smessage]);
127 };
128 sink->set_formatter(formatter);
129 logging::core::get()->add_sink(sink);
130 cacheSink_ = sink;
131}
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 "ProgressLogger"
Definition: log.hpp:294
const QuantLib::ext::shared_ptr< file_sink > & fileSink()
Definition: log.hpp:298
QuantLib::ext::shared_ptr< text_sink > cacheSink_
Definition: log.hpp:309
static constexpr const char * name
Definition: log.hpp:736
#define LOG(text)
Logging Macro (Level = Notice)
Definition: log.hpp:552
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:

◆ ProgressLogger() [2/2]

ProgressLogger ( const bool  coutLog)

Definition at line 297 of file log.hpp.

297: ProgressLogger() { setCoutLog(coutLog); }
ProgressLogger()
Constructors.
Definition: log.cpp:103
void setCoutLog(bool flag)
Definition: log.cpp:164
+ Here is the call graph for this function:

Member Function Documentation

◆ fileSink()

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

Definition at line 298 of file log.hpp.

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

◆ coutSink()

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

Definition at line 299 of file log.hpp.

299{ return coutSink_; }
QuantLib::ext::shared_ptr< text_sink > coutSink_
Definition: log.hpp:308

◆ cacheSink()

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

Definition at line 300 of file log.hpp.

300{ return cacheSink_; }

◆ removeSinks()

void removeSinks ( )
overridevirtual

Destructor.

Implements IndependentLogger.

Definition at line 133 of file log.cpp.

133 {
134 if (fileSink_) {
135 logging::core::get()->remove_sink(fileSink_);
136 fileSink_ = nullptr;
137 }
138 if (coutSink_) {
139 logging::core::get()->remove_sink(coutSink_);
140 coutSink_ = nullptr;
141 }
142}

◆ setCoutLog()

void setCoutLog ( bool  flag)

Definition at line 164 of file log.cpp.

164 {
165 if (flag) {
166 if (!coutSink_) {
167 // Create backend and initialize it with a stream
168 QuantLib::ext::shared_ptr<lsinks::text_ostream_backend> backend = QuantLib::ext::make_shared<lsinks::text_ostream_backend>();
169 backend->add_stream(QuantLib::ext::shared_ptr<std::ostream>(&std::clog, boost::null_deleter()));
170
171 // Wrap it into the frontend and register in the core
172 QuantLib::ext::shared_ptr<text_sink> sink(new text_sink(backend));
173 sink->set_filter(messageType == ProgressMessage::name);
174 logging::core::get()->add_sink(sink);
175
176 // Store the sink for removal/retrieval later
177 coutSink_ = sink;
178 }
179 } else if (coutSink_) {
180 logging::core::get()->remove_sink(coutSink_);
181 coutSink_ = nullptr;
182 }
183}
+ Here is the caller graph for this function:

◆ setFileLog()

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

Definition at line 144 of file log.cpp.

144 {
145 if (rotationSize == 0) {
146 fileSink_ = logging::add_file_log(
147 lkeywords::target = dir,
148 lkeywords::file_name = filepath,
149 lkeywords::filter = messageType == ProgressLogger::name,
150 lkeywords::auto_flush = true
151 );
152 } else {
153 fileSink_ = logging::add_file_log(
154 lkeywords::target = dir,
155 lkeywords::file_name = filepath,
156 lkeywords::filter = messageType == ProgressLogger::name,
157 lkeywords::scan_method = lsinks::file::scan_matching,
158 lkeywords::rotation_size = rotationSize,
159 lkeywords::auto_flush = true
160 );
161 }
162}

Member Data Documentation

◆ name

const string name = "ProgressLogger"
static

the name "ProgressLogger"

Definition at line 294 of file log.hpp.

◆ fileSink_

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

Definition at line 307 of file log.hpp.

◆ coutSink_

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

Definition at line 308 of file log.hpp.

◆ cacheSink_

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

Definition at line 309 of file log.hpp.