LogService

enum class LogLevel

Values:

enumerator Audit
enumerator Error
enumerator Warn
enumerator Info
enumerator Debug
enumerator Trace
enum class SeverityLevel : uint8_t

Values:

enumerator LOG_ERROR

Indicates the bundle or service may not be functional.

Action should be taken to correct this situation.

enumerator LOG_WARNING

Indicates a bundle or service is still functioning but may experience problems in the future because of the warning condition.

enumerator LOG_INFO

May be the result of any change in the bundle or service and does not indicate a problem.

enumerator LOG_DEBUG

Used for problem determination and may be irrelevant to anyone but the bundle developer.

class Logger
#include <cppmicroservices/logservice/Logger.hpp>

Provides methods for bundles to write messages to the log.

Logger interface defines several methods for each of the defined LogLevels.

Remark

This class is thread-safe.

Public Functions

virtual ~Logger() = default
virtual void audit(std::string const &message) = 0

Logs a message at LogLevel.Audit level.

Parameters:

message – The message to log.

virtual void audit(std::string const &format, std::string const &arg) = 0

Logs a message at LogLevel.Audit level.

Parameters:
  • format – The format of the message to log.

  • arg – The argument to format into the message.

virtual void audit(std::string const &format, std::string const &arg1, std::string const &arg2) = 0

Logs a message at LogLevel.Audit level.

Parameters:
  • format – The format of the message to log.

  • arg1 – The first argument to format into the message.

  • arg2 – The second argument to format into the message.

virtual void audit(std::string const &message, const std::exception_ptr ex) = 0

Logs a message at LogLevel.Audit level.

Parameters:
  • message – The message to log.

  • ex – The exception that reflects the condition or nullptr.

virtual void audit(std::string const &message, ServiceReferenceBase const &sr) = 0

Logs a message at LogLevel.Audit level.

Parameters:
  • message – The message to log.

  • sr – The ServiceReferenceBase object of the service that this message is associated with or an invalid object.

virtual void audit(std::string const &message, ServiceReferenceBase const &sr, const std::exception_ptr ex) = 0

Logs a message at LogLevel.Audit level.

Parameters:
  • message – The message to log.

  • sr – The ServiceReferenceBase object of the service that this message is associated with or an invalid object.

  • ex – The exception that reflects the condition or nullptr.

virtual void debug(std::string const &message) = 0

Logs a message at LogLevel.Debug level.

Parameters:

message – The message to log.

virtual void debug(std::string const &format, std::string const &arg) = 0

Logs a message at LogLevel.Debug level.

Parameters:
  • format – The format of the message to log.

  • arg – The argument to format into the message.

virtual void debug(std::string const &format, std::string const &arg1, std::string const &arg2) = 0

Logs a message at LogLevel.Debug level.

Parameters:
  • format – The format of the message to log.

  • arg1 – The first argument to format into the message.

  • arg2 – The second argument to format into the message.

virtual void debug(std::string const &message, const std::exception_ptr ex) = 0

Logs a message at LogLevel.Debug level.

Parameters:
  • message – The message to log.

  • ex – The exception that reflects the condition or nullptr.

virtual void debug(std::string const &message, ServiceReferenceBase const &sr) = 0

Logs a message at LogLevel.Debug level.

Parameters:
  • message – The message to log.

  • sr – The ServiceReferenceBase object of the service that this message is associated with or an invalid object.

virtual void debug(std::string const &message, ServiceReferenceBase const &sr, const std::exception_ptr ex) = 0

Logs a message at LogLevel.Debug level.

Parameters:
  • message – The message to log.

  • sr – The ServiceReferenceBase object of the service that this message is associated with or an invalid object.

  • ex – The exception that reflects the condition or nullptr.

virtual void error(std::string const &message) = 0

Logs a message at LogLevel.Error level.

Parameters:

message – The message to log.

virtual void error(std::string const &format, std::string const &arg) = 0

Logs a message at LogLevel.Error level.

Parameters:
  • format – The format of the message to log.

  • arg – The argument to format into the message.

virtual void error(std::string const &format, std::string const &arg1, std::string const &arg2) = 0

Logs a message at LogLevel.Error level.

Parameters:
  • format – The format of the message to log.

  • arg1 – The first argument to format into the message.

  • arg2 – The second argument to format into the message.

virtual void error(std::string const &message, const std::exception_ptr ex) = 0

Logs a message at LogLevel.Error level.

Parameters:
  • message – The message to log.

  • ex – The exception that reflects the condition or nullptr.

virtual void error(std::string const &message, ServiceReferenceBase const &sr) = 0

Logs a message at LogLevel.Error level.

Parameters:
  • message – The message to log.

  • sr – The ServiceReferenceBase object of the service that this message is associated with or an invalid object.

virtual void error(std::string const &message, ServiceReferenceBase const &sr, const std::exception_ptr ex) = 0

Logs a message at LogLevel.Error level.

Parameters:
  • message – The message to log.

  • sr – The ServiceReferenceBase object of the service that this message is associated with or an invalid object.

  • ex – The exception that reflects the condition or nullptr.

virtual void info(std::string const &message) = 0

Logs a message at LogLevel.Info level.

Parameters:

message – The message to log.

virtual void info(std::string const &format, std::string const &arg) = 0

Logs a message at LogLevel.Info level.

Parameters:
  • format – The format of the message to log.

  • arg – The argument to format into the message.

virtual void info(std::string const &format, std::string const &arg1, std::string const &arg2) = 0

Logs a message at LogLevel.Info level.

Parameters:
  • format – The format of the message to log.

  • arg1 – The first argument to format into the message.

  • arg2 – The second argument to format into the message.

virtual void info(std::string const &message, const std::exception_ptr ex) = 0

Logs a message at LogLevel.Info level.

Parameters:
  • message – The message to log.

  • ex – The exception that reflects the condition or nullptr.

virtual void info(std::string const &message, ServiceReferenceBase const &sr) = 0

Logs a message at LogLevel.Info level.

Parameters:
  • message – The message to log.

  • sr – The ServiceReferenceBase object of the service that this message is associated with or an invalid object.

virtual void info(std::string const &message, ServiceReferenceBase const &sr, const std::exception_ptr ex) = 0

Logs a message at LogLevel.Info level.

Parameters:
  • message – The message to log.

  • sr – The ServiceReferenceBase object of the service that this message is associated with or an invalid object.

  • ex – The exception that reflects the condition or nullptr.

virtual void trace(std::string const &message) = 0

Logs a message at LogLevel.Trace level.

Parameters:

message – The message to log.

virtual void trace(std::string const &format, std::string const &arg) = 0

Logs a message at LogLevel.Trace level.

Parameters:
  • format – The format of the message to log.

  • arg – The argument to format into the message.

virtual void trace(std::string const &format, std::string const &arg1, std::string const &arg2) = 0

Logs a message at LogLevel.Trace level.

Parameters:
  • format – The format of the message to log.

  • arg1 – The first argument to format into the message.

  • arg2 – The second argument to format into the message.

virtual void trace(std::string const &message, const std::exception_ptr ex) = 0

Logs a message at LogLevel.Trace level.

Parameters:
  • message – The message to log.

  • ex – The exception that reflects the condition or nullptr.

virtual void trace(std::string const &message, ServiceReferenceBase const &sr) = 0

Logs a message at LogLevel.Trace level.

Parameters:
  • message – The message to log.

  • sr – The ServiceReferenceBase object of the service that this message is associated with or an invalid object.

virtual void trace(std::string const &message, ServiceReferenceBase const &sr, const std::exception_ptr ex) = 0

Logs a message at LogLevel.Trace level.

Parameters:
  • message – The message to log.

  • sr – The ServiceReferenceBase object of the service that this message is associated with or an invalid object.

  • ex – The exception that reflects the condition or nullptr.

virtual void warn(std::string const &message) = 0

Logs a message at LogLevel.Warn level.

Parameters:

message – The message to log.

virtual void warn(std::string const &format, std::string const &arg) = 0

Logs a message at LogLevel.Warn level.

Parameters:
  • format – The format of the message to log.

  • arg – The argument to format into the message.

virtual void warn(std::string const &format, std::string const &arg1, std::string const &arg2) = 0

Logs a message at LogLevel.Warn level.

Parameters:
  • format – The format of the message to log.

  • arg1 – The first argument to format into the message.

  • arg2 – The second argument to format into the message.

virtual void warn(std::string const &message, const std::exception_ptr ex) = 0

Logs a message at LogLevel.Warn level.

Parameters:
  • message – The message to log.

  • ex – The exception that reflects the condition or nullptr.

virtual void warn(std::string const &message, ServiceReferenceBase const &sr) = 0

Logs a message at LogLevel.Warn level.

Parameters:
  • message – The message to log.

  • sr – The ServiceReferenceBase object of the service that this message is associated with or an invalid object.

virtual void warn(std::string const &message, ServiceReferenceBase const &sr, const std::exception_ptr ex) = 0

Logs a message at LogLevel.Warn level.

Parameters:
  • message – The message to log.

  • sr – The ServiceReferenceBase object of the service that this message is associated with or an invalid object.

  • ex – The exception that reflects the condition or nullptr.

class LoggerFactory
#include <cppmicroservices/logservice/LoggerFactory.hpp>

LoggerFactory is the service interface that allows a bundle to obtain a Logger.

It provides methods to obtain Logger; then a bundle can start logging messages to the Log Service by calling one of the Logger methods.

Remark

This class is thread safe.

Subclassed by cppmicroservices::logservice::LogService

Public Functions

virtual ~LoggerFactory() = default
virtual std::shared_ptr<Logger> getLogger(std::string const &name = ROOT_LOGGER_NAME) const = 0
        Return the Logger named with the specified name.
        @param name The name to use for the logger name.

If the name parameter is equal to ROOT_LOGGER_NAME, then the root logger is returned.

virtual std::shared_ptr<Logger> getLogger(const cppmicroservices::Bundle &bundle, std::string const &name = ROOT_LOGGER_NAME) const = 0

        Return the Logger for the specified bundle, named with the specified name.
If the name parameter is equal to ROOT_LOGGER_NAME, then the root logger is returned.

Parameters:
  • bundle – The bundle associated with the Logger.

  • name – The name to use for the logger name.

Public Static Attributes

static const std::string ROOT_LOGGER_NAME
class LogService : public cppmicroservices::logservice::LoggerFactory
#include <cppmicroservices/logservice/LogService.hpp>

Provides methods for bundles to write messages to the log.

LogService methods are provided to log messages; optionally with a ServiceReference object or an exception. Bundles must log messages in the OSGi environment with a severity level according to the following hierarchy:

  1. LOG_ERROR

  2. LOG_WARNING

  3. LOG_INFO

  4. LOG_DEBUG

Remark

This class is thread safe.

Public Functions

virtual ~LogService() = default
virtual void Log(SeverityLevel level, std::string const &message) = 0

Logs a message.

Parameters:
  • level – The severity of the message. This should be one of the defined log levels but may be any integer that is interpreted in a user defined way.

  • message – Human readable string describing the condition or empty string.

virtual void Log(SeverityLevel level, std::string const &message, const std::exception_ptr ex) = 0

Logs a message.

Parameters:
  • level – The severity of the message. This should be one of the defined log levels but may be any integer that is interpreted in a user defined way.

  • message – Human readable string describing the condition or empty string.

  • ex – The exception that reflects the condition or nullptr.

virtual void Log(ServiceReferenceBase const &sr, SeverityLevel level, std::string const &message) = 0

Logs a message.

Parameters:
  • sr – The ServiceReferenceBase object of the service that this message is associated with or an invalid object.

  • level – The severity of the message. This should be one of the defined log levels but may be any integer that is interpreted in a user defined way.

  • message – Human readable string describing the condition or empty string.

virtual void Log(ServiceReferenceBase const &sr, SeverityLevel level, std::string const &message, const std::exception_ptr ex) = 0

Logs a message with an exception associated and a ServiceReference object.

Parameters:
  • sr – The ServiceReferenceBase object of the service that this message is associated with or an invalid object.

  • level – The severity of the message. This should be one of the defined log levels but may be any integer that is interpreted in a user defined way.

  • message – Human readable string describing the condition or empty string.

  • ex – The exception that reflects the condition or nullptr.