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

LoggerStream class that is a std::ostream replacement that will log each line. More...

#include <ored/utilities/log.hpp>

+ Collaboration diagram for LoggerStream:

Public Member Functions

 LoggerStream (unsigned mask, const char *filename, unsigned lineNo)
 
 ~LoggerStream ()
 destructor - this is when the logging takes place. More...
 
 operator std::ostream & ()
 cast this LoggerStream as a ostream& More...
 

Private Attributes

unsigned mask_
 
const char * filename_
 
unsigned lineNo_
 
std::stringstream ss_
 

Detailed Description

LoggerStream class that is a std::ostream replacement that will log each line.

LoggerStream is a simple wrapper around a std::string stream, it has an explicit cast std::ostream& method so it can be used in place of any std::ostream, this can be used with QuantExt methods that take a std::ostream& for logging purposes.

Once the stream falls out of focus, it's destructor will take the buffered log messages and pass them the main ore::data::Log::instance().

Note the following

The LoggerStream relies on falling out of scope to trigger the logging, as such they should not be created using the new operator.

The proper usage is to use the macro LOGGERSTREAM and DLOGGERSTREAM, if a function takes a std::ostream& as a parameter, use the macro instead.

void function(int x, int y, std::ostream& out);
void main () {
// call function
function (3, 4, LOGGERSTREAM);
// All logging will be completed before this line
}
#define LOGGERSTREAM(text)
Definition: log.hpp:631

Definition at line 605 of file log.hpp.

Constructor & Destructor Documentation

◆ LoggerStream()

LoggerStream ( unsigned  mask,
const char *  filename,
unsigned  lineNo 
)

Definition at line 471 of file log.cpp.

472 : mask_(mask), filename_(filename), lineNo_(lineNo), ss_() {
473 QL_REQUIRE(mask == ORE_ALERT || mask == ORE_CRITICAL || mask == ORE_ERROR || mask == ORE_WARNING ||
474 mask == ORE_NOTICE || mask == ORE_DEBUG || mask == ORE_DATA,
475 "Invalid log mask " << mask);
476}
std::stringstream ss_
Definition: log.hpp:619
const char * filename_
Definition: log.hpp:617
#define ORE_DEBUG
Definition: log.hpp:32
#define ORE_CRITICAL
Definition: log.hpp:28
#define ORE_DATA
Definition: log.hpp:33
#define ORE_NOTICE
Definition: log.hpp:31
#define ORE_ERROR
Definition: log.hpp:29
#define ORE_WARNING
Definition: log.hpp:30
#define ORE_ALERT
Definition: log.hpp:27

◆ ~LoggerStream()

destructor - this is when the logging takes place.

Definition at line 478 of file log.cpp.

478 {
479 string text;
480 while (getline(ss_, text)) {
481 // we expand the MLOG macro here so we can overwrite __FILE__ and __LINE__
482 if (ore::data::Log::instance().enabled() && ore::data::Log::instance().filter(mask_)) {
483 boost::unique_lock<boost::shared_mutex> lock(ore::data::Log::instance().mutex());
484 ore::data::Log::instance().header(mask_, filename_, lineNo_);
485 ore::data::Log::instance().logStream() << text;
486 ore::data::Log::instance().log(mask_);
487 }
488 }
489}
SafeStack< Filter > filter

Member Function Documentation

◆ operator std::ostream &()

operator std::ostream & ( )

cast this LoggerStream as a ostream&

Definition at line 613 of file log.hpp.

613{ return ss_; }

Member Data Documentation

◆ mask_

unsigned mask_
private

Definition at line 616 of file log.hpp.

◆ filename_

const char* filename_
private

Definition at line 617 of file log.hpp.

◆ lineNo_

unsigned lineNo_
private

Definition at line 618 of file log.hpp.

◆ ss_

std::stringstream ss_
private

Definition at line 619 of file log.hpp.