remage
Simulation framework for HPGe-based experiments
 
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 <cstdarg>
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
58class RMGLog {
59
60 public:
61
62 // definition of log level
63
66 enum LogLevel {
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
181 static std::string fVersion;
182
185 static RMGLog::LogLevel fMinimumLogLevel;
186
189 static bool fFirstOutputDone;
190
193 static bool fHadWarning;
194
197 static bool fHadError;
198
201 static bool fUsePrefix;
202
205 static int fProcNum;
206};
207
208#include "RMGLog.icc"
209
210#endif
211
212// vim: tabstop=2 shiftwidth=2 expandtab
LogLevel
Definition RMGLog.hh:66
@ error
Print only errors.
Definition RMGLog.hh:72
@ nothing
Print nothing.
Definition RMGLog.hh:74
@ warning
Print only warnings and errors.
Definition RMGLog.hh:71
@ debug_event
Print everything, including debug info (also in the event loop)
Definition RMGLog.hh:67
@ detail
Print all details of operation.
Definition RMGLog.hh:69
@ fatal
Print only errors, stop execution.
Definition RMGLog.hh:73
@ summary
Print only results summary, warnings, and errors.
Definition RMGLog.hh:70
@ debug
Print everything, including debug info (not in the event loop)
Definition RMGLog.hh:68
static void SetProcNum(int proc_num)
Definition RMGLog.hh:125
static RMGLog::LogLevel GetLogLevel()
Definition RMGLog.hh:103
static bool GetPrefix()
Definition RMGLog.hh:108
static const std::string & GetVersion()
Definition RMGLog.hh:158
static void SetLogLevel(RMGLog::LogLevel loglevel)
Definition RMGLog.hh:117
RMGLog()
Definition RMGLog.cc:72
static void SetInihibitStartupInfo(bool flag)
Definition RMGLog.hh:129
static void SetPrefix(bool flag)
Definition RMGLog.hh:121
static void StartupInfo()
Definition RMGLog.cc:82
static void Out(RMGLog::LogLevel loglevel, const T &message)