Logging.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <mutex>
4 #include <vector>
5 #include <unordered_map>
6 #include <string>
7 #include <cstdint>
8 #include <thread>
9 
10 // libraries
11 #include <spdlog/spdlog.h>
12 #include <spdlog/sinks/stdout_color_sinks.h>
13 
14 // shared
16 
17 // project
21 #include <depthai/utility/Path.hpp>
22 #include "Environment.hpp"
23 
24 namespace dai {
25 
26 class Logging {
27  // private constructor
28  Logging();
29  ~Logging() {}
30 
31 public:
32  static Logging& getInstance() {
33  static Logging logging;
34  return logging;
35  }
36  Logging(Logging const&) = delete;
37  void operator=(Logging const&) = delete;
38 
39  // Public API
40  spdlog::logger logger;
41  spdlog::level::level_enum parseLevel(std::string lvl);
42 };
43 
44 
45 namespace logger
46 {
47 
48 inline spdlog::level::level_enum get_level()
49 {
50  return Logging::getInstance().logger.level();
51 }
52 
53 template<typename FormatString, typename... Args>
54 inline void log(spdlog::source_loc source, spdlog::level::level_enum lvl, const FormatString &fmt, Args&&...args)
55 {
56  Logging::getInstance().logger.log(source, lvl, fmt, std::forward<Args>(args)...);
57 }
58 
59 template<typename FormatString, typename... Args>
60 inline void log(spdlog::level::level_enum lvl, const FormatString &fmt, Args&&...args)
61 {
62  Logging::getInstance().logger.log(spdlog::source_loc{}, lvl, fmt, std::forward<Args>(args)...);
63 }
64 
65 template<typename FormatString, typename... Args>
66 inline void trace(const FormatString &fmt, Args&&...args)
67 {
68  Logging::getInstance().logger.trace(fmt, std::forward<Args>(args)...);
69 }
70 
71 template<typename FormatString, typename... Args>
72 inline void debug(const FormatString &fmt, Args&&...args)
73 {
74  Logging::getInstance().logger.debug(fmt, std::forward<Args>(args)...);
75 }
76 
77 template<typename FormatString, typename... Args>
78 inline void info(const FormatString &fmt, Args&&...args)
79 {
80  Logging::getInstance().logger.info(fmt, std::forward<Args>(args)...);
81 }
82 
83 template<typename FormatString, typename... Args>
84 inline void warn(const FormatString &fmt, Args&&...args)
85 {
86  Logging::getInstance().logger.warn(fmt, std::forward<Args>(args)...);
87 }
88 
89 template<typename FormatString, typename... Args>
90 inline void error(const FormatString &fmt, Args&&...args)
91 {
92  Logging::getInstance().logger.error(fmt, std::forward<Args>(args)...);
93 }
94 
95 template<typename FormatString, typename... Args>
96 inline void critical(const FormatString &fmt, Args&&...args)
97 {
98  Logging::getInstance().logger.critical(fmt, std::forward<Args>(args)...);
99 }
100 
101 template<typename T>
102 inline void log(spdlog::source_loc source, spdlog::level::level_enum lvl, const T &msg)
103 {
104  Logging::getInstance().logger.log(source, lvl, msg);
105 }
106 
107 template<typename T>
108 inline void log(spdlog::level::level_enum lvl, const T &msg)
109 {
110  Logging::getInstance().logger.log(lvl, msg);
111 }
112 
113 template<typename T>
114 inline void trace(const T &msg)
115 {
116  Logging::getInstance().logger.trace(msg);
117 }
118 
119 template<typename T>
120 inline void debug(const T &msg)
121 {
122  Logging::getInstance().logger.debug(msg);
123 }
124 
125 template<typename T>
126 inline void info(const T &msg)
127 {
128  Logging::getInstance().logger.info(msg);
129 }
130 
131 template<typename T>
132 inline void warn(const T &msg)
133 {
134  Logging::getInstance().logger.warn(msg);
135 }
136 
137 template<typename T>
138 inline void error(const T &msg)
139 {
140  Logging::getInstance().logger.error(msg);
141 }
142 
143 template<typename T>
144 inline void critical(const T &msg)
145 {
146  Logging::getInstance().logger.critical(msg);
147 }
148 
149 } // namespace logger
150 
151 
152 } // namespace dai
Environment.hpp
dai::logger::get_level
spdlog::level::level_enum get_level()
Definition: Logging.hpp:48
dai::logger::critical
void critical(const FormatString &fmt, Args &&...args)
Definition: Logging.hpp:96
dai::logger::info
void info(const FormatString &fmt, Args &&...args)
Definition: Logging.hpp:78
dai::Logging::~Logging
~Logging()
Definition: Logging.hpp:29
dai::Logging::Logging
Logging()
Definition: Logging.cpp:5
dai::logger::debug
void debug(const FormatString &fmt, Args &&...args)
Definition: Logging.hpp:72
dai::logger::warn
void warn(const FormatString &fmt, Args &&...args)
Definition: Logging.hpp:84
dai::logger::log
void log(spdlog::source_loc source, spdlog::level::level_enum lvl, const FormatString &fmt, Args &&...args)
Definition: Logging.hpp:54
Device.hpp
DeviceBootloader.hpp
dai::logger::error
void error(const FormatString &fmt, Args &&...args)
Definition: Logging.hpp:90
dai::Logging
Definition: Logging.hpp:26
dai::Logging::operator=
void operator=(Logging const &)=delete
Path.hpp
OpenVINO.hpp
fmt
dai::logger::trace
void trace(const FormatString &fmt, Args &&...args)
Definition: Logging.hpp:66
dai::Logging::getInstance
static Logging & getInstance()
Definition: Logging.hpp:32
dai::Logging::logger
spdlog::logger logger
Definition: Logging.hpp:40
LogConstants.hpp
dai
Definition: CameraExposureOffset.hpp:6
dai::Logging::parseLevel
spdlog::level::level_enum parseLevel(std::string lvl)
Definition: Logging.cpp:31


depthai
Author(s): Martin Peterlin
autogenerated on Sat Mar 22 2025 02:58:19