Logging front-end and wrappers#
-
class logstream#
Class to manage the debug logging stream.
Public Functions
-
void requestConsole(bool ignoreErrors)#
Helper force a console on platforms where it might optional, when we need to show a console. This basically means Windows at the moment - on other platforms it’s a no-op
-
void setLogLevels(sgDebugClass c, sgDebugPriority p, const std::string &tag = "console")#
Set the log class and priority level.
- Parameters:
c – debug class
p – priority
tag – optional tag to identify the target of the log level change, for example “console” or “file”
-
std::string getLogClassesAsString() const#
Get the Log Classes as a string, in the format which could be passed tp parseLogClasses.
-
void setDeveloperMode(bool devMode)#
set developer mode on/off. In developer mode, SG_DEV_WARN messages are treated as warnings. In normal (non-developer) mode they are treated as SG_DEBUG.
-
bool inDeveloperMode() const#
check if developer mode is set or not
-
void setFileLine(bool fileLine)#
set output of file:line mode on/off. If on, all log messages are prefixed by the file:line of the caller of SG_LOG().
-
void log(sgDebugClass c, sgDebugPriority p, const char *fileName, int line, const char *function, const std::string &msg)#
the core logging method
-
void hexdump(sgDebugClass c, sgDebugPriority p, const char *fileName, int line, const char *function, const void *mem, unsigned int len, unsigned int columns = 16)#
output formatted hex dump of memory block
-
void popup(const std::string &msg)#
support for the SG_POPUP logging class set the content of the popup message
-
std::string get_popup()#
retrieve the contents of the popup message and clear it’s internal content. The return value may be an empty string.
-
bool has_popup()#
return true if a new popup message is available. false otherwise.
-
void addCallback(simgear::LogCallback *cb, bool replayRetained = true)#
register a logging callback. Note callbacks are run in a dedicated thread, so callbacks which pass data to other threads must use appropriate locking.
-
void setMaxRetainedEntries(size_t max)#
Keep the most recent entries (up to @max of them, oldest dropped first), and submit them to callbacks which are added later. This allows simplified logging configuration, but still including early startup information in all logs. Zero (the default) keeps nothing. Reducing the limit discards the oldest entries immediately.
Only entries which are generated at all are kept, so what gets retained depends on the levels of the registered callbacks.
-
void visitRetainedEntries(const std::function<void(const simgear::RetainedLogEntry&)> &visitor) const#
Call @visitor with each retained entry, oldest first. The log thread is held up while this runs, so keep the visitor quick and do not log from it.
-
void setTestingMode(bool testMode)#
Set up the logstream for running in test mode. For example the callbacks will be unregistered and the behaviour of the would_log() function sanitized.
Public Static Functions
-
static void disableStderrLogging()#
prevent logging to stderr, when we are outputting information on stdout for an early exit (eg version info or JSON report)
-
class LogStreamPrivate : public SGThread#
Public Functions
-
inline virtual void run() override#
All threads execute by deriving the run() method of SGThread. If this function terminates then the thread also terminates.
-
inline void recomputeCombinedLevels()#
rebuild _combinedLogLevels from the console levels and every callback. Must be called with the log thread paused.
Public Members
-
CallbackVec m_consoleCallbacks#
subset of callbacks which correspond to stdout / console, and hence should dynamically reflect console logging settings
-
inline virtual void run() override#
-
void requestConsole(bool ignoreErrors)#
Logging front-end macros#
-
SG_LOG(C, P, M)#
Log a message.
- Parameters:
C – debug class
P – priority
M – message
-
SG_BULK_LOG(C, M)#
LogLevels#
-
struct LogLevels#
Stores a set of log levels per each logging class, including the SG_ALL class.
Internally uses an array, so pretty efficient to access and update.
Public Functions
-
std::string to_string() const#
create a standard string representation of the log levels, in the format which could be parsed by parseLogSpecFromString
-
sgDebugPriority get(sgDebugClass c) const#
get the debug priority for a level, falling back to SG_ALL if the specific class is not set
-
std::string to_string() const#