xerus
a general purpose tensor library
namedLogger.h File Reference

Header file for all logging macros and log-buffer functionality. More...

#include <mutex>
#include <string>
#include <sstream>
#include "callStack.h"
#include "exceptions.h"
#include <iostream>

Go to the source code of this file.

Classes

struct  xerus::misc::internal::LogFlag< lvl >
 

Namespaces

 xerus
 The main namespace of xerus.
 
 xerus::misc
 Collection of classes and functions that provide elementary functionality that is not special to xerus as a tensor library.
 
 xerus::misc::internal
 Namespace for function and classes designated only for internal use.
 
 xerus::misc::internal::buffer
 

Macros

#define XERUS_COMPILE_TIME_EVAL(e)   (std::integral_constant<decltype(e), e>::value)
 forces the compiler to evaluate e during compilation More...
 
#define XERUS_IS_LOGGING(lvl)   (::xerus::misc::internal::LogFlag<xerus::misc::internal::log_namehash(XERUS_STRINGIFY(lvl))>::flag != xerus::misc::internal::NOT_LOGGING)
 evaluates to true if lvl is begin logged (either to cerr or into a file on error) in the current configuration More...
 
#define XERUS_LOG(lvl, ...)
 logs the message msg with severity level lvl More...
 
#define XERUS_LOG_ONCE(lvl, ...)
 logs the message msg with severity level lvl at most once per program execution More...
 
#define XERUS_LOG_SHORT(lvl, ...)
 logs the message msg with severity level lvl, omits the current file name and line number More...
 
#define XERUS_LOGSTREAM   std::cerr
 
#define XERUS_NAMED_LOGGER_LOGBUFFER(lvl)
 
#define XERUS_SET_DEFAULT_LOG_LEVELS
 
#define XERUS_SET_LOGGING(lvl, value)
 set the logging behaviour of severity level lvl to value (either NOT_LOGGING, LOGGING_ON_ERROR or LOGGING_FULL) More...
 
#define XERUS_STRINGIFY(x)   XERUS_STRINGIFY2(x)
 
#define XERUS_STRINGIFY2(x)   #x
 

Enumerations

enum  { xerus::misc::internal::NOT_LOGGING = 0, xerus::misc::internal::LOGGING_FULL = 2, xerus::misc::internal::LOGGING_EXCEPTION = 3 }
 

Functions

void xerus::misc::internal::buffer::checkSwitch ()
 
void xerus::misc::internal::buffer::dump_log (std::string _comment)
 
std::ostream & xerus::misc::internal::get_fileStream ()
 
constexpr uint64_t xerus::misc::internal::log_namehash (const char *x)
 Hashes a given c-string using the FNV-1a standard hash. More...
 
void xerus::misc::internal::log_timestamp (std::ostream &_out, const char *_file, int _line, const char *_lvl)
 
void xerus::misc::internal::log_timestamp (std::ostream &_out, const char *_lvl)
 
void xerus::misc::internal::log_timestamp (std::ostream &_out)
 

Variables

std::stringstream xerus::misc::internal::buffer::current
 
std::string xerus::misc::internal::logFilePrefix
 
static const auto xerus::misc::internal::LOGGING_ON_ERROR = NOT_LOGGING
 
std::mutex xerus::misc::internal::namedLoggerMutex
 
std::stringstream xerus::misc::internal::buffer::old
 
std::chrono::system_clock::time_point xerus::misc::internal::programStartTime
 
bool xerus::misc::internal::silenced = false
 

Detailed Description

Header file for all logging macros and log-buffer functionality.

Definition in file namedLogger.h.

Macro Definition Documentation

◆ XERUS_COMPILE_TIME_EVAL

#define XERUS_COMPILE_TIME_EVAL (   e)    (std::integral_constant<decltype(e), e>::value)

forces the compiler to evaluate e during compilation

Definition at line 100 of file namedLogger.h.

◆ XERUS_IS_LOGGING

evaluates to true if lvl is begin logged (either to cerr or into a file on error) in the current configuration

Definition at line 198 of file namedLogger.h.

◆ XERUS_LOG

#define XERUS_LOG (   lvl,
  ... 
)
Value:
std::stringstream tmpStream; \
tmpStream << __VA_ARGS__ << std::endl; \
XERUS_LOGSTREAM << tmpStream.str() << std::flush; \
} \
XERUS_NAMED_LOGGER_LOGBUFFER(lvl) \
XERUS_THROW(xerus::misc::generic_error() << __FILE__ << ":" << __LINE__ << ": " XERUS_STRINGIFY(lvl) " invoked:\n" << tmpStream.str() << "callstack:\n" << xerus::misc::get_call_stack()); \
} \
} else \
(void)0
#define XERUS_STRINGIFY(x)
Definition: namedLogger.h:93
constexpr uint64_t log_namehash(const char *x)
Hashes a given c-string using the FNV-1a standard hash.
Definition: namedLogger.h:49
void log_timestamp(std::ostream &_out)
Definition: namedLogger.cpp:46
std::string get_call_stack()
Returns a string representation of the current call-stack (excluding the function itself)...
Definition: callStack.cpp:166
#define XERUS_LOGSTREAM
Definition: namedLogger.h:39
The xerus exception class.
Definition: exceptions.h:37
std::mutex namedLoggerMutex
Definition: namedLogger.cpp:38

logs the message msg with severity level lvl

the exact behaviour is modified by the SET_DEFAULT_LOG_LEVELS and XERUS_SET_LOGGING macros. In case lvl is not being logged with the current configuration, this macro evaluates to an if (false) {} expression and is fully removed by the compiler.

Definition at line 139 of file namedLogger.h.

◆ XERUS_LOG_ONCE

#define XERUS_LOG_ONCE (   lvl,
  ... 
)
Value:
{\
static bool logged = false;\
if (!logged) {\
XERUS_LOG(lvl, __VA_ARGS__);\
logged = true;\
}\
}

logs the message msg with severity level lvl at most once per program execution

the exact behaviour is modified by the SET_DEFAULT_LOG_LEVELS and XERUS_SET_LOGGING macros. In case lvl is not being logged with the current configuration, this macro evaluates to an if (false) {} expression and is fully removed by the compiler.

Definition at line 185 of file namedLogger.h.

◆ XERUS_LOG_SHORT

#define XERUS_LOG_SHORT (   lvl,
  ... 
)
Value:
std::stringstream tmpStream; \
tmpStream << __VA_ARGS__ << std::endl; \
XERUS_LOGSTREAM << tmpStream.str() << std::flush; \
} \
XERUS_NAMED_LOGGER_LOGBUFFER(lvl) \
XERUS_THROW(xerus::misc::generic_error() << XERUS_STRINGIFY(lvl) " error invoked:\n" << tmpStream.str() << "callstack:\n" << xerus::misc::get_call_stack()); \
} \
} else \
(void)0
#define XERUS_STRINGIFY(x)
Definition: namedLogger.h:93
constexpr uint64_t log_namehash(const char *x)
Hashes a given c-string using the FNV-1a standard hash.
Definition: namedLogger.h:49
void log_timestamp(std::ostream &_out)
Definition: namedLogger.cpp:46
std::string get_call_stack()
Returns a string representation of the current call-stack (excluding the function itself)...
Definition: callStack.cpp:166
#define XERUS_LOGSTREAM
Definition: namedLogger.h:39
The xerus exception class.
Definition: exceptions.h:37
std::mutex namedLoggerMutex
Definition: namedLogger.cpp:38

logs the message msg with severity level lvl, omits the current file name and line number

the exact behaviour is modified by the SET_DEFAULT_LOG_LEVELS and XERUS_SET_LOGGING macros. In case lvl is not being logged with the current configuration, this macro evaluates to an if (false) {} expression and is fully removed by the compiler.

Definition at line 162 of file namedLogger.h.

◆ XERUS_LOGSTREAM

#define XERUS_LOGSTREAM   std::cerr

Definition at line 39 of file namedLogger.h.

◆ XERUS_NAMED_LOGGER_LOGBUFFER

#define XERUS_NAMED_LOGGER_LOGBUFFER (   lvl)

Definition at line 127 of file namedLogger.h.

◆ XERUS_SET_DEFAULT_LOG_LEVELS

#define XERUS_SET_DEFAULT_LOG_LEVELS
Value:
XERUS_SET_LOGGING(critical, xerus::misc::internal::LOGGING_EXCEPTION)\
XERUS_SET_LOGGING(error, xerus::misc::internal::LOGGING_EXCEPTION)\
XERUS_SET_LOGGING(warning, xerus::misc::internal::LOGGING_FULL)\
XERUS_SET_LOGGING(info, xerus::misc::internal::LOGGING_FULL)\
XERUS_SET_LOGGING(debug, xerus::misc::internal::LOGGING_ON_ERROR)
#define XERUS_SET_LOGGING(lvl, value)
set the logging behaviour of severity level lvl to value (either NOT_LOGGING, LOGGING_ON_ERROR or LOG...
Definition: namedLogger.h:211
static const auto LOGGING_ON_ERROR
Definition: namedLogger.h:72

Definition at line 219 of file namedLogger.h.

◆ XERUS_SET_LOGGING

#define XERUS_SET_LOGGING (   lvl,
  value 
)
Value:
namespace xerus { namespace misc { namespace internal { \
template<> struct LogFlag<xerus::misc::internal::log_namehash(XERUS_STRINGIFY(lvl))>{ static const int flag = value; }; \
}}}
The main namespace of xerus.
Definition: basic.h:37
constexpr uint64_t log_namehash(const char *x)
Hashes a given c-string using the FNV-1a standard hash.
Definition: namedLogger.h:49

set the logging behaviour of severity level lvl to value (either NOT_LOGGING, LOGGING_ON_ERROR or LOGGING_FULL)

this definition must not be repeated and must be defined in a global header that is included before any msg is logged with that lvl

Definition at line 211 of file namedLogger.h.

◆ XERUS_STRINGIFY

#define XERUS_STRINGIFY (   x)    XERUS_STRINGIFY2(x)

Definition at line 93 of file namedLogger.h.

◆ XERUS_STRINGIFY2

#define XERUS_STRINGIFY2 (   x)    #x

Definition at line 92 of file namedLogger.h.