23#include "utils/synchronised.hpp"
34# define VALIST __gnuc_va_list
36# define VALIST va_list
39#if defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 1800
40# define va_copy(dest, src) dest = src
83 static void writeLine(
const char *line,
int level);
85 static void printMessage(
int level,
const char *component,
86 const char *format, VALIST va_list);
94#define LOG(NAME, LEVEL) \
95 static void NAME(const char *component, const char *format, ...) \
97 if(LEVEL < m_min_log_level) return; \
99 va_start(args, format); \
100 printMessage(LEVEL, component, format, args); \
103 if (LEVEL == LL_FATAL) \
109 LOG(verbose, LL_VERBOSE);
110 LOG(debug, LL_DEBUG);
113 LOG(error, LL_ERROR);
114 LOG(fatal, LL_FATAL);
120 static void toggleConsoleLog(
bool val);
130 if(n<0 || n>LL_FATAL)
132 warn(
"Log",
"Log level %d not in range [%d-%d] - ignored.\n",
133 n, LL_VERBOSE, LL_FATAL);
154 static void setPrefix(
const char* prefix);
static void setPrefix(const char *prefix)
Sets a prefix to be printed before each line.
Definition: log.cpp:52
static void openOutputFiles(const std::string &logout)
This function opens the files that will contain the output.
Definition: log.cpp:316
static bool m_no_colors
If set this will disable coloring of log messages.
Definition: log.hpp:61
static void closeOutputFiles()
Function to close output files.
Definition: log.cpp:333
static LogLevel getLogLevel()
Returns the log level.
Definition: log.hpp:143
static FILE * m_file_stdout
The file where stdout output will be written.
Definition: log.hpp:67
static size_t m_buffer_size
<0 if no buffered logging is to be used, otherwise this is the maximum number of lines the buffer sho...
Definition: log.hpp:79
static bool m_console_log
If false that logging will only be saved to a file.
Definition: log.hpp:64
LogLevel
The various log levels used in STK.
Definition: log.hpp:47
static void flushBuffers()
Flushes all stored log messages to the various output devices (thread safe).
Definition: log.cpp:299
static void disableColor()
Disable coloring of log messages.
Definition: log.hpp:146
static void setTerminalColor(LogLevel level)
Selects background/foreground colors for the message depending on log level.
Definition: log.cpp:67
static void printMessage(int level, const char *component, const char *format, VALIST va_list)
This actually creates a log message.
Definition: log.cpp:156
static void resetTerminalColor()
Resets the terminal color to the default, and adds a new line (if a new line is added as part of the ...
Definition: log.cpp:132
static LogLevel m_min_log_level
Which message level to print.
Definition: log.hpp:58
static void setBufferSize(size_t n)
Sets the number of lines to buffer.
Definition: log.hpp:125
static void writeLine(const char *line, int level)
Writes the specified line to the various output devices, e.g.
Definition: log.cpp:238
static void setLogLevel(int n)
Defines the minimum log level to be displayed.
Definition: log.hpp:128
A variable that is automatically synchronised using pthreads mutex.
Definition: synchronised.hpp:28
An optional buffer for lines to be output.
Definition: log.hpp:71