remage
Simulation framework for HPGe-based experiments
Toggle main menu visibility
Loading...
Searching...
No Matches
RMGLog.hh
1
// Copyright (C) 2022 Luigi Pertoldi <https://orcid.org/0000-0002-0467-2571>
2
//
3
// This program is free software: you can redistribute it and/or modify it under
4
// the terms of the GNU Lesser General Public License as published by the Free
5
// Software Foundation, either version 3 of the License, or (at your option) any
6
// later version.
7
//
8
// This program is distributed in the hope that it will be useful, but WITHOUT
9
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11
// details.
12
//
13
// You should have received a copy of the GNU Lesser General Public License
14
// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16
17
// Modified by Luigi Pertoldi <https://orcid.org/0000-0002-0467-2571> in 2022
18
19
#ifndef _RMG_LOG_HH_
20
#define _RMG_LOG_HH_
21
31
32
/*
33
* Copyright (C) 2007-2018, the BAT core developer team
34
* All rights reserved.
35
*
36
* For the licensing terms see doc/COPYING.
37
* For documentation see http://mpp.mpg.de/bat
38
*/
39
40
// ---------------------------------------------------------
41
42
#include <atomic>
43
#include <fstream>
44
#include <iostream>
45
#include <string>
46
47
#include "globals.hh"
48
49
#include "fmt/core.h"
50
51
#define OutDev(loglevel, ...) RMGLog::Out(loglevel, "[", __PRETTY_FUNCTION__, "] ", __VA_ARGS__)
52
53
#define OutFormatDev(loglevel, fmt, ...) \
54
RMGLog::OutFormat(loglevel, "[" + std::string(__PRETTY_FUNCTION__) + "] " + fmt, __VA_ARGS__)
55
56
// ---------------------------------------------------------
57
58
class
RMGLog
{
59
60
public
:
61
62
// definition of log level
63
66
enum
LogLevel
{
67
debug_event
= 0,
68
debug
= 10,
69
detail
= 20,
70
summary
= 30,
71
warning
= 40,
72
error
= 50,
73
fatal
= 60,
74
nothing
= 70
75
};
76
77
enum
Ansi {
78
black = 30,
79
red = 31,
80
green = 32,
81
yellow = 33,
82
blue = 34,
83
magenta = 35,
84
cyan = 36,
85
grey = 37,
86
unspecified
87
};
88
91
94
RMGLog
();
95
99
103
static
RMGLog::LogLevel
GetLogLevel
() {
return
fMinimumLogLevel; }
104
108
static
bool
GetPrefix
() {
return
fUsePrefix; }
109
113
117
static
void
SetLogLevel
(
RMGLog::LogLevel
loglevel) { fMinimumLogLevel = loglevel; }
118
121
static
void
SetPrefix
(
bool
flag) { fUsePrefix = flag; }
122
125
static
void
SetProcNum
(
int
proc_num) { fProcNum = proc_num; }
126
129
static
void
SetInihibitStartupInfo
(
bool
flag) { fFirstOutputDone = flag; }
130
134
139
template
<
typename
T>
static
void
Out
(
RMGLog::LogLevel
loglevel,
const
T& message);
140
141
template
<
typename
T,
typename
... Args>
142
static
void
Out
(
RMGLog::LogLevel
loglevel,
const
T& msg_first,
const
Args&... args);
143
144
template
<
typename
... Args>
145
static
void
OutFormat(
RMGLog::LogLevel
loglevel,
const
std::string& fmt,
const
Args&... args);
146
147
template
<
typename
T,
typename
... Args>
148
static
void
Out
(
RMGLog::LogLevel
loglevel, T& msg_first, Args... msg_other) {
149
RMGLog::Out
(loglevel, msg_first, msg_other...);
150
}
151
154
static
void
StartupInfo
();
155
158
static
const
std::string&
GetVersion
() {
return
fVersion; }
159
160
static
bool
SupportsColors(
const
std::ostream& os);
161
162
template
<RMGLog::Ansi color,
typename
T>
163
static
std::string Colorize(
const
T& msg, std::ostream& os,
bool
bold =
false
);
164
165
static
bool
HadWarning() {
return
fHadWarning; }
166
static
bool
HadError() {
return
fHadError; }
167
169
170
private
:
171
172
template
<
typename
T>
173
static
void
Print(
RMGLog::LogLevel
loglevel,
const
T& msg,
bool
prefixed =
true
,
bool
do_flush =
true
);
174
177
static
std::string
GetPrefix
(
RMGLog::LogLevel
, std::ostream& os);
178
182
static
bool
ShouldPrintWithLevel(
RMGLog::LogLevel
loglevel);
183
186
static
std::string fVersion;
187
190
static
RMGLog::LogLevel
fMinimumLogLevel;
191
194
static
std::atomic<bool> fFirstOutputDone;
195
198
static
std::atomic<bool> fHadWarning;
199
202
static
std::atomic<bool> fHadError;
203
206
static
bool
fUsePrefix;
207
210
static
int
fProcNum;
211
};
212
213
#include "RMGLog.icc"
214
215
#endif
216
217
// vim: tabstop=2 shiftwidth=2 expandtab
RMGLog::LogLevel
LogLevel
Definition
RMGLog.hh:66
RMGLog::error
@ error
Print only errors.
Definition
RMGLog.hh:72
RMGLog::nothing
@ nothing
Print nothing.
Definition
RMGLog.hh:74
RMGLog::warning
@ warning
Print only warnings and errors.
Definition
RMGLog.hh:71
RMGLog::debug_event
@ debug_event
Print everything, including debug info (also in the event loop).
Definition
RMGLog.hh:67
RMGLog::detail
@ detail
Print all details of operation.
Definition
RMGLog.hh:69
RMGLog::fatal
@ fatal
Print only errors, stop execution.
Definition
RMGLog.hh:73
RMGLog::summary
@ summary
Print only results summary, warnings, and errors.
Definition
RMGLog.hh:70
RMGLog::debug
@ debug
Print everything, including debug info (not in the event loop).
Definition
RMGLog.hh:68
RMGLog::SetProcNum
static void SetProcNum(int proc_num)
Definition
RMGLog.hh:125
RMGLog::GetLogLevel
static RMGLog::LogLevel GetLogLevel()
Definition
RMGLog.hh:103
RMGLog::GetPrefix
static bool GetPrefix()
Definition
RMGLog.hh:108
RMGLog::GetVersion
static const std::string & GetVersion()
Definition
RMGLog.hh:158
RMGLog::SetLogLevel
static void SetLogLevel(RMGLog::LogLevel loglevel)
Definition
RMGLog.hh:117
RMGLog::RMGLog
RMGLog()
Definition
RMGLog.cc:72
RMGLog::SetInihibitStartupInfo
static void SetInihibitStartupInfo(bool flag)
Definition
RMGLog.hh:129
RMGLog::SetPrefix
static void SetPrefix(bool flag)
Definition
RMGLog.hh:121
RMGLog::StartupInfo
static void StartupInfo()
Definition
RMGLog.cc:82
RMGLog::Out
static void Out(RMGLog::LogLevel loglevel, const T &message)
include
RMGLog.hh
Generated by
1.17.0