Logging

Extensible general-purpose logging facilities.


Exception-safety Tags

Tags that signify exception-safeties of logging facilities.

Header file: sneaker/logging/exception_safety_tag.h

type sneaker::logging::exception_safe_tag

Tag that signifies exception-safe logging facilities.

type sneaker::logging::exception_unsafe_tag

Tag that signifies non exception-safe logging facilities.

Thread-safety Tags

Tags that signify thread-safeties of logging facilities.

Header file: sneaker/logging/thread_safety_tag.h

type sneaker::logging::thread_safe_tag

Tag that signifies thread-safe logging facilities.

type sneaker::logging::thread_unsafe_tag

Tag that signifies non thread-safe logging facilities.

Log Levels

Various levels of log severity.

Header file: sneaker/logging/log_level.h

enum class sneaker::logging::LogLevel

Enumerations of various levels of log severity. Values are:

  • LOG_LEVEL_DEBUG
  • LOG_LEVEL_INFO
  • LOG_LEVEL_WARN
  • LOG_LEVEL_ERROR
  • LOG_LEVEL_FATAL

Log Schemes

Mechanisms of logging.

Header file: sneaker/logging/log_scheme.h

class sneaker::logging::log_scheme

Abstraction of a particular mechanism of storing log records.

virtual void write(const char *msg) = 0

Base member of writing a log record. To be defined in subclasses.

virtual ~log_scheme()

Base destructor.

class sneaker::logging::stream_log_scheme

Logging scheme that sends log records to std::ostream.

virtual void write(const char *msg)

Writes the log message to std::ostream.

class sneaker::logging::stdout_log_scheme : public stream_log_scheme

Logging scheme that sends log records to stdout.

stdout_log_scheme()

Constructor.

virtual ~stdout_log_scheme()

Destructor.

class sneaker::logging::stderr_log_scheme : public stream_log_scheme

Logging scheme that sends log records to stderr.

stderr_log_scheme()

Constructor.

virtual ~stderr_log_scheme()

Destructor.

class sneaker::logging::file_log_scheme : public stream_log_scheme

Logging scheme that sends log records to a file.

file_log_scheme(const char* filename);

Constructor that takes a file path.

virtual ~file_log_scheme()

Destructor.

Logger

Class that encapsulates the core logging mechanism. Can be customized with particular exception-safety and thread-safety tags.

Header file: sneaker/logging/logger.h

template<typename thread_safety_tag, typename exception_safety_tag> sneaker::logging::logger

explicit logger(log_scheme *log_scheme)

Constructor.

template<size_t LINE_SIZE=1024> void write(LogLevel log_lvl, const char* format, ...)

Writes a free-format log record message.

Helper Utilities

Utility functions that faciliate logging.

Header file: sneaker/logging/logging.h

LOG(lvl, file, line, format, ...)

Convenience macro that logs a log record message by taking the log level, file and line number of where the log occurs, and the format and arguments that goes into the log message.

LOG_DEBUG(format, ...)

Convenience macro that logs a log record in LOG_LEVEL_DEBUG level.

LOG_INFO(format, ...)

Convenience macro that logs a log record in LOG_LEVEL_INFO level.

LOG_WARN(format, ...)

Convenience macro that logs a log record in LOG_LEVEL_WARN level.

LOG_ERROR(format, ...)

Convenience macro that logs a log record in LOG_LEVEL_ERROR level.

LOG_FATAL(format, ...)

Convenience macro that logs a log record in LOG_LEVEL_FATAL level.

LOG_DETAILED(lvl, file, line, format, ...)

Convenience macro that logs a log record message by taking the log level, file and line number of where the log occurs, and the format and arguments that goes into the log message. Also logs the timestamp of the occurance of log.

LOG_DEBUG_DETAILED(format, ...)

Convenience macro that logs a log record in LOG_LEVEL_DEBUG level.

LOG_INFO_DETAILED(format, ...)

Convenience macro that logs a log record in LOG_LEVEL_INFO level.

LOG_WARN_DETAILED(format, ...)

Convenience macro that logs a log record in LOG_LEVEL_WARN level.

LOG_ERROR_DETAILED(format, ...)

Convenience macro that logs a log record in LOG_LEVEL_ERROR level.

LOG_FATAL_DETAILED(format, ...)

Convenience macro that logs a log record in LOG_LEVEL_FATAL level.