AOSharedServiceLibrary
Logging Interface

Logging exposes a pointer to a Logger instance, which can log directly itself or provide categories to log to.

#include "include/aossl/logging/factory_logging.h"
#include "include/aossl/logging/logging_interface.h"

LoggingComponentFactory logging_factory;
LoggingCategoryInterface *main_logging;

std::string initFileName = "configuration_file";
logging = logging_factory.get_logging_interface(initFileName);
main_logging = logging->get_category("main");

logging->debug("My message");
main_logging->error("Bad things happened!")

We read from the log4cpp configuration files, of which several examples are provided within the library itself.

The configuration file starts by defining our categories, and relating them to an appender.

log4cpp.rootCategory=DEBUG, rootAppender
log4cpp.category.main=DEBUG, mainAppender

Then, we define our appenders. We can define a simple console appender like so:

log4cpp.appender.rootAppender=ConsoleAppender
log4cpp.appender.rootAppender.layout=PatternLayout
log4cpp.appender.rootAppender.layout.ConversionPattern=%d [%p] %m%n

Or a file appender like so:

log4cpp.appender.mainAppender=FileAppender
log4cpp.appender.mainAppender.threshold=DEBUG
log4cpp.appender.mainAppender.fileName=ivan_main.log
log4cpp.appender.mainAppender.layout=PatternLayout
log4cpp.appender.mainAppender.layout.ConversionPattern=%d [%p] %m%n

RollingFileAppender is also supported, which will roll the log file over beyond a certain size. Syslog appenders are also supported, as long as the process has permission to write to the syslog.

Alternatively, we can use a simple, default configuration that requires no config file:

std::string logFileName = "test.log";
logging = logging_factory.get_logging_interface(logFileName, AOSSL_LOG_DEBUG);
sub_category = logging->get_category("main");
logging->debug("My message");
sub_category->error("Bad things happened!")

Go Home