Logging Framework
OpenIG uses the objects in this section to log events to the console or to files.
ConsoleLogSink — log to standard error
Properties
"level": string, optional-
The level of log entries.
Must be one of the following settings. These are ordered from most verbose to least verbose:
-
ALL(log all messages) -
TRACE(log low-level tracing information) -
DEBUG(log debugging information) -
STAT(log performance measurement statistics) -
CONFIG(log configuration information) -
INFO(log general information) -
WARNING(log potential problems) -
ERROR(log serious failures) -
OFF(log no messages)
Default:
INFO. -
"stream": string, optional-
The standard output to use to display logs in the console.
Must be one of the following settings:
-
ERR(use standard error: System.err) -
OUT(use standard output: System.out) -
AUTO(select standard error or output depending on the message log level: TRACE, DEBUG, STAT, CONFIG, INFO print toSystem.out; WARNING and ERROR print toSystem.err)
Default:
ERR. -
FileLogSink — log to a file
Usage
{
"name": string,
"type": "FileLogSink",
"config": {
"file": configuration expression,
"level": string
}
}
Properties
"file": configuration expression, required-
The path to the log file.
A configuration expression, described in Expressions(5) is independent of the request, response, and contexts, so do not use expressions that reference their properties. You can, however, use
${env['variable']},${system['property']}, and all the built-in functions listed in Functions(5). "level": string, optional-
The level of log entries.
Must be one of the following settings. These are ordered from most verbose to least verbose:
-
ALL(log all messages) -
TRACE(log low-level tracing information) -
DEBUG(log debugging information) -
STAT(log performance measurement statistics) -
CONFIG(log configuration information) -
INFO(log general information) -
WARNING(log potential problems) -
ERROR(log serious failures) -
OFF(log no messages)
Default:
INFO. -
Slf4jLogSink — delegate log writing to SLF4J
Description
A log sink that delegates the writing of logs to SLF4J. OpenIG uses the Logback implementation of the SLF4J API. Use this log sink to define different logging behavior for routes and third-party dependencies.
A default configuration for logging is defined in OpenIG. To change the configuration, create a file $HOME/.openig/config/logback.xml. For a description of the available parameters, see the Logback website.
Properties
"base": string, optional-
The name for a logger that can be defined in
logback.xml. The logger identifies a route or third-party dependency for which to define different logging behavior.Logger names follow a hierarchical naming rule. When an object logs a message to
Slf4jLogSink, a descendant logger is created the whose name is a concatenation of the base and the object name, separated with a.. For example, when an objectMyObjectlogs a message to to anSlf4jLogSinkwith basecom.example.app, a logger namedcom.example.app.myobjectis created.The hierarchical naming allows you to configure
logback.xmlwith different logging characteristics for different components in a route.Default: Empty string.
Example
In the following example, requests from the client filter, MyObject, create a logger called com.example.app.myobject.
{
"name": "MyLogSink",
"type": "Slf4jLogSink",
"config": {
"base": "com.example.app"
}
},
{
"name": "MyObject",
"type": "OAuth2ClientFilter",
"config": {
"logSink": "MyLogSink"
}
}
The following logback.xml sets the logging level to DEBUG for requests from the client filter, and to INFO for other requests with the base com.example.app.
<?xml version="1.0" encoding="UTF-8"?><configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<logger name="com.example.app" level="INFO"/>
<logger name="com.example.app.myobject" level="DEBUG"/>
<root level="DEBUG">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
For an example configuration, see Separating Logs for Different Routes in the Gateway Guide.