Logger.h File Reference
#include <string>
#include <sstream>
#include <functional>
#include <type_traits>
#include <iomanip>
#include "GeneralDefine.h"
#include <iostream>

Go to the source code of this file.

Classes

class  LoggerOutput
 Default functions for output generation. More...
 
class  LL< Level >
 Tag for template metaprogramming. More...
 
class  Logger< L, ASSERTS >
 the Logger class is the main class of the logger implementation. It holds all the functions which invoke certain methods to create messages based on input parameter deductions. More...
 

Macros

#define MERCURYDPM_LOGLEVEL   Log::DEFAULT
 
#define CG_LOGLEVEL   Log::DEFAULT
 
#define MERCURYDPM_ASSERTS   true
 
#define assert(e, ...)   assert(true,"")
 

Enumerations

enum class  Flusher { FLUSH , NO_FLUSH }
 The Logger class provides ability to write log messages in your own customized format. More...
 
enum class  Log : signed char {
  FATAL = -20 , ERROR = -15 , WARN = -10 , INFO = -5 ,
  DEFAULT = 0 , VERBOSE = 5 , DEBUG = 10
}
 The different loglevels. More...
 

Functions

constexpr bool operator<= (const Log rhs, const Log lhs)
 Internally used to filter on loglevel. Do not edit, as this is required for an optimised logger. More...
 

Variables

LoggerOutputloggerOutput
 Declaration of the output functions. More...
 
LL< Log::FATAL > FATAL
 Fatal log level. More...
 
LL< Log::ERROR > ERROR
 Error log level. More...
 
LL< Log::WARN > WARN
 Warning log level. More...
 
LL< Log::INFO > INFO
 Info log level. More...
 
LL< Log::DEFAULT > DEFAULT
 Default log level. More...
 
LL< Log::VERBOSE > VERBOSE
 Verbose information. More...
 
LL< Log::DEBUG > DEBUG
 Debug information. More...
 
Logger< MERCURYDPM_LOGLEVELlogger
 
Logger< CG_LOGLEVELcgLogger
 

Macro Definition Documentation

◆ assert

#define assert (   e,
  ... 
)    assert(true,"")

◆ CG_LOGLEVEL

#define CG_LOGLEVEL   Log::DEFAULT

◆ MERCURYDPM_ASSERTS

#define MERCURYDPM_ASSERTS   true

◆ MERCURYDPM_LOGLEVEL

#define MERCURYDPM_LOGLEVEL   Log::DEFAULT

Enumeration Type Documentation

◆ Flusher

enum Flusher
strong

The Logger class provides ability to write log messages in your own customized format.

logger objects can be globally called on different loglevels whose usage is briefly explained where they have been declared down below.

The previous version of the Logger used the syntax Logger<Log::LEVEL> logger; which is now predefined in logger.cc.

The operator() function is utilized in this logger to keep log messages in a single statement of format:

 logger(Log::LEVEL, "Message", args...);

Where args... is a user defined pack of parameters. Each parameter is denoted by a percentage character %, see example below.

logger(INFO, "The current timestep is %.", getTimeStep()); OUTPUT: The current timestep is 0.0104124.

The output of arguments an also be customized by a certain precision or width. A number following the percentage character is defined as the precision of the parameter (e.g. %12), whereas a full stop followed by a number is defined as the output width of a parameter (e.g. %.10). Here std::left was chosen as default positioning. See examples below.

logger(INFO, "The current timestep is %12.", getTimestep()); OUTPUT: The current timestep is 0.01020304917.

logger(INFO, "The current timestep is %.12.", getTimestep()); OUTPUT: The current timestep is 0.0102051 .

logger(INFO, "The current timestep is %12.14.", getTimestep()); OUTPUT: The current timestep is 0.01020304917 .

After each invocation of the logger the output is flushed. To speed-up the code it is key to avoid flushing of the output wherever possible. Therefore, escape characters such as "\n" are preferred over std::endl. Furthermore if a parameter pack of the logger contains the argument Flusher::NO_FLUSH it will skip the use of std::endl after logger invocation.

Default loglevel is Log::DEFAULT = 0.

Enum class which enables/disables flushing of output.

the Flusher class is only used if the loglevel is below VERBOSE and DEBUG and if the CMAKE_BUILD_TYPE is not "Debug". If Flusher::NO_FLUSH is added as an argument to a logger invocation it will prevent the logger to call std::endl and flush the ouput at the end of the call. This is mainly utilized to speed up the code when logging messages.

Enumerator
FLUSH 
NO_FLUSH 
115 {
116  FLUSH,
117  NO_FLUSH
118 };

◆ Log

enum Log : signed char
strong

The different loglevels.

The different loglevels, represented as signed characters, in descending order of severeness. Worst is FATAL, best is DEBUG.

Please, use the tags FATAL/ERROR/etc without class/enum/namespace.

Enumerator
FATAL 
ERROR 
WARN 
INFO 
DEFAULT 
VERBOSE 
DEBUG 
130 {
131  FATAL = -20, ERROR = -15, WARN = -10, INFO = -5, DEFAULT = 0, VERBOSE = 5, DEBUG = 10
132 };
LL< Log::VERBOSE > VERBOSE
Verbose information.
Definition: Logger.cc:57
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:55
LL< Log::DEBUG > DEBUG
Debug information.
Definition: Logger.cc:58
LL< Log::FATAL > FATAL
Fatal log level.
Definition: Logger.cc:52
LL< Log::ERROR > ERROR
Error log level.
Definition: Logger.cc:53
LL< Log::WARN > WARN
Warning log level.
Definition: Logger.cc:54
LL< Log::DEFAULT > DEFAULT
Default log level.
Definition: Logger.cc:56

Function Documentation

◆ operator<=()

constexpr bool operator<= ( const Log  rhs,
const Log  lhs 
)
constexpr

Internally used to filter on loglevel. Do not edit, as this is required for an optimised logger.

used for the implementation of different loglevels; the operator compares current loglevel to a fixed one and thus checks if a message should be logged.

141 {
142  return ((static_cast<signed char>(rhs)) <= (static_cast<signed char>(lhs)));
143 }

Variable Documentation

◆ cgLogger

Logger<CG_LOGLEVEL> cgLogger
extern

◆ DEBUG

LL<Log::DEBUG> DEBUG
extern

Debug information.

Only used for internal development. Can be very cryptic, as it is only meant for finding bugs / oddities by the internal development team.

Example: Collision found between Particle #38201 and Wall #5

Default behaviour: ignore.

Referenced by BaseHandler< T >::BaseHandler(), load(), main(), SmallMatrix< numberOfRows, numberOfColumns >::operator*(), operator*(), CGFields::OrientationField::OrientationField(), CGFields::OrientationField::setFields(), BaseHandler< T >::~BaseHandler(), MixedSpecies< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >::~MixedSpecies(), and Species< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >::~Species().

◆ DEFAULT

LL<Log::DEFAULT> DEFAULT
extern

Default log level.

Only useful for defining the loglevel of the logger itself. Should not actually be used.

◆ ERROR

LL<Log::ERROR> ERROR
extern

Error log level.

Error, as in, the program has found a severe problem which it cannot resolve any further. It does not know how to recover in a sane way. The difference to FATAL is mainly that this type of failure is most often caused by human error.

Example: Negative time step, Infinite end time and no override of the continuation function.

Default behaviour: log to std::cerr, followed by std::exit().

Referenced by addObject(), CLiveStatistics< T >::CLiveStatistics(), commandLineCG(), SmallMatrix< numberOfRows, numberOfColumns >::computeWedgeStuffVector(), SmallMatrix< numberOfRows, numberOfColumns >::determinant(), SolidProblem< ELEMENT_TYPE >::get_x(), BaseHandler< T >::getObjectById(), BaseHandler< T >::getObjectsById(), helpers::getSaveCountFromNumberOfSavesAndTimeMaxAndTimeStep(), main(), Species< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >::mixAll(), helpers::more(), operator<<(), operator>>(), helpers::readArrayFromFile(), NurbsSurface::set(), Statistics(), statistics_while_running< T >::statistics_while_running(), test1(), test2(), and SolidProblem< ELEMENT_TYPE >::writeToVTK().

◆ FATAL

LL<Log::FATAL> FATAL
extern

Fatal log level.

The following are the loglevels which should be used to control the logger. They are declared here but defined in Logger.cc.

Fatal, as in, the program has suffered from the worst possible failure and there is no way it can gracefully recover. The difference to ERROR is mainly that this type of failure is most often caused by non-human error

Example: No memory allocations possible

Default behaviour: log to std::cerr, followed by std::exit().

Fatal log level.

Referenced by compareParticles(), main(), and transformMercuryToVTK().

◆ INFO

LL<Log::INFO> INFO
extern

Info log level.

Useful information, small oddities and statistics which should be of no real effect to the user, but still give useful information about the current state and progress of the program.

Example: Finished inserting 381 particles.

Default behaviour: log to std::cout, returns afterwards.

Referenced by helpers::addToFile(), checkTemplate(), CLiveStatistics< T >::CLiveStatistics(), commandLineCG(), helpers::compare(), computeFFc(), SCoupling< M, O >::computeOneTimeStepForSCoupling(), computeSimpleFFc(), SolidProblem< ELEMENT_TYPE >::countPinned(), NurbsUtils::extendKnotVector(), SolidProblem< ELEMENT_TYPE >::get_x(), getLinearFit(), SCoupling< M, O >::getSCoupledElements(), mathsFunc::goldenSectionSearch(), helpers::readFromCommandLine< std::string >(), HstopCurve(), ScaleCoupling< M, O >::initialiseCoupledElements(), load(), LoadClumps(), loadingTest(), LoadMass(), LoadPD(), LoadPebbles(), SolidProblem< ELEMENT_TYPE >::loadSolidMesh(), LoadTOI(), main(), helpers::more(), normalAndTangentialLoadingTest(), objectivenessTest(), particleParticleTest(), SolidProblem< ELEMENT_TYPE >::pinBoundaries(), SolidProblem< ELEMENT_TYPE >::pinBoundary(), PointIsAboveCurve(), SolidProblem< ELEMENT_TYPE >::prepareForSolve(), helpers::readArrayFromCommandLine(), helpers::readFromCommandLine(), helpers::readFromFile(), helpers::readVectorFromCommandLine(), SolidProblem< ELEMENT_TYPE >::saveSolidMesh(), NurbsSurface::set(), SolidProblem< ELEMENT_TYPE >::setBodyForceAsGravity(), SolidProblem< ELEMENT_TYPE >::setDensity(), SolidProblem< ELEMENT_TYPE >::setElasticModulus(), SolidProblem< ELEMENT_TYPE >::setIsPinned(), SolidProblem< ELEMENT_TYPE >::setName(), SolidProblem< ELEMENT_TYPE >::setOomphGravity(), SolidProblem< ELEMENT_TYPE >::setPoissonRatio(), SolidProblem< ELEMENT_TYPE >::setSolidCubicMesh(), Thermal< Particle >::setTimeDependentTemperature(), SolidProblem< ELEMENT_TYPE >::SolidProblem(), ScaleCoupling< M, O >::solveScaleCoupling(), SolidProblem< ELEMENT_TYPE >::solveSteady(), SCoupling< M, O >::solveSurfaceCoupling(), SCoupling< M, O >::solveSurfaceCouplingFixedSolid(), SolidProblem< ELEMENT_TYPE >::solveUnsteady(), Statistics(), statistics_while_running< T >::statistics_while_running(), test1(), test2(), testCGHandler(), transformMercuryToVTK(), wallParticleTest(), and SolidProblem< ELEMENT_TYPE >::writeToVTK().

◆ logger

Logger<MERCURYDPM_LOGLEVEL> logger
extern

Default logger. Use this for general logging.

For very specific modules, define your own logger. If you want to make extensive use of Debug messages, please use a custom logger as well, to prevent polluting the output.

◆ loggerOutput

LoggerOutput* loggerOutput
extern

Declaration of the output functions.

If the output needs to be redirected, please swap the loggerOutput pointer to your preferred LoggerOutput instance, and make sure this exists until AFTER an std::exit() invocation. (e.g. clean up with std::atexit())

Referenced by Logger< L, ASSERTS >::if(), main(), and Logger< L, ASSERTS >::operator()().

◆ VERBOSE

LL<Log::VERBOSE> VERBOSE
extern

Verbose information.

Information which is not useful to anybody except those looking for weird behaviour. These should however still be clear in meaning.

Example: Finished creating a particle.

Default behaviour: ignore.

Referenced by ScaleCoupling< M, O >::computeCouplingForce(), ScaleCoupling< M, O >::computeNodalCouplingForces(), NurbsSurface::getDistance(), ScaleCoupling< M, O >::initialiseCoupledElements(), load(), LoadClumps(), main(), BaseHandler< T >::read(), ScaleCoupling< M, O >::CoupledParticle::removeCoupledElement(), ScaleCoupling< M, O >::CoupledParticle::setCoupledElement(), and ScaleCoupling< M, O >::updateCoupledElements().

◆ WARN