80 #include <TObjString.h>
83 #include <RAT/json.hh>
89 #include "dprintf.hpp"
91 #include "multiio.hpp"
92 #include "string_utilities.hpp"
93 #include "stringio.hpp"
131 [[noreturn]]
static void Die(std::string message,
int return_code = 1);
136 static void Assert(
bool condition, std::string message,
int return_code = 1);
147 static void AddObject(
const std::string &name, TObject *obj) {
148 objects.push_back(std::pair<std::string, TObject *>(name, obj));
165 inline static void TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
168 inline static void TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
171 inline static void TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
172 const std::string &value);
175 inline static void TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
176 const std::vector<int> &value);
178 inline static void TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
179 const std::vector<double> &value);
181 inline static void TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
182 const std::vector<std::string> &value);
185 inline static void TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
188 static TMap *GetDBTraceMap() {
return dbtrace; };
195 inline static void AddDBEntry(
const std::string &key,
const std::string &value);
222 static std::vector<std::pair<std::string, TObject *>>
objects;
234 dbtrace->Add(
new TObjString(key.c_str()),
new TObjString(value.c_str()));
239 inline std::string to_ratdb_float_string(
double value) {
241 return std::string(
"0.0");
243 return ::to_string(value);
246 inline std::string to_ratdb_double_string(
double value) {
247 std::string str = to_ratdb_float_string(value);
248 size_t pos = str.find(
"d");
249 if (pos == std::string::npos) str +=
"d";
253 inline std::string escape_ratdb_string(
const std::string &value) {
254 if (value.find(
"\"") != std::string::npos)
Log::Die(
"RATDB Trace Eror: value string with quotes inside!");
255 return "\"" + value +
"\"";
258 void Log::TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
int value) {
259 AddDBEntry(table +
"[" + index +
"]." + field, ::to_string(value));
262 void Log::TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
double value) {
263 AddDBEntry(table +
"[" + index +
"]." + field, to_ratdb_double_string(value));
266 void Log::TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
267 const std::string &value) {
268 AddDBEntry(table +
"[" + index +
"]." + field, escape_ratdb_string(value));
271 void Log::TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
272 const std::vector<int> &value) {
273 std::string key = table +
"[" + index +
"]." + field;
276 std::string str_value(
"[ ");
277 for (
unsigned i = 0; i < value.size(); i++) {
278 str_value += ::to_string(value[i]) +
", ";
285 void Log::TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
286 const std::vector<double> &value) {
287 std::string key = table +
"[" + index +
"]." + field;
290 std::string str_value(
"[ ");
291 for (
unsigned i = 0; i < value.size(); i++) {
292 str_value += to_ratdb_double_string(value[i]) +
", ";
299 void Log::TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
300 const std::vector<std::string> &value) {
301 std::string key = table +
"[" + index +
"]." + field;
304 std::string str_value(
"[ ");
305 for (
unsigned i = 0; i < value.size(); i++) {
306 str_value += escape_ratdb_string(value[i]) +
", ";
313 void Log::TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
315 std::string key = table +
"[" + index +
"]." + field;
318 std::stringstream ss;
320 writer.putValue(value);
static int log_level
Definition: Log.hh:215
static std::vector< std::pair< std::string, TObject * > > objects
Definition: Log.hh:222
static void AddDBEntry(const std::string &key, const std::string &value)
Inline functions.
Definition: Log.hh:232
static void SetDBTraceState(bool state=true)
Definition: Log.hh:159
static void AddObject(const std::string &name, TObject *obj)
Definition: Log.hh:147
static const std::string GetLogBuffer()
Definition: Log.cc:122
static bool GetDBTraceState()
Definition: Log.hh:162
static void Die(std::string message, int return_code=1)
Definition: Log.cc:90
static const std::string & GetMacro()
Definition: Log.hh:144
static void SetLogLevel(Level level)
Definition: Log.cc:85
static omtext * outstreams[4]
Definition: Log.hh:210
static std::vector< std::pair< std::string, TObject * > > GetObjects()
Definition: Log.hh:153
static int GetDisplayLevel()
Definition: Log.hh:118
static void TraceDBAccess(const std::string &table, const std::string &index, const std::string &field, int value)
Definition: Log.hh:258
Level
Definition: Log.hh:100
@ INFO
Definition: Log.hh:102
@ DETAIL
Definition: Log.hh:103
@ DEBUG
Definition: Log.hh:105
@ WARN
Definition: Log.hh:101
static TMap * dbtrace
Definition: Log.hh:220
static int GetLogLevel()
Definition: Log.hh:124
static std::string filename
Definition: Log.hh:212
static oftext logfile
Definition: Log.hh:213
static void AddMacro(const std::string &contents)
Definition: Log.hh:142
static std::string macro
Definition: Log.hh:217
static void Assert(bool condition, std::string message, int return_code=1)
Definition: Log.cc:95
static void SetupIO()
Definition: Log.cc:102
static bool enable_dbtrace
Definition: Log.hh:219
static void SetDisplayLevel(Level level)
Definition: Log.cc:80
static int display_level
Definition: Log.hh:214
static void ClearOMText(omtext *out)
Definition: Log.cc:117
Log()
Definition: Log.cc:59
static bool Init(std::string _filename, Level display=INFO, Level log=DETAIL)
Definition: Log.cc:63
Definition: fileio.hpp:22
Definition: multiio.hpp:18
Definition: CCCrossSecMessenger.hh:29