class NRPLogger

Overview

NRP Logging functions. More…

#include <nrp_logger.h>

class NRPLogger {
public:
    // typedefs

    typedef spdlog::level::level_enum level_t;
    typedef void(&)(const std::string&) spdlog_out_fcn_t;

    // structs

    struct LoggerConfig;

    // construction

    NRPLogger(std::string loggerName = _defaultLoggerName.data());

    NRPLogger(
        std::string loggerName,
        NRPLogger::level_t fileLogLevel,
        NRPLogger::level_t consoleLogLevel,
        std::string logDir,
        bool doSavePars = false
    );

    // methods

    void flush();
    static std::string level_to_string(const NRPLogger::level_t& level);
    static NRPLogger::level_t level_from_string(const std::string& level);
    static void shutdownDefault();
    static spdlog::logger& nrpLogger();

    template <typename FormatString, typename... Args>
    static void debug(
        const FormatString& fmt,
        const Args&... args
    );

    template <typename FormatString, typename... Args>
    static void info(
        const FormatString& fmt,
        const Args&... args
    );

    template <typename FormatString, typename... Args>
    static void warn(
        const FormatString& fmt,
        const Args&... args
    );

    template <typename FormatString, typename... Args>
    static void error(
        const FormatString& fmt,
        const Args&... args
    );

    template <typename FormatString, typename... Args>
    static void critical(
        const FormatString& fmt,
        const Args&... args
    );

    template <typename Message>
    static void debug(const Message& msg);

    template <typename Message>
    static void info(const Message& msg);

    template <typename Message>
    static void warn(const Message& msg);

    template <typename Message>
    static void error(const Message& msg);

    template <typename Message>
    static void critical(const Message& msg);
};

Detailed Documentation

NRP Logging functions.

Typedefs

typedef spdlog::level::level_enum level_t

The wrapper type for log levels.

typedef void(&)(const std::string&) spdlog_out_fcn_t

Logging function type, is used by Exception.

Construction

NRPLogger(std::string loggerName = _defaultLoggerName.data())

The creation of the configurable instance of spdlog, that is set to default logger, with default settings.

Parameters:

loggerName

The name of the logger, that is to be displayed in message and placed as log file prefix

NRPLogger(
    std::string loggerName,
    NRPLogger::level_t fileLogLevel,
    NRPLogger::level_t consoleLogLevel,
    std::string logDir,
    bool doSavePars = false
)

The creation of the configurable instance of spdlog, that is set to default logger.

If the launcher is set true, then the constructor tries to save the logger settings to the shared memory object. Otherwise, the constructor tries to load this settings from the shared memory object. In case of success, these settings are applied to the logger to be created, otherwise the provided settings are used.

Parameters:

loggerName

The name of the logger, that is to be displayed in message and placed as log file prefix

logDir

The location for the log files

fileLogLevel

The minimum log level to be put to the log files

consoleLogLevel

The minimum log level to be printed in console

doSavePars

Save logger parameters to shared memory or not (load them instaed)

Methods

void flush()

Flush default logger.

static std::string level_to_string(const NRPLogger::level_t& level)

Wrapper function for converting enumed log level into string.

Parameters:

level

The numbered representation of the log level

static NRPLogger::level_t level_from_string(const std::string& level)

Wrapper function for getting enumed log level from string. Non-valid string is converted to enum::off.

Parameters:

level

The string representation of the log level

static void shutdownDefault()

Shutdown default logger.

static spdlog::logger& nrpLogger()

Get default NRPLogger.

template <typename FormatString, typename... Args>
static void debug(
    const FormatString& fmt,
    const Args&... args
)

NRP logging function with message formatting for debug level.

Parameters:

fmt

Message format string in fmt library style https://fmt.dev/latest/index.html

args

Arguments for substitution into format string #fmt

template <typename FormatString, typename... Args>
static void info(
    const FormatString& fmt,
    const Args&... args
)

NRP logging function with message formatting for info level.

Parameters:

fmt

Message format string in fmt library style https://fmt.dev/latest/index.html

args

Arguments for substitution into format string #fmt

template <typename FormatString, typename... Args>
static void warn(
    const FormatString& fmt,
    const Args&... args
)

NRP logging function with message formatting for warning level.

Parameters:

fmt

Message format string in fmt library style https://fmt.dev/latest/index.html

args

Arguments for substitution into format string #fmt

template <typename FormatString, typename... Args>
static void error(
    const FormatString& fmt,
    const Args&... args
)

NRP logging function with message formatting for error level.

Parameters:

fmt

Message format string in fmt library style https://fmt.dev/latest/index.html

args

Arguments for substitution into format string #fmt

template <typename FormatString, typename... Args>
static void critical(
    const FormatString& fmt,
    const Args&... args
)

NRP logging function with message formatting for critical error level.

Parameters:

fmt

Message format string in fmt library style https://fmt.dev/latest/index.html

args

Arguments for substitution into format string #fmt

template <typename Message>
static void debug(const Message& msg)

NRP logging function for debug level.

Parameters:

msg

The message to be logged

template <typename Message>
static void info(const Message& msg)

NRP logging function for info level.

Parameters:

msg

The message to be logged

template <typename Message>
static void warn(const Message& msg)

NRP logging function for warning level.

Parameters:

msg

The message to be logged

template <typename Message>
static void error(const Message& msg)

NRP logging function for error level.

Parameters:

msg

The message to be logged

template <typename Message>
static void critical(const Message& msg)

NRP logging function for critical error level.

Parameters:

msg

The message to be logged