OpenCPN Partial API docs
Loading...
Searching...
No Matches
logger.h File Reference

Enhanced logging interface on top of wx/log.h. More...

#include <chrono>
#include <fstream>
#include <ostream>
#include <sstream>
#include <string>
#include <wx/log.h>

Go to the source code of this file.

Classes

class  OcpnLog
 Customized logger class appending to a file providing: More...
 
class  Logger
 Transient logger class, instantiated/used by the LOG macros. More...
 
class  CountedLogFilter
 Filter logging every nth message. More...
 
class  TimedLogFilter
 Filter logging repeated message with specified interval. More...
 

Macros

#define DO_LOG_MESSAGE(level, fmt, ...)
 
#define _LOG(level)
 
#define TRACE_LOG   _LOG(wxLOG_Trace)
 
#define DEBUG_LOG   _LOG(wxLOG_Debug)
 
#define INFO_LOG   _LOG(wxLOG_Info)
 
#define MESSAGE_LOG   _LOG(wxLOG_Message)
 
#define WARNING_LOG   _LOG(wxLOG_Warning)
 
#define ERROR_LOG   _LOG(wxLOG_Error)
 
#define LOG_TRACE(fmt, ...)   DO_LOG_MESSAGE(wxLOG_Trace, fmt, ##__VA_ARGS__);
 
#define LOG_DEBUG(fmt, ...)   DO_LOG_MESSAGE(wxLOG_Debug, fmt, ##__VA_ARGS__);
 
#define LOG_INFO(fmt, ...)   DO_LOG_MESSAGE(wxLOG_Info, fmt, ##__VA_ARGS__);
 
#define LOG_MESSAGE(fmt, ...)   DO_LOG_MESSAGE(wxLOG_Message, fmt, ##__VA_ARGS__);
 
#define LOG_WARNING(fmt, ...)   DO_LOG_MESSAGE(wxLOG_Warning, fmt, ##__VA_ARGS__);
 
#define LOG_ERROR(fmt, ...)   DO_LOG_MESSAGE(wxLOG_Error, fmt, ##__VA_ARGS__);
 

Detailed Description

Enhanced logging interface on top of wx/log.h.

The OcpnLog acts as the active wxLog target: it formats and prints log messages, overriding the default setup.

The Logger acts as a frontend to the wxLog logging providing C-style macros used like

LOG_INFO("Broken: %s", why);

Here is also C++ ostream log macros used like

INFO_LOG << "Broken: " << why;

These macros are very fast when logging is disabled for actual level, faster then the original wxLogMessage() and friends. They do not respect wxLog's component levels and trace masks, logging anything with a level <= wxLog::GetLogLevel().

Definition in file logger.h.

Macro Definition Documentation

◆ _LOG

#define _LOG (   level)
Value:
if (level > wxLog::GetLogLevel()) \
; \
else \
Logger().get(level, __FILE__, __LINE__)

Definition at line 62 of file logger.h.

◆ DEBUG_LOG

#define DEBUG_LOG   _LOG(wxLOG_Debug)

Definition at line 69 of file logger.h.

◆ DO_LOG_MESSAGE

#define DO_LOG_MESSAGE (   level,
  fmt,
  ... 
)
Value:
{ \
if (level <= wxLog::GetLogLevel()) { \
Logger::logMessage(level, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
} \
}

Definition at line 55 of file logger.h.

◆ ERROR_LOG

#define ERROR_LOG   _LOG(wxLOG_Error)

Definition at line 73 of file logger.h.

◆ INFO_LOG

#define INFO_LOG   _LOG(wxLOG_Info)

Definition at line 70 of file logger.h.

◆ LOG_DEBUG

#define LOG_DEBUG (   fmt,
  ... 
)    DO_LOG_MESSAGE(wxLOG_Debug, fmt, ##__VA_ARGS__);

Definition at line 76 of file logger.h.

◆ LOG_ERROR

#define LOG_ERROR (   fmt,
  ... 
)    DO_LOG_MESSAGE(wxLOG_Error, fmt, ##__VA_ARGS__);

Definition at line 80 of file logger.h.

◆ LOG_INFO

#define LOG_INFO (   fmt,
  ... 
)    DO_LOG_MESSAGE(wxLOG_Info, fmt, ##__VA_ARGS__);

Definition at line 77 of file logger.h.

◆ LOG_MESSAGE

#define LOG_MESSAGE (   fmt,
  ... 
)    DO_LOG_MESSAGE(wxLOG_Message, fmt, ##__VA_ARGS__);

Definition at line 78 of file logger.h.

◆ LOG_TRACE

#define LOG_TRACE (   fmt,
  ... 
)    DO_LOG_MESSAGE(wxLOG_Trace, fmt, ##__VA_ARGS__);

Definition at line 75 of file logger.h.

◆ LOG_WARNING

#define LOG_WARNING (   fmt,
  ... 
)    DO_LOG_MESSAGE(wxLOG_Warning, fmt, ##__VA_ARGS__);

Definition at line 79 of file logger.h.

◆ MESSAGE_LOG

#define MESSAGE_LOG   _LOG(wxLOG_Message)

Definition at line 71 of file logger.h.

◆ TRACE_LOG

#define TRACE_LOG   _LOG(wxLOG_Trace)

Definition at line 68 of file logger.h.

◆ WARNING_LOG

#define WARNING_LOG   _LOG(wxLOG_Warning)

Definition at line 72 of file logger.h.