Logging
Host Bootloader Framework

Logging support. More...

Collaboration diagram for Logging:

## Classes

class | Logger
| Base logger class. More...
class | Log
| Wraps a set of static functions for easy global logging access. More...
class | StdoutLogger
| Simple logger that writes to stdout. More...
class | FileLogger
| Simple logger that writes to a file. More...

## Usage Information

Logging support.

## Class Documentation

class Logger

Base logger class.

There are two types of logging levels that are used by this class. First there is the filter level. Any log message that is assigned a level higher than the current filter level is discarded. Secondly there is the current output level. Log messages that do not have their own level use the current output level to determine if they should be shown or not.

The two methods setFilterLevel() and setOutputLevel() set the filter and default output logging levels, respectively. There are corresponding getter methods as well. Both the filter and output levels are initialized to INFO during object construction.

Most use of the logger classes is expected to be through the Log class. It provides static logging methods that call through to a global singleton logger instance. There is also a Log::SetOutputLevel utility class that makes it extremely easiy to temporarily change the default output logging level.

Of all the overloaded log() methods in this class, none of them are really expected to be reimplemented by subclasses. Instead, there is the single protected _log() method that takes a simple string pointer. The other log methods all wind up calling _log(), so it provides a single point to override. In fact, _log() is pure virtual, so subclasses must implement it.

See also
  Log

There are two types of logging levels that are used by this class. First there is the filter level. Any log message that is assigned a level higher than the current filter level is discarded. Secondly there is the current output level. Log messages that do not have their own level use the current output level to determine if they should be shown or not.

The two methods setFilterLevel() and setOutputLevel() set the filter and default output logging levels, respectively. There are corresponding getter methods as well. Both the filter and output levels are initialized to kInfo during object construction.

Most use of the logger classes is expected to be through the Log class. It provides static logging methods that call through to a global singleton logger instance. There is also a Log::SetOutputLevel utility class that makes it extremely easiy to temporarily change the default output logging level.

Of all the overloaded log() methods in this class, none of them are really expected to be reimplemented by subclasses. Instead, there is the single protected _log() method that takes a simple string pointer. The other log methods all wind up calling _log(), so it provides a single point to override. In fact, _log() is pure virtual, so subclasses must implement it.

See also
  Log

Inheritance diagram for Logger:
[legend]

### Public Types

enum | log_level_t { URGENT = 0, ERROR, WARNING, INFO, INFO2, DEBUG, DEBUG2, kUrgent = 0, kJson, kError, kWarning, kInfo, kInfo2, kDebug, kDebug2, kInfo1 = kInfo, kDebug1 = kDebug }
| Logging levels. More...
enum | log_level_t { URGENT = 0, ERROR, WARNING, INFO, INFO2, DEBUG, DEBUG2, kUrgent = 0, kJson, kError, kWarning, kInfo, kInfo2, kDebug, kDebug2, kInfo1 = kInfo, kDebug1 = kDebug }
| Logging levels. More...

### Public Member Functions

| Logger ()
| Default constructor.
virtual | ~Logger ()
| Destructor.
| Logger ()
| Default constructor.
virtual | ~Logger ()
| Destructor.
Logging levels
void | setFilterLevel (log_level_t level)
| Changes the logging level to level.
log_level_t | getFilterLevel () const
| Returns the current logging filter level.
void | setOutputLevel (log_level_t level)
| Changes the logging output level to level.
log_level_t | getOutputLevel () const
| Returns the current logging output level.
void | setFilterLevel (log_level_t level)
| Changes the logging level to level.
log_level_t | getFilterLevel () const
| Returns the current logging filter level.
void | setOutputLevel (log_level_t level)
| Changes the logging output level to level.
log_level_t | getOutputLevel () const
| Returns the current logging output level.
Logging
virtual void | log (const char *fmt,...)
| Log with format.
virtual void | log (const std::string &msg)
| Log a string object.
virtual void | log (log_level_t level, const char *fmt,...)
| Log with format at a specific output level.
virtual void | log (log_level_t level, const std::string &msg)
| Log a string output at a specific output level.
virtual void | log (const char *fmt, va_list args)
| Log with format using an argument list.
virtual void | log (log_level_t level, const char *fmt, va_list args)
| Log with format using an argument with a specific output level. More...
virtual void | log (const char *fmt,...)
| Log with format.
virtual void | log (const std::string &msg)
| Log a string object.
virtual void | log (log_level_t level, const char *fmt,...)
| Log with format at a specific output level.
virtual void | log (log_level_t level, const std::string &msg)
| Log a string output at a specific output level.
virtual void | log (const char *fmt, va_list args)
| Log with format using an argument list.
virtual void | log (log_level_t level, const char *fmt, va_list args)
| Log with format using an argument with a specific output level.

### Protected Member Functions

virtual void | _log (const char *msg)=0
| The base pure virtual logging function implemented by subclasses.
virtual void | _log (const char *msg)=0
| The base pure virtual logging function implemented by subclasses.

### Protected Attributes

log_level_t | m_filter
| The current logging filter level.
log_level_t | m_level
| The current log output level.

#### Member Enumeration Documentation

enum Logger::log_level_t

Logging levels.

Enumerator
URGENT | The lowest level, for messages that must always be logged.
ERROR | For fatal error messages.
WARNING | For non-fatal warning messages.
INFO | The normal log level, for status messages.
INFO2 | For verbose status messages.
DEBUG | For internal reporting.
DEBUG2 | Highest log level; verbose debug logging.
kUrgent | The lowest level, for messages that must always be logged.
kJson | For machine language output only.
kError | For fatal error messages.
kWarning | For non-fatal warning messages.
kInfo | The normal log level, for status messages.
kInfo2 | For verbose status messages.
kDebug | For internal reporting.
kDebug2 | Highest log level; verbose debug logging.
kInfo1 | Alias for kInfo.
kDebug1 | Alias for kDebug.

enum Logger::log_level_t

Logging levels.

Enumerator
URGENT | The lowest level, for messages that must always be logged.
ERROR | For fatal error messages.
WARNING | For non-fatal warning messages.
INFO | The normal log level, for status messages.
INFO2 | For verbose status messages.
DEBUG | For internal reporting.
DEBUG2 | Highest log level; verbose debug logging.
kUrgent | The lowest level, for messages that must always be logged.
kJson | For machine language output only.
kError | For fatal error messages.
kWarning | For non-fatal warning messages.
kInfo | The normal log level, for status messages.
kInfo2 | For verbose status messages.
kDebug | For internal reporting.
kDebug2 | Highest log level; verbose debug logging.
kInfo1 | Alias for kInfo.
kDebug1 | Alias for kDebug.

#### Member Function Documentation

void Logger::log | ( | log_level_t | level,
|  | const char * | fmt,
|  | va_list | args
| ) |  |

virtual

Log with format using an argument with a specific output level.

Allocates a temporary 1KB buffer which is used to hold the formatted string.

class Log

Wraps a set of static functions for easy global logging access.

This class has a set of static methods that make it easy to access a global logger instance without having to worry about extern symbols. It does this by keeping a static member variable pointing at the singleton logger instance, which is set with the setLogger() static method.

There is also an inner utility class called SetOutputLevel that uses C++ scoping rules to temporarily change the output logging level. When the SetOutputLevel instance falls out of scope the output level is restored to the previous value.

Collaboration diagram for Log:
[legend]

### Static Public Member Functions

Singleton logger access
static Logger * | getLogger ()
| Returns the current global logger singleton.
static void | setLogger (Logger *logger)
| Sets the global logger singleton instance.
static Logger * | getLogger ()
| Returns the current global logger singleton.
static void | setLogger (Logger *logger)
| Sets the global logger singleton instance.
Logging
static void | log (const char *fmt,...)
| Log with format.
static void | log (const std::string &msg)
| Log a string object.
static void | log (Logger::log_level_t level, const char *fmt,...)
| Log with format at a specific output level.
static void | log (Logger::log_level_t level, const std::string &msg)
| Log a string output at a specific output level.
static void | log (const char *fmt,...)
| Log with format.
static void | log (const std::string &msg)
| Log a string object.
static void | log (Logger::log_level_t level, const char *fmt,...)
| Log with format at a specific output level.
static void | log (Logger::log_level_t level, const std::string &msg)
| Log a string output at a specific output level.
Logging level helpers
These static methods log a message with an implicit log level.
static void | urgent (const char *fmt,...)
| Log a message with Logger::kUrgent level.
static void | json (const char *fmt,...)
| Log a message with Logger::kJson level.
static void | error (const char *fmt,...)
| Log a message with Logger::kError level.
static void | warning (const char *fmt,...)
| Log a message with Logger::kWarning level.
static void | info (const char *fmt,...)
| Log a message with Logger::kInfo level.
static void | info2 (const char *fmt,...)
| Log a message with Logger::kInfo2 level.
static void | debug (const char *fmt,...)
| Log a message with Logger::kDebug level.
static void | debug2 (const char *fmt,...)
| Log a message with Logger::kDebug2 level.

### Static Protected Attributes

static Logger * | s_logger = NULL
| The single global logger instance.

class StdoutLogger

Simple logger that writes to stdout.

Inheritance diagram for StdoutLogger:
[legend]
Collaboration diagram for StdoutLogger:
[legend]

### Protected Member Functions

virtual void | _log (const char *msg)
| Logs the message to stdout.
virtual void | _log (const char *msg)
| Logs the message to stdout.

## Additional Inherited Members

Public Types inherited from Logger
enum | log_level_t { URGENT = 0, ERROR, WARNING, INFO, INFO2, DEBUG, DEBUG2, kUrgent = 0, kJson, kError, kWarning, kInfo, kInfo2, kDebug, kDebug2, kInfo1 = kInfo, kDebug1 = kDebug }
| Logging levels. More...
enum | log_level_t { URGENT = 0, ERROR, WARNING, INFO, INFO2, DEBUG, DEBUG2, kUrgent = 0, kJson, kError, kWarning, kInfo, kInfo2, kDebug, kDebug2, kInfo1 = kInfo, kDebug1 = kDebug }
| Logging levels. More...
Public Member Functions inherited from Logger
| Logger ()
| Default constructor.
virtual | ~Logger ()
| Destructor.
| Logger ()
| Default constructor.
virtual | ~Logger ()
| Destructor.
void | setFilterLevel (log_level_t level)
| Changes the logging level to level.
log_level_t | getFilterLevel () const
| Returns the current logging filter level.
void | setOutputLevel (log_level_t level)
| Changes the logging output level to level.
log_level_t | getOutputLevel () const
| Returns the current logging output level.
void | setFilterLevel (log_level_t level)
| Changes the logging level to level.
log_level_t | getFilterLevel () const
| Returns the current logging filter level.
void | setOutputLevel (log_level_t level)
| Changes the logging output level to level.
log_level_t | getOutputLevel () const
| Returns the current logging output level.
virtual void | log (const char *fmt,...)
| Log with format.
virtual void | log (const std::string &msg)
| Log a string object.
virtual void | log (log_level_t level, const char *fmt,...)
| Log with format at a specific output level.
virtual void | log (log_level_t level, const std::string &msg)
| Log a string output at a specific output level.
virtual void | log (const char *fmt, va_list args)
| Log with format using an argument list.
virtual void | log (log_level_t level, const char *fmt, va_list args)
| Log with format using an argument with a specific output level. More...
virtual void | log (const char *fmt,...)
| Log with format.
virtual void | log (const std::string &msg)
| Log a string object.
virtual void | log (log_level_t level, const char *fmt,...)
| Log with format at a specific output level.
virtual void | log (log_level_t level, const std::string &msg)
| Log a string output at a specific output level.
virtual void | log (const char *fmt, va_list args)
| Log with format using an argument list.
virtual void | log (log_level_t level, const char *fmt, va_list args)
| Log with format using an argument with a specific output level.
Protected Attributes inherited from Logger
log_level_t | m_filter
| The current logging filter level.
log_level_t | m_level
| The current log output level.

class FileLogger

Simple logger that writes to a file.

Inheritance diagram for FileLogger:
[legend]
Collaboration diagram for FileLogger:
[legend]

### Public Member Functions

| FileLogger (const char *file_path)
Public Member Functions inherited from Logger
| Logger ()
| Default constructor.
virtual | ~Logger ()
| Destructor.
| Logger ()
| Default constructor.
virtual | ~Logger ()
| Destructor.
void | setFilterLevel (log_level_t level)
| Changes the logging level to level.
log_level_t | getFilterLevel () const
| Returns the current logging filter level.
void | setOutputLevel (log_level_t level)
| Changes the logging output level to level.
log_level_t | getOutputLevel () const
| Returns the current logging output level.
void | setFilterLevel (log_level_t level)
| Changes the logging level to level.
log_level_t | getFilterLevel () const
| Returns the current logging filter level.
void | setOutputLevel (log_level_t level)
| Changes the logging output level to level.
log_level_t | getOutputLevel () const
| Returns the current logging output level.
virtual void | log (const char *fmt,...)
| Log with format.
virtual void | log (const std::string &msg)
| Log a string object.
virtual void | log (log_level_t level, const char *fmt,...)
| Log with format at a specific output level.
virtual void | log (log_level_t level, const std::string &msg)
| Log a string output at a specific output level.
virtual void | log (const char *fmt, va_list args)
| Log with format using an argument list.
virtual void | log (log_level_t level, const char *fmt, va_list args)
| Log with format using an argument with a specific output level. More...
virtual void | log (const char *fmt,...)
| Log with format.
virtual void | log (const std::string &msg)
| Log a string object.
virtual void | log (log_level_t level, const char *fmt,...)
| Log with format at a specific output level.
virtual void | log (log_level_t level, const std::string &msg)
| Log a string output at a specific output level.
virtual void | log (const char *fmt, va_list args)
| Log with format using an argument list.
virtual void | log (log_level_t level, const char *fmt, va_list args)
| Log with format using an argument with a specific output level.

### Protected Member Functions

virtual void | _log (const char *msg)
| Logs the message to the file.

### Protected Attributes

const std::string | m_file_path
| The name of the file, including the path, to log to.
std::ofstream | m_logFile
| The name of the file, including the path, to log to.
Protected Attributes inherited from Logger
log_level_t | m_filter
| The current logging filter level.
log_level_t | m_level
| The current log output level.

## Additional Inherited Members

Public Types inherited from Logger
enum | log_level_t { URGENT = 0, ERROR, WARNING, INFO, INFO2, DEBUG, DEBUG2, kUrgent = 0, kJson, kError, kWarning, kInfo, kInfo2, kDebug, kDebug2, kInfo1 = kInfo, kDebug1 = kDebug }
| Logging levels. More...
enum | log_level_t { URGENT = 0, ERROR, WARNING, INFO, INFO2, DEBUG, DEBUG2, kUrgent = 0, kJson, kError, kWarning, kInfo, kInfo2, kDebug, kDebug2, kInfo1 = kInfo, kDebug1 = kDebug }
| Logging levels. More...