-
Notifications
You must be signed in to change notification settings - Fork 36
/
Logger.cpp
50 lines (39 loc) · 1.42 KB
/
Logger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* @file Logger.cpp
* @authors Giulio Romualdi
* @copyright 2021 Istituto Italiano di Tecnologia (IIT). This software may be modified and
* distributed under the terms of the GNU Lesser General Public License v2.1 or any later version.
*/
#include <spdlog/sinks/stdout_color_sinks.h>
#include <BipedalLocomotion/TextLogging/Logger.h>
namespace BipedalLocomotion
{
std::shared_ptr<TextLogging::Logger> loggerCreation()
{
auto logger = spdlog::get("blf");
// if the logger called blf already exist. If it does not exist it is created.
if (logger == nullptr)
{
// spdlog already handle the logger as singleton create the logger called blf
auto console = spdlog::stdout_color_mt("blf");
// get the logger
logger = spdlog::get("blf");
// if the project is compiled in debug the level of spdlog is set in debug
#ifdef NDEBUG
logger->set_level(spdlog::level::info);
#else
logger->set_level(spdlog::level::debug);
#endif // NDEBUG
// set the custom pattern
logger->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [thread: %t] [%n] %^[%l]%$ %v");
}
return logger;
}
TextLogging::Logger* const log()
{
// Since the oobject is static the memory is not deallocated
static std::shared_ptr<TextLogging::Logger> logger(loggerCreation());
// the logger exist because loggerCreation is called.
return logger.get();
}
} // namespace BipedalLocomotion