Antares Xpansion
Investment simulations for Antares studies
Loading...
Searching...
No Matches
LogUtils.h
1#pragma once
2#include <stdexcept>
3#include <string>
4
5namespace LogUtils
6{
7inline std::string LogLocationToStr(int line, const char* file, const char* func)
8{
9 return std::string("Logged from function '") + func + "' in file '" + file + "' at line "
10 + std::to_string(line) + ".\n";
11}
12
13template<typename T>
14class XpansionError: public T
15{
16public:
17 explicit XpansionError(const std::string& err_message, const std::string& log_location):
18 T(log_location + err_message),
19 err_message_(err_message)
20 {
21 }
22
23 explicit XpansionError(const std::string& prefix,
24 const std::string& err_message,
25 const std::string& log_location):
26 T(log_location + prefix + err_message),
27 err_message_(err_message)
28 {
29 }
30
31public:
32 std::string ErrorMessage() const
33 {
34 return err_message_;
35 }
36
37private:
38 const std::string err_message_;
39};
40
41enum class LOGLEVEL
42{
43 NONE,
44 TRACE,
45 DEBUG,
46 INFO,
47 WARNING,
48 ERR,
49 FATAL
50};
51enum class LOGGERTYPE
52{
53 NONE,
54 FILE,
55 CONSOLE
56};
57
58inline std::string LogLevelToStr(const LogUtils::LOGLEVEL log_level)
59{
60 switch (log_level)
61 {
62 case LogUtils::LOGLEVEL::TRACE:
63 return "TRACE";
64 case LogUtils::LOGLEVEL::DEBUG:
65 return "DEBUG";
66 case LogUtils::LOGLEVEL::INFO:
67 return "INFO";
68 case LogUtils::LOGLEVEL::WARNING:
69 return "WARNING";
70 case LogUtils::LOGLEVEL::ERR:
71 return "ERROR";
72 case LogUtils::LOGLEVEL::FATAL:
73 return "FATAL";
74 default:
75 return "";
76 }
77}
78} // namespace LogUtils
79
80#define LOGLOCATION LogUtils::LogLocationToStr(__LINE__, __FILE__, __func__)