 |
Fledge
An open source edge computing platform for industrial users
|
19 #include <condition_variable>
21 #include <sys/socket.h>
22 #include <arpa/inet.h>
23 #define PRINT_FUNC Logger::getLogger()->info("%s:%d", __FUNCTION__, __LINE__);
53 Logger(
const std::string& application);
56 void debug(
const std::string& msg, ...);
58 void info(
const std::string& msg, ...);
59 void warn(
const std::string& msg, ...);
60 void error(
const std::string& msg, ...);
61 void fatal(
const std::string& msg, ...);
63 std::string& getMinLevel() {
return levelString; }
66 typedef void (*LogInterceptor)(LogLevel,
const std::string&,
void*);
75 std::string *format(
const std::string& msg, va_list ap);
77 std::string levelString;
80 struct InterceptorData {
81 LogInterceptor callback;
85 std::multimap<LogLevel, InterceptorData> m_interceptors;
86 std::mutex m_interceptorMapMutex;
91 LogInterceptor callback;
95 std::queue<LogTask> m_taskQueue;
96 std::mutex m_queueMutex;
97 std::condition_variable m_condition;
98 std::atomic<bool> m_runWorker;
99 std::thread *m_workerThread;
101 void log(
int sysLogLvl,
const char * lvlName, LogLevel appLogLvl,
const std::string& msg, va_list args);
102 void sendToUdpSink(
const std::string& msg);
103 void executeInterceptor(LogLevel level,
const std::string& message);
105 int m_UdpSockFD = -1;
106 struct sockaddr_in m_UdpServerAddr;
107 bool m_SyslogUdpEnabled =
false;
108 std::string m_identifier;
109 std::string m_hostname;
static Logger * getLogger()
Return the singleton instance of the logger class.
Definition: logger.cpp:184
void debug(const std::string &msg,...)
Log a message at the level debug.
Definition: logger.cpp:346
void fatal(const std::string &msg,...)
Log a message at the level fatal.
Definition: logger.cpp:465
void error(const std::string &msg,...)
Log a message at the level error.
Definition: logger.cpp:447
void printLongString(const std::string &, LogLevel=LogLevel::DEBUG)
Log a long string across multiple syslog entries.
Definition: logger.cpp:363
void warn(const std::string &msg,...)
Log a message at the level warn.
Definition: logger.cpp:430
void info(const std::string &msg,...)
Log a message at the level info.
Definition: logger.cpp:413
bool registerInterceptor(LogLevel level, LogInterceptor callback, void *userData)
Register a callback function to be called when a log message is written that matches the specificatio...
Definition: logger.cpp:246
~Logger()
Destructor for the logger class.
Definition: logger.cpp:138
Logger(const std::string &application)
Constructor for the Logger class.
Definition: logger.cpp:48
void setMinLevel(const std::string &level)
Set the minimum level of logging to write to syslog.
Definition: logger.cpp:204
Fledge Logger class used to log to syslog.
Definition: logger.h:42
bool unregisterInterceptor(LogLevel level, LogInterceptor callback)
Remove the registration of a previously registered callback.
Definition: logger.cpp:274