MotionLib  1.0.0
SamBuCa motion library
Environment.cpp
1 /*
2 ** Copyright (C) 2022 CERN
3 **
4 ** This software is provided 'as-is', without any express or implied
5 ** warranty. In no event will the authors be held liable for any damages
6 ** arising from the use of this software.
7 **
8 ** Permission is granted to anyone to use this software for any purpose,
9 ** including commercial applications, and to alter it and redistribute it
10 ** freely, subject to the following restrictions:
11 **
12 ** 1. The origin of this software must not be misrepresented; you must not
13 ** claim that you wrote the original software. If you use this software
14 ** in a product, an acknowledgment in the product documentation would be
15 ** appreciated but is not required.
16 ** 2. Altered source versions must be plainly marked as such, and must not be
17 ** misrepresented as being the original software.
18 ** 3. This notice may not be removed or altered from any source distribution.
19 **
20 ** Created on: 2022-07-14T14:48:00
21 ** Author: Sylvain Fargier <sylvain.fargier@cern.ch>
22 */
23 
24 #include "Environment.hpp"
25 
26 #include <logger/Logger.hpp>
27 #include <oatpp/core/base/Environment.hpp>
28 
29 #include <ccut/Singleton.hxx>
30 
31 template class ccut::Singleton<smc::debug::Environment,
32  ccut::SingletonType::automatic>;
33 
34 class Logger : public oatpp::base::Logger
35 {
36 public:
37  void log(v_uint32 priority,
38  const std::string &tag,
39  const std::string &message)
40  {
41  logger::log(loggerLevel(priority), "http:" + tag) << message;
42  }
43 
44  bool isLogPriorityEnabled(v_uint32 prio)
45  {
46  return loggerLevel(prio) <= logger::Config().getLevel();
47  }
48 
49  inline logger::Level loggerLevel(v_uint32 prio) const
50  {
51  switch (prio)
52  {
53  case PRIORITY_V:
54  case PRIORITY_D: return logger::Level::DEBUG;
55  case PRIORITY_I: return logger::Level::NOTICE;
56  case PRIORITY_W: return logger::Level::WARNING;
57  case PRIORITY_E: return logger::Level::ERROR;
58  default: return logger::Level::INFO;
59  }
60  }
61 };
62 
63 namespace smc {
64 namespace debug {
65 
66 Environment::Environment() : m_logger(new Logger)
67 {
68  oatpp::base::Environment::init();
69  oatpp::base::Environment::setLogger(m_logger);
70  oatpp::base::Environment::printCompilationConfig();
71 }
72 
73 Environment::~Environment()
74 {
75  oatpp::base::Environment::destroy();
76 }
77 
78 } // namespace debug
79 } // namespace smc
main motion-lib namespace
Definition: Client.cpp:30