11#ifndef MCRL2_UTILITIES_LOGGER_H
12#define MCRL2_UTILITIES_LOGGER_H
47 static const char*
const buffer[] = {
"quiet",
"error",
"warning",
"info",
"status",
"verbose",
"debug",
"trace"};
48 if ((
unsigned) level >=
sizeof(buffer) /
sizeof(buffer[0]))
return "unknown level";
60 else if (s ==
"error")
64 else if (s ==
"warning")
72 else if (s ==
"status")
76 else if (s ==
"verbose")
80 else if (s ==
"debug")
84 else if (s ==
"trace")
90 throw std::runtime_error(
"Unknown log-level " + s +
" provided.");
117 virtual void output(
const log_level_t level,
const time_t timestamp,
const std::string& msg,
const bool print_time_information) = 0;
150 thread_local bool print_timing_info=
false;
151 return print_timing_info;
159 return m_output_policies;
193 std::set<output_policy*>::iterator i =
output_policies().find(&policy);
259 static std::string
format(
const log_level_t level,
const time_t timestamp,
const std::string& msg,
const bool print_time_information)
262 (void)level; (void)timestamp; (void)print_time_information;
264 assert(
quiet != level);
280 static std::atomic<bool> m_last_message_ended_with_newline =
true;
281 return m_last_message_ended_with_newline;
287 static std::atomic<bool> m_last_message_was_status =
false;
288 return m_last_message_was_status;
294 static std::atomic<std::size_t> m_caret_pos = 0;
301 static std::atomic<std::size_t> m_last_caret_pos = 0;
302 return m_last_caret_pos;
311 static std::string
format(
const log_level_t level,
const time_t timestamp,
const std::string& msg,
const bool print_time_information);
323 static std::atomic<FILE*> g_stream(stderr);
350 virtual void output(
const log_level_t level,
const time_t timestamp,
const std::string& msg,
const bool print_time_information)
override
352 assert(
quiet != level);
359 fprintf(p_stream,
"%s",
formatter::format(level, timestamp, msg, print_time_information).c_str());
377 std::set<output_policy*> result;
391#define mCRL2log(LEVEL) if (mcrl2::log::mCRL2logEnabled(LEVEL)) mcrl2::log::logger(LEVEL).get()
static void set_stream(FILE *stream)
virtual void output(const log_level_t level, const time_t timestamp, const std::string &msg, const bool print_time_information) override
static std::atomic< FILE * > & get_stream()
Obtain the underlying stream used to print to a file.
Class for logging messages.
static bool & m_print_time_information()
An indication whether time information should be printed.
static void clear_report_time_info()
Indicate that timing information should not be printed.
static void unregister_output_policy(output_policy &policy)
Unregister output policy.
static void set_report_time_info()
Indicate that timing information should be printed.
log_level_t m_level
The loglevel of the current message.
static std::set< output_policy * > & output_policies()
Output policies.
static log_level_t get_reporting_level()
Get reporting level.
static void set_reporting_level(const log_level_t level)
Set reporting level.
std::ostringstream & get()
logger(const log_level_t l)
Default constructor.
static void clear_output_policies()
Clear all output policies.
time_t m_timestamp
Timestamp of the current message.
static void register_output_policy(output_policy &policy)
Register output policy.
~logger()
Destructor; flushes output. Flushing during destruction is important to confer thread safety to the l...
static bool get_report_time_info()
Get whether timing information is printed.
static std::atomic< log_level_t > & log_level()
std::ostringstream m_os
Stream that is printed to internally Collects the full debug message that we are currently printing.
Interface class for output policy.
output_policy()
Constructor.
virtual void output(const log_level_t level, const time_t timestamp, const std::string &msg, const bool print_time_information)=0
Output message.
virtual ~output_policy()
Destructor.
Inherit from this class to prevent it from being copyable.
output_policy & default_output_policy()
The default output policy used by the logger.
std::string log_level_to_string(const log_level_t level)
Convert log level to string This string is used to prefix messages in the logging output.
std::string format_time(const time_t *t)
std::set< output_policy * > initialise_output_policies()
Initialise the output policies. This returns the singleton set containing the default output policy.
log_level_t
Log levels that are supported.
log_level_t log_level_from_string(const std::string &s)
Convert string to log level.
bool mCRL2logEnabled(const log_level_t level)
String manipulation functions.