Peano
Loading...
Searching...
No Matches
tarch::logging::Log Class Reference

Log Device. More...

#include <Log.h>

Collaboration diagram for tarch::logging::Log:

Public Types

typedef std::function< std::string(void) > Message
 We could make the logMacroMessage passed into a log statement a string.
 

Public Member Functions

 Log (const std::string &className)
 Constructor.
 
virtual ~Log ()
 Destructor.
 
void debug (const std::string &methodName, Message logMacroMessage) const
 Log Debug Information.
 
void info (const std::string &methodName, Message logMacroMessage)
 Log Information.
 
void warning (const std::string &methodName, Message logMacroMessage)
 Log a Warning.
 
void error (const std::string &methodName, Message logMacroMessage)
 Log an Error.
 
void traceIn (const std::string &methodName, Message logMacroMessage)
 
void traceOut (const std::string &methodName, Message logMacroMessage)
 
void indent (bool indent, const std::string &trace, Message logMacroMessage) const
 Indent the Subsequent Messages.
 
std::string getTraceInformation (const std::string &methodName) const
 

Static Public Member Functions

static std::string getMachineInformation ()
 Writes information about the computer the output is written from.
 
static void exception (const std::bad_alloc &exception, const std::string &file, const int lineNumber)
 Logs and exception and stops the application.
 
static void flushBeforeAssertion ()
 

Private Types

typedef CommandLineLogger UseLogService
 

Private Member Functions

long int getTimeStamp () const
 Returns the time stamp in nanoseconds.
 

Private Attributes

std::string _className
 Name of the class that is using the interface.
 
std::chrono::system_clock::time_point _startupTime
 

Detailed Description

Log Device.

Log is the class all logging classes should use. To use the logging API they have to create an instance by their own. It is suggested to hold this instance static for the constructor of the Log class has to be given the class name of the logging class. The Log class itself is stateless. The log requests on this instance are processed here and forwarded to the assigned logger (an internal attribute).

Which concrete implementation has to be used for logging is switched using a compiler attribute. Since the logging is used extremely often, this is better than dynamic binding.

There are five different log levels, the user may write any output:

  • error: Here only errors have to be written to. Error logMacroMessages may never be oppressed.
  • warning:
  • debug: Debug information that is switched off normally. Only available if you use Debug
  • info: Statistical information, copyright and similar information. Should be used rather seldom.

Runtime

The underlying log device (like the CommandlineLogger) has to offer synchronized output methods. Thus, calls to logging methods in multithreaded environments mark synchronization points of your programme and will change timing behaviour!

output format

You can switch the log output format by setting -DUseLogService=xxx. At the moment, I support two different formats for xxx:

Author
Tobias Weinzierl

Definition at line 516 of file Log.h.

Member Typedef Documentation

◆ Message

typedef std::function< std::string(void) > tarch::logging::Log::Message

We could make the logMacroMessage passed into a log statement a string.

However, many codes write rather complicated strings and therefore spend a lot of time to construct the logMacroMessage. This is fine in release mode, e.g., where the number of strings is small. It is problematic in trace mode or debug, where we have a lot of strings, and most of them won't be used, as we filter them out later anyway.

Therefore, I switch to lazy evaluation: a logMacroMessage string is constructed if and only if the logMacroMessage will be written. The construction is realised through a (lambda) function modelled via Message.

Definition at line 577 of file Log.h.

◆ UseLogService

Definition at line 519 of file Log.h.

Constructor & Destructor Documentation

◆ Log()

tarch::logging::Log::Log ( const std::string & className)

Constructor.

For the machine name.

Parameters
classNameName of the class that is using the logging component. Please specify both class name and namespace using the format namespace::classname

If it doesn't work, switch it off in the file CompilerSpecificSettings.h.

Definition at line 45 of file Log.cpp.

References _startupTime.

◆ ~Log()

tarch::logging::Log::~Log ( )
virtual

Destructor.

Definition at line 51 of file Log.cpp.

Member Function Documentation

◆ debug()

void tarch::logging::Log::debug ( const std::string & methodName,
Message logMacroMessage ) const

Log Debug Information.

Remark: Please do not use this operation directly, but use the macros above instead.

The method has to be given the method name. Often it is useful to pass the whole method signature, that means e.g. if the method info itself would log, the method invocation would look like this:

  info("info(std::string,std::string)", "just an example text");

So you are able to identify methods in your log although you use overloading.

Parameters
methodNamemethod name
logMacroMessagelog logMacroMessage

Definition at line 600 of file Log.h.

Referenced by kernel_impl.impl::alloc(), kernel_impl.impl::loop(), and kernel_impl.impl::stencil().

Here is the caller graph for this function:

◆ error()

void tarch::logging::Log::error ( const std::string & methodName,
Message logMacroMessage )

Log an Error.

The method has to be given the method name. Often it is useful to pass the whole method signature, that means e.g. if the method info itself would log, the method invocation would look like this:

  info("info(std::string,std::string)", "just an example text");

So you are able to identify methods in your log although you use overloading.

Parameters
methodNamemethod name
logMacroMessagelog logMacroMessage

Definition at line 73 of file Log.cpp.

References tarch::mpi::Rank::getInstance(), and tarch::multicore::Core::getInstance().

Here is the call graph for this function:

◆ exception()

static void tarch::logging::Log::exception ( const std::bad_alloc & exception,
const std::string & file,
const int lineNumber )
static

Logs and exception and stops the application.

I recommend to use the corresponding macro instead.

◆ flushBeforeAssertion()

void tarch::logging::Log::flushBeforeAssertion ( )
static

Definition at line 129 of file Log.cpp.

◆ getMachineInformation()

std::string tarch::logging::Log::getMachineInformation ( )
static

Writes information about the computer the output is written from.

The information string contains the operation system name, the computer name and the cpu name.

Definition at line 99 of file Log.cpp.

References assertion, tarch::mpi::Rank::getInstance(), and tarch::mpi::Rank::getRank().

Here is the call graph for this function:

◆ getTimeStamp()

long int tarch::logging::Log::getTimeStamp ( ) const
private

Returns the time stamp in nanoseconds.

Definition at line 133 of file Log.cpp.

References assertion1.

◆ getTraceInformation()

std::string tarch::logging::Log::getTraceInformation ( const std::string & methodName) const

Definition at line 140 of file Log.cpp.

◆ indent()

void tarch::logging::Log::indent ( bool indent,
const std::string & trace,
Message logMacroMessage ) const

Indent the Subsequent Messages.

Depending on indent the operation increments or decrements the indent. The call is forwarded to the logging device.

Definition at line 95 of file Log.cpp.

Referenced by printers.cpp_printer::alloc(), kernel_impl.impl::alloc(), printers.cpp_printer::loop(), kernel_impl.impl::loop(), and kernel_impl.impl::stencil().

Here is the caller graph for this function:

◆ info()

void tarch::logging::Log::info ( const std::string & methodName,
Message logMacroMessage )

Log Information.

The method has to be given the method name. Often it is useful to pass the whole method signature, that means e.g. if the method info itself would log, the method invocation would look like this:

  info("info(std::string,std::string)", "just an example text");

So you are able to identify methods in your log although you use overloading.

Parameters
methodNamemethod name
logMacroMessagelog logMacroMessage

Definition at line 61 of file Log.cpp.

References tarch::logging::LogFilter::getInstance(), tarch::mpi::Rank::getInstance(), and tarch::multicore::Core::getInstance().

Here is the call graph for this function:

◆ traceIn()

void tarch::logging::Log::traceIn ( const std::string & methodName,
Message logMacroMessage )

Definition at line 90 of file Log.cpp.

◆ traceOut()

void tarch::logging::Log::traceOut ( const std::string & methodName,
Message logMacroMessage )

Definition at line 92 of file Log.cpp.

◆ warning()

void tarch::logging::Log::warning ( const std::string & methodName,
Message logMacroMessage )

Log a Warning.

The method has to be given the method name. Often it is useful to pass the whole method signature, that means e.g. if the method info itself would log, the method invocation would look like this:

  info("info(std::string,std::string)", "just an example text");

So you are able to identify methods in your log although you use overloading.

Parameters
methodNamemethod name
logMacroMessagelog logMacroMessage

Definition at line 67 of file Log.cpp.

References tarch::logging::LogFilter::getInstance(), tarch::mpi::Rank::getInstance(), and tarch::multicore::Core::getInstance().

Here is the call graph for this function:

Field Documentation

◆ _className

std::string tarch::logging::Log::_className
private

Name of the class that is using the interface.

Definition at line 530 of file Log.h.

◆ _startupTime

std::chrono::system_clock::time_point tarch::logging::Log::_startupTime
private

Definition at line 532 of file Log.h.

Referenced by Log().


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