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

FileLogger. More...

#include <ored/utilities/log.hpp>

+ Inheritance diagram for FileLogger:
+ Collaboration diagram for FileLogger:

Public Member Functions

 FileLogger (const std::string &filename)
 Constructor. More...
 
virtual ~FileLogger ()
 Destructor. More...
 
virtual void log (unsigned, const std::string &) override
 The log callback. More...
 
- Public Member Functions inherited from Logger
virtual ~Logger ()
 Destructor. More...
 
virtual void log (unsigned level, const std::string &s)=0
 The Log call back function. More...
 
const std::string & name ()
 Returns the Logger name. More...
 

Static Public Attributes

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

Private Attributes

std::string filename_
 
std::fstream fout_
 

Additional Inherited Members

- Protected Member Functions inherited from Logger
 Logger (const std::string &name)
 Constructor. More...
 

Detailed Description

FileLogger.

This logger writes each log message out to the given file. The file is flushed, but not closed, after each log message.

See also
Log

Definition at line 193 of file log.hpp.

Constructor & Destructor Documentation

◆ FileLogger()

FileLogger ( const std::string &  filename)

Constructor.

Construct a file logger using the given filename, this filename is passed to std::fostream::open() and this constructor will throw an exception if the file is not opened (e.g. if the filename is invalid)

Parameters
filenamethe log filename

Definition at line 84 of file log.cpp.

84 : Logger(name), filename_(filename) {
85 fout_.open(filename.c_str(), ios_base::out);
86 QL_REQUIRE(fout_.is_open(), "Error opening file " << filename);
87 fout_.setf(ios::fixed, ios::floatfield);
88 fout_.setf(ios::showpoint);
89}
static const std::string name
the name "FileLogger"
Definition: log.hpp:196
std::string filename_
Definition: log.hpp:210
std::fstream fout_
Definition: log.hpp:211
Logger(const std::string &name)
Constructor.
Definition: log.hpp:152

◆ ~FileLogger()

~FileLogger ( )
virtual

Destructor.

Definition at line 91 of file log.cpp.

91 {
92 if (fout_.is_open())
93 fout_.close();
94}

Member Function Documentation

◆ log()

void log ( unsigned  ,
const std::string &  msg 
)
overridevirtual

The log callback.

Implements Logger.

Definition at line 96 of file log.cpp.

96 {
97 if (fout_.is_open())
98 fout_ << msg << endl;
99}

Member Data Documentation

◆ name

const string name = "FileLogger"
static

the name "FileLogger"

Definition at line 196 of file log.hpp.

◆ filename_

std::string filename_
private

Definition at line 210 of file log.hpp.

◆ fout_

std::fstream fout_
private

Definition at line 211 of file log.hpp.