Logging - sonata-nfv/tng-sla-mgmt GitHub Wiki
- log4j Core - log4j-core 2.11.1
- log4j2 for extended json layout - net.savantly.log4j2 1.0.0
tng-sla-mgmt
uses a configuration file, which include a Console Appender for SYSTEM_OUT log printing, with INFO as the default log level.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="console" target="SYSTEM_OUT"/>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="console" />
</Root>
</Loggers>
</Configuration>
To log a message, we create a final static logger and define a name for the logger, normally, we use the full package class name.
static Logger logger = LogManager.getLogger("");
Then, we log messages with different priorities, for example, debug, info, warn, error and fatal. The SLA Manager uses mainly info, debug or warn.
logger.info("{\"type\":\"{}\",\"timestamp\":\"{}\",\"start_stop\":\"\",\"component\":\"tng-sla-mgmt\",\"operation\":\"{}\",\"message\":\"{}\",\"status\":\"{}\",\"time_elapsed\":\"\"}", type, timestamps, operation, message, status);
{
"type": "I",
"timestamp": "2018-11-26 10:0:00 UTC",
"component": "tng-sla-mgmt",
"operation": "sla template creation",
"message": "temlate created",
"status": "201"
}