Flyby SDK v1.0.2
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include <fstream>
11#include <mutex>
12#include <string>
13
14#include <flyby/message/client.h>
15
16namespace flyby {
21 enum class LogLevel : uint8_t {
22 ERROR = 0,
23 WARNING,
24 INFO,
25 DEBUG,
26 };
27
32 class Logger {
33 public:
39 explicit Logger(const std::string& filepath);
40
46 explicit Logger(std::shared_ptr<Publisher> publisher);
47
54 explicit Logger(std::shared_ptr<Publisher> publisher, const std::string& filepath);
55
56 virtual ~Logger();
57
63 [[maybe_unused]] void set_stdout(bool allow_stdout);
64
70 [[maybe_unused]] void set_log_level(LogLevel level);
71
78 virtual void log(LogLevel level, const std::string& message);
79
87 virtual void log(LogLevel level, const std::string& tag, const std::string& message);
88
94 virtual void d(const std::string& message);
95
102 virtual void d(const std::string& tag, const std::string& message);
103
109 virtual void i(const std::string& message);
110
117 virtual void i(const std::string& tag, const std::string& message);
118
124 virtual void w(const std::string& message);
125
132 virtual void w(const std::string& tag, const std::string& message);
133
139 virtual void e(const std::string& message);
140
147 virtual void e(const std::string& tag, const std::string& message);
148
149 protected:
156
157 private:
158 std::mutex m_mutex;
159
160 bool m_allow_stdout { false };
161
162 LogLevel m_level { LogLevel::INFO };
163
164 std::ofstream m_file_stream;
165 std::shared_ptr<Publisher> m_publisher;
166 };
167} // namespace flyby
virtual void e(const std::string &tag, const std::string &message)
Logs a message at the error log level.
virtual void log(LogLevel level, const std::string &tag, const std::string &message)
Logs a message at a log level.
virtual void log(LogLevel level, const std::string &message)
Logs a message at a log level.
virtual void w(const std::string &tag, const std::string &message)
Logs a message at the warning log level.
void set_log_level(LogLevel level)
Sets the current log level.
virtual void d(const std::string &tag, const std::string &message)
Logs a message at the debug log level.
void set_stdout(bool allow_stdout)
Allow/stop the logger from outputting to stdout.
Logger(const std::string &filepath)
Constructs a logger that writes to a file.
virtual void i(const std::string &message)
Logs a message at the info log level.
Logger(std::shared_ptr< Publisher > publisher, const std::string &filepath)
Constructs a logger that writes to the message bus and to a file.
virtual void d(const std::string &message)
Logs a message at the debug log level.
virtual void e(const std::string &message)
Logs a message at the error log level.
Logger(std::shared_ptr< Publisher > publisher)
Constructs a logger that writes to the message bus.
Logger()
Constructs an empty logger.
virtual void i(const std::string &tag, const std::string &message)
Logs a message at the info log level.
virtual void w(const std::string &message)
Logs a message at the warning log level.
LogLevel
The log level that is displayed with the message in the log.
Definition log.h:21