LoggingLevel.hpp
Go to the documentation of this file.
1 // @formatter:off
2 //
3 // Balau core C++ library
4 //
5 // Copyright (C) 2008 Bora Software (contact@borasoftware.com)
6 //
7 // Licensed under the Boost Software License - Version 1.0 - August 17th, 2003.
8 // See the LICENSE file for the full license text.
9 //
10 
16 
17 #ifndef COM_BORA_SOFTWARE__BALAU_LOGGING__LOGGING_LEVEL
18 #define COM_BORA_SOFTWARE__BALAU_LOGGING__LOGGING_LEVEL
19 
21 
22 namespace Balau {
23 
25 
32 enum class LoggingLevel {
36  TRACE = 4,
37 
41  DEBUG = 3,
42 
46  INFO = 2,
47 
51  WARN = 1,
52 
56  ERROR = 0,
57 
61  NONE = -1
62 };
63 
64 // The number of logging levels not including NONE (which never results in logging).
65 constexpr size_t _BalauLoggingLevelCount = 5;
66 
72 template <typename AllocatorT>
74  switch (level) {
75  case LoggingLevel::TRACE: return "TRACE";
76  case LoggingLevel::DEBUG: return "DEBUG";
77  case LoggingLevel::INFO: return "INFO";
78  case LoggingLevel::WARN: return "WARN";
79  case LoggingLevel::ERROR: return "ERROR";
80  case LoggingLevel::NONE: return "NONE";
81  default: ThrowBalauException(Exception::BugException, "Unhandled LoggingLevel in switch statement.");
82  }
83 }
84 
90 inline std::string toString(LoggingLevel level) {
91  switch (level) {
92  case LoggingLevel::TRACE: return "TRACE";
93  case LoggingLevel::DEBUG: return "DEBUG";
94  case LoggingLevel::INFO: return "INFO";
95  case LoggingLevel::WARN: return "WARN";
96  case LoggingLevel::ERROR: return "ERROR";
97  case LoggingLevel::NONE: return "NONE";
98  default: ThrowBalauException(Exception::BugException, "Unhandled LoggingLevel in switch statement.");
99  }
100 }
101 
102 } // namespace Balau
103 
104 #endif // COM_BORA_SOFTWARE__BALAU_LOGGING__LOGGING_LEVEL
Log to the logger&#39;s trace stream if the logger is trace enabled.
#define ThrowBalauException(ExceptionClass,...)
Throw a Balau style exception, with implicit file and line number, and optional stacktrace.
Definition: BalauException.hpp:45
LoggingLevel
The logging level.
Definition: LoggingLevel.hpp:32
Log to the logger&#39;s error stream if the logger is error enabled.
The root Balau namespace.
Definition: ApplicationConfiguration.hpp:23
Log to the logger&#39;s info stream if the logger is info enabled.
Used to indicate that a logger is not enabled.
Thrown when a bug is encountered (mainly unimplemented switch cases).
Definition: BalauException.hpp:178
Log to the logger&#39;s debug stream if the logger is debug enabled.
Base Balau exception classes.
std::basic_string< char, std::char_traits< char >, AllocatorT > U8String
UTF-8 string type with selectable allocator.
Definition: ToStringA.hpp:41
Balau::U8String< AllocatorT > toString(LoggingLevel level)
Print the logging level as a UTF-8 string.
Definition: LoggingLevel.hpp:73
Log to the logger&#39;s warn stream if the logger is warn enabled.