ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
message.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdio>
4#include <fmt/format.h>
5#include <fmt/color.h>
6#include <fmt/ranges.h>
8#include <ctime>
9#include <chrono>
10#include <iomanip>
11
23enum class VerbosityLevel : char
24{
25 None, // No message output
26 Error, // fatal errors are printed
27 Warning, // warnings are printend
28 Result, // results of the analysis (including CE)
29 Progress, // progress notifications
30 Success, // verification success/claim holds
31 Fail, // verification/claim fails
32 Status, // all kinds of things esbmc is doing that may be useful to the user
33 Debug // messages that are only useful if you need to debug.
34};
35
37{
38 static inline class statet
39 {
40 static void println(
41 FILE *f,
43 fmt::string_view format,
44 fmt::format_args args);
45
46 public:
48 std::unordered_map<std::string, VerbosityLevel> modules;
50
51 FILE *target(const char *mod, VerbosityLevel lvl) const;
52
53 void set_flushln() const;
54
55 template <typename... Args>
56 bool logln(
57 const char *mod,
59 const char *file,
60 int line,
61 fmt::format_string<Args...> format,
62 Args &&...args) const
63 {
64 FILE *f = target(mod, lvl);
65 if (!f)
66 return false;
67 if (config.options.get_bool_option("log-message"))
68 {
69 std::time_t currentTime = std::chrono::system_clock::to_time_t(
70 std::chrono::system_clock::now());
71 std::string timeStr =
72 (std::ostringstream{}
73 << std::put_time(std::localtime(&currentTime), "%Y-%m-%d %H:%M:%S"))
74 .str();
75 fmt::print(f, "[{}] File: {}, Line: {} ", timeStr, file, line);
76 }
77 println(f, lvl, format, fmt::make_format_args(args...));
78 return true;
79 }
81};
82
83#define log_error(fmt, ...) \
84 messaget::state.logln( \
85 nullptr, VerbosityLevel::Error, __FILE__, __LINE__, FMT_STRING(fmt), ##__VA_ARGS__)
86#define log_result(fmt, ...) \
87 messaget::state.logln( \
88 nullptr, VerbosityLevel::Result, __FILE__, __LINE__, FMT_STRING(fmt), ##__VA_ARGS__)
89#define log_warning(fmt, ...) \
90 messaget::state.logln( \
91 nullptr, VerbosityLevel::Warning, __FILE__, __LINE__, FMT_STRING(fmt), ##__VA_ARGS__)
92#define log_progress(fmt, ...) \
93 messaget::state.logln( \
94 nullptr, VerbosityLevel::Progress, __FILE__, __LINE__, FMT_STRING(fmt), ##__VA_ARGS__)
95#define log_success(fmt, ...) \
96 messaget::state.logln( \
97 nullptr, VerbosityLevel::Success, __FILE__, __LINE__, FMT_STRING(fmt), ##__VA_ARGS__)
98#define log_fail(fmt, ...) \
99 messaget::state.logln( \
100 nullptr, VerbosityLevel::Fail, __FILE__, __LINE__, FMT_STRING(fmt), ##__VA_ARGS__)
101#define log_status(fmt, ...) \
102 messaget::state.logln( \
103 nullptr, VerbosityLevel::Status, __FILE__, __LINE__, FMT_STRING(fmt), ##__VA_ARGS__)
104#define log_debug(mod, fmt, ...) \
105 messaget::state.logln( \
106 mod, VerbosityLevel::Debug, __FILE__, __LINE__, FMT_STRING(fmt), ##__VA_ARGS__)
Definition message.h:39
FILE * out
Definition message.h:49
bool logln(const char *mod, VerbosityLevel lvl, const char *file, int line, fmt::format_string< Args... > format, Args &&...args) const
Definition message.h:56
FILE * target(const char *mod, VerbosityLevel lvl) const
Definition message.cpp:64
VerbosityLevel verbosity
Definition message.h:47
std::unordered_map< std::string, VerbosityLevel > modules
Definition message.h:48
void set_flushln() const
Definition message.cpp:73
configt config
Definition config.cpp:8
VerbosityLevel
Verbosity refers to the max level of which inputs are going to be printed out.
Definition message.h:24
@ Warning
Definition message.h:27
@ Progress
Definition message.h:29
@ Success
Definition message.h:30
@ None
Definition message.h:25
@ Result
Definition message.h:28
@ Error
Definition message.h:26
@ Debug
Definition message.h:33
@ Fail
Definition message.h:31
@ Status
Definition message.h:32
FILE * stderr
__ESBMC_C_CPP_BEGIN struct __esbmc_file_t FILE
Definition message.h:37
static class messaget::statet state