NOCL  v0.1.0-2524
Modern C++ Class Library for GUI Projects
nocl::Logfile Class Reference

Text log file. More...

#include <Logfile.hpp>

Inheritance diagram for nocl::Logfile:
Collaboration diagram for nocl::Logfile:

Public Member Functions

virtual ~Logfile (void)
 Destructor. More...
 
 Logfile (void)=delete
 Deleted empty constructor. Use static get() instead. More...
 
 Logfile (const Logfile &rhs)=delete
 Deleted copy constructor. Use static get() instead. More...
 
Logfileoperator= (const Logfile &rhs)=delete
 Deleted assignment operator. Use static get() instead. More...
 
virtual Logfilets (void)
 Write the current timestamp (as defined by nocl::timestamp_str()) to the log file. More...
 
virtual Logfileclose (void)
 
 Logfile (const int magic, const std::string &fname)
 Do not use this constructor! It is a workaround until I figure out how to correctly insert a Logfile object into a std::map using get std::map::emplace(). More...
 

Static Public Member Functions

static Logfileget (const std::string fname)
 
static Logfileget (const std::string fname, const nocl::Bytes truncate_size_in_bytes)
 
static void log_nocl_exceptions (const Logfile &logfile)
 Let nocl::Exception classes know where exceptions should be logged. More...
 

Public Attributes

std::string filename
 

Protected Member Functions

 Logfile (const std::string &fname)
 Protected constructor. Use static get() instead of calling this method. More...
 

Detailed Description

Text log file.

For example:

nocl::Logfile & log_file = Logfile::get("/var/log/myapp.log");
log_file.ts() << "starting service" << std::endl;

Constructor & Destructor Documentation

◆ ~Logfile()

nocl::Logfile::~Logfile ( void  )
virtual

Destructor.

◆ Logfile() [1/4]

nocl::Logfile::Logfile ( void  )
delete

Deleted empty constructor. Use static get() instead.

◆ Logfile() [2/4]

nocl::Logfile::Logfile ( const Logfile rhs)
delete

Deleted copy constructor. Use static get() instead.

◆ Logfile() [3/4]

nocl::Logfile::Logfile ( const int  magic,
const std::string &  fname 
)

Do not use this constructor! It is a workaround until I figure out how to correctly insert a Logfile object into a std::map using get std::map::emplace().

Instead of calling this, use the static method get().

References NOCL_WHERE.

◆ Logfile() [4/4]

nocl::Logfile::Logfile ( const std::string &  fname)
protected

Protected constructor. Use static get() instead of calling this method.

References filename, and ts().

Here is the call graph for this function:

Member Function Documentation

◆ operator=()

Logfile& nocl::Logfile::operator= ( const Logfile rhs)
delete

Deleted assignment operator. Use static get() instead.

◆ get() [1/2]

nocl::Logfile & nocl::Logfile::get ( const std::string  fname)
static

References filename.

Referenced by nocl::Exception::Exception().

Here is the caller graph for this function:

◆ get() [2/2]

nocl::Logfile & nocl::Logfile::get ( const std::string  fname,
const nocl::Bytes  truncate_size_in_bytes 
)
static

References nocl::approximate_iec_bytes(), filename, and nocl::timestamp_str().

Here is the call graph for this function:

◆ ts()

nocl::Logfile & nocl::Logfile::ts ( void  )
virtual

Write the current timestamp (as defined by nocl::timestamp_str()) to the log file.

Returns
Return a reference to the open stream. This can be used to easily log a new line of text to the file.

For example:

nocl::Logfile & log_file = nocl::Logfile::get("/var/log/myapp.log");
log_file.ts() << "processing data..." << std::endl;

References nocl::timestamp_str().

Referenced by close(), nocl::Exception::Exception(), and Logfile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ close()

nocl::Logfile & nocl::Logfile::close ( void  )
virtual

References filename, and ts().

Here is the call graph for this function:

◆ log_nocl_exceptions()

void nocl::Logfile::log_nocl_exceptions ( const Logfile logfile)
static

Let nocl::Exception classes know where exceptions should be logged.

This can also be set via nocl::Exception::log_filename.

References filename, and nocl::Exception::log_filename.

Member Data Documentation

◆ filename

std::string nocl::Logfile::filename

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