ifm3d
log_level.h
1 // -*- c++ -*-
2 /*
3  * Copyright 2023-present ifm electronic, gmbh
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef IFM3D_COMMON_LOGGING_LOG_LEVEL_H
8 #define IFM3D_COMMON_LOGGING_LOG_LEVEL_H
9 
10 #include <cctype>
11 
12 namespace ifm3d
13 {
14  enum class LogLevel
15  {
16  None = 0,
17  Critical = 1,
18  Error = 2,
19  Warning = 3,
20  Info = 4,
21  Debug = 5,
22  Verbose = 6
23  };
24 
25  inline const char*
26  LogLevelToString(LogLevel severity)
27  {
28  switch (severity)
29  {
30  case LogLevel::Critical:
31  return "CRITICAL";
32  case LogLevel::Error:
33  return "ERROR";
34  case LogLevel::Warning:
35  return "WARN";
36  case LogLevel::Info:
37  return "INFO";
38  case LogLevel::Debug:
39  return "DEBUG";
40  case LogLevel::Verbose:
41  return "VERBOSE";
42  default:
43  return "NONE";
44  }
45  }
46 
47  inline LogLevel
48  LogLevelFromString(const char* str)
49  {
50  switch (std::toupper(str[0]))
51  {
52  case 'C':
53  return LogLevel::Critical;
54  case 'E':
55  return LogLevel::Error;
56  case 'W':
57  return LogLevel::Warning;
58  case 'I':
59  return LogLevel::Info;
60  case 'D':
61  return LogLevel::Debug;
62  case 'V':
63  return LogLevel::Verbose;
64  default:
65  return LogLevel::None;
66  }
67  }
68 }
69 #endif // IFM3D_COMMON_LOGGING_LOG_LEVEL_H