![]() |
Peano
|
#include <Log.h>
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 |
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:
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!
You can switch the log output format by setting -DUseLogService=xxx. At the moment, I support two different formats for xxx:
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.
|
private |
tarch::logging::Log::Log | ( | const std::string & | className | ) |
Constructor.
For the machine name.
className | Name 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 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.
methodName | method name |
logMacroMessage | log logMacroMessage |
Definition at line 600 of file Log.h.
Referenced by kernel_impl.impl::alloc(), kernel_impl.impl::loop(), and kernel_impl.impl::stencil().
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.
methodName | method name |
logMacroMessage | log logMacroMessage |
Definition at line 73 of file Log.cpp.
References tarch::mpi::Rank::getInstance(), and tarch::multicore::Core::getInstance().
|
static |
Logs and exception and stops the application.
I recommend to use the corresponding macro instead.
|
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().
|
private |
Returns the time stamp in nanoseconds.
Definition at line 133 of file Log.cpp.
References assertion1.
std::string tarch::logging::Log::getTraceInformation | ( | const std::string & | methodName | ) | const |
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().
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.
methodName | method name |
logMacroMessage | log logMacroMessage |
Definition at line 61 of file Log.cpp.
References tarch::logging::LogFilter::getInstance(), tarch::mpi::Rank::getInstance(), and tarch::multicore::Core::getInstance().
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.
methodName | method name |
logMacroMessage | log logMacroMessage |
Definition at line 67 of file Log.cpp.
References tarch::logging::LogFilter::getInstance(), tarch::mpi::Rank::getInstance(), and tarch::multicore::Core::getInstance().
|
private |
|
private |