Skip to content

How to use Logger

Pooyan Dadvand edited this page Nov 20, 2017 · 18 revisions

The logging system in Kratos has 3 important parts:

  • LoggerMessage a data class storing the message with some attributes like label, category, severity
  • Logger is a singleton object in charge of gathering all messages produced in the code and passing them to the outputs
  • LoggerOutput takes message and write it to the output (or file). This is the extension point of the logger and one can create its output to write only some messages (filtering by category, severity, label, etc.) with custom format.

Sending a Message

The simplest way to send a message is to use predefined macros:

KRATOS_INFO("Some label") << "Some message with value: " << 3.14 << " with more message";

This example sends a message with INFO severity and STATUS category. There are macros for each severity level:

  • KRATOS_WARNING for reporting a warning without interrupting the simulation
  • KRATOS_INFO is the standard level in which minimum level of information should be provided
  • KRATOS_DETAIL is to make more detailed output. All above macros should be used with low frequencies and should be avoided in fine grain parts like elements and conditions.
  • KRATOS_TRACE which will be enabled only in debug mode and will be ignored completely in release modes. This is the most verbose level for debugging only.
  • KRATOS_CHECK_POINTis an special macro which to be used for quality control and regression tests and is enabled only when KRATOS_ENABLE_CHECK_POINT is defined. Providing outputs with CHECKING category to be used in filtering output for regression tests.

Apart from severity each message has a category which can be:

  • STATUS to be used to indicate status of solution like passing some point, if is converged, some steps started or finished, etc.
  • CRITICAL is to indicate an exceptional nature of the message used for errors and warnings.
  • STATISTICS indicates that the message has statistical information like number of iterations, solver residual, mesh quality and so on.
  • PROFILING to be used for timing (not implemented yet)
  • CHECKING is for regression tests and quality control messages.

One can change the category by passing it to the message:

KRATOS_INFO("Number of Iterations") << number_of_iterations << LoggerMessage::Category::STATISTICS;

Note that each logger output can filter the messages by their category and severity and show only the ones it wants. For example an output associated with statistical file can only print the messages with STATISTICS as category.

Project information

Getting Started

Tutorials

Developers

Kratos structure

Conventions

Solvers

Debugging, profiling and testing

HOW TOs

Utilities

Kratos API

Kratos Structural Mechanics API

Clone this wiki locally