◀︎ Airlift • ◀︎ Getting Started • ◀︎ Next Steps
Airlift includes a simple logging API based on the JDK logging package.
We need a few additional dependencies. Add the following to the dependencies section of your
pom.xml
file:
<dependency>
<groupId>io.airlift</groupId>
<artifactId>log</artifactId>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>log-manager</artifactId>
</dependency>
Example logging:
import io.airlift.log.Logger;
public class MyClass
{
private static final Logger LOG = Logger.get(MyClass.class);
public void fooBar(String argument)
{
LOG.info("Formatted output %s", argument);
}
}
The logging system has several configuration options that are provided to make it easier to use in cloud native environments.
-
log.output-file
can be set to the desired output for logging and also provides a mechanism to stream logs over tcp. Setting this to the formattcp://<host>:<port>
will enable the socket logger for tcp streaming. -
log.format
can be set to eithertext
orjson
. When set tojson
, the log record is formatted as a JSON object, one per line. Any newlines in the field values, such as exception stack traces, will be escaped as normal in the JSON object. This allows for capturing and indexing exceptions as singular fields in a logging search system. -
node.annotation-file
allows a file containing fields to be set at startup that can be interpolated from environment variables and will be included in all log output.For example:
#config.properties node.annotation-file=annotations.properties log.format=json
#annotations.properties hostIp=${ENV:HOST_IP} podName=${ENV:POD_NAME}
{ "timestamp": "2021-12-06T16:23:41.352519093Z", "level": "DEBUG", "thread": "main", "logger": "TestLogger", "message": "Test Log Message", "annotations": { "hostIp": "127.0.0.1", "podName": "mypod" } }