OSVR-Core
LogLevelTranslate.h
Go to the documentation of this file.
1 
11 // Copyright 2016 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_LogLevelTranslate_h_GUID_24C67818_0BC8_41B9_7003_1098631ED86F
26 #define INCLUDED_LogLevelTranslate_h_GUID_24C67818_0BC8_41B9_7003_1098631ED86F
27 
28 // Internal Includes
29 #include <osvr/Util/LogLevel.h>
30 
31 // Library/third-party includes
32 #include <spdlog/common.h>
33 
34 // Standard includes
35 // - none
36 
37 namespace osvr {
38 namespace util {
39  namespace log {
40 
42  inline spdlog::level::level_enum
44  if (level <= OSVR_LOGLEVEL_TRACE) {
45  return spdlog::level::trace;
46  }
47  if (level <= OSVR_LOGLEVEL_DEBUG) {
48  return spdlog::level::debug;
49  }
50  if (level <= OSVR_LOGLEVEL_INFO) {
51  return spdlog::level::info;
52  }
53  if (level <= OSVR_LOGLEVEL_NOTICE) {
54  return spdlog::level::info;
55  }
56  if (level <= OSVR_LOGLEVEL_WARN) {
57  return spdlog::level::warn;
58  }
59  if (level <= OSVR_LOGLEVEL_ERROR) {
60  return spdlog::level::err;
61  }
62  return spdlog::level::critical;
63  }
64 
65  inline spdlog::level::level_enum convertToLevelEnum(LogLevel level) {
66  return convertToLevelEnum(
67  static_cast<OSVR_LogLevel>(static_cast<int>(level)));
68  }
69 
71  inline LogLevel convertFromLevelEnum(spdlog::level::level_enum level) {
72  switch (level) {
73  case spdlog::level::trace:
74  return LogLevel::trace;
75  case spdlog::level::debug:
76  return LogLevel::debug;
77  case spdlog::level::info:
78  return LogLevel::info;
79  case spdlog::level::warn:
80  return LogLevel::warn;
81  case spdlog::level::err:
82  return LogLevel::error;
83  case spdlog::level::critical:
84  return LogLevel::critical;
85  default:
86  return LogLevel::critical;
87  }
88  }
89 
90  } // namespace log
91 } // namespace util
92 } // namespace osvr
93 
94 #endif // INCLUDED_LogLevelTranslate_h_GUID_24C67818_0BC8_41B9_7003_1098631ED86F
Definition: RunLoopManager.h:42
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
spdlog::level::level_enum convertToLevelEnum(OSVR_LogLevel level)
Maps OSVR log levels into spdlog levels.
Definition: LogLevelTranslate.h:43
LogLevel
Log message severity levels.
Definition: LogLevel.h:45
Header.
OSVR_LogLevel
Log message severity levels.
Definition: LogLevelC.h:44
LogLevel convertFromLevelEnum(spdlog::level::level_enum level)
The reverse mapping.
Definition: LogLevelTranslate.h:71