SuperTuxKart
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
Log Class Reference

Classes

struct  LineInfo
 An optional buffer for lines to be output. More...
 

Public Types

enum  LogLevel {
  LL_DEBUG, LL_VERBOSE, LL_INFO, LL_WARN,
  LL_ERROR, LL_FATAL
}
 The various log levels used in STK.
 

Public Member Functions

 LOG (verbose, LL_VERBOSE)
 
 LOG (debug, LL_DEBUG)
 
 LOG (info, LL_INFO)
 
 LOG (warn, LL_WARN)
 
 LOG (error, LL_ERROR)
 
 LOG (fatal, LL_FATAL)
 

Static Public Member Functions

static void openOutputFiles (const std::string &logout)
 This function opens the files that will contain the output. More...
 
static void closeOutputFiles ()
 Function to close output files.
 
static void flushBuffers ()
 Flushes all stored log messages to the various output devices (thread safe).
 
static void toggleConsoleLog (bool val)
 
static void setBufferSize (size_t n)
 Sets the number of lines to buffer. More...
 
static void setLogLevel (int n)
 Defines the minimum log level to be displayed.
 
static LogLevel getLogLevel ()
 Returns the log level. More...
 
static void disableColor ()
 Disable coloring of log messages.
 
static void setPrefix (const char *prefix)
 Sets a prefix to be printed before each line. More...
 

Static Private Member Functions

static void setTerminalColor (LogLevel level)
 Selects background/foreground colors for the message depending on log level. More...
 
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 message, a potential change of background color will also affect the next row).
 
static void writeLine (const char *line, int level)
 Writes the specified line to the various output devices, e.g. More...
 
static void printMessage (int level, const char *component, const char *format, VALIST va_list)
 This actually creates a log message. More...
 

Static Private Attributes

static LogLevel m_min_log_level = Log::LL_VERBOSE
 Which message level to print.
 
static bool m_no_colors = false
 If set this will disable coloring of log messages.
 
static bool m_console_log = true
 If false that logging will only be saved to a file.
 
static FILE * m_file_stdout = NULL
 The file where stdout output will be written.
 
static Synchronised< std::vector< struct LineInfo > > m_line_buffer
 
static size_t m_buffer_size = 1
 <0 if no buffered logging is to be used, otherwise this is the maximum number of lines the buffer should hold.
 

Member Function Documentation

◆ getLogLevel()

static LogLevel Log::getLogLevel ( )
inlinestatic

Returns the log level.

This is useful if some work is necessary to preprate output strings, which might not be used at all (example: replacing the cleartext password in an http request).

◆ openOutputFiles()

void Log::openOutputFiles ( const std::string &  logout)
static

This function opens the files that will contain the output.

Parameters
logout: name of the file that will contain stdout output
logerr: name of the file that will contain stderr output

◆ printMessage()

void Log::printMessage ( int  level,
const char *  component,
const char *  format,
VALIST  args 
)
staticprivate

This actually creates a log message.

If the messages are to be buffered, it will be appended to the output buffer. If the buffer is full, it will be flushed. If the message is not to be buffered, it will be immediately written using writeLine().

Parameters
levelLog level of the message to print.
formatA printf-like format string.
va_listThe values to be printed for the format.

◆ setBufferSize()

static void Log::setBufferSize ( size_t  n)
inlinestatic

Sets the number of lines to buffer.

Setting the buffer size to a a value <=1 means no buffering, lines will be immediately printed.

◆ setPrefix()

void Log::setPrefix ( const char *  prefix)
static

Sets a prefix to be printed before each line.

To disable the prefix, set it to "", max length of prefix is 10, if larger than that the remaining characters are ignored.

◆ setTerminalColor()

void Log::setTerminalColor ( LogLevel  level)
staticprivate

Selects background/foreground colors for the message depending on log level.

It is only called if messages are not redirected to a file.

Parameters
levelThe level for which to set the color.

◆ writeLine()

void Log::writeLine ( const char *  line,
int  level 
)
staticprivate

Writes the specified line to the various output devices, e.g.

terminal, log file etc. If log messages are not redirected to a file, it tries to select a terminal colour.

Parameters
lineThe line to write.
levelMessage level. Only used to select terminal colour.

The documentation for this class was generated from the following files: