External Logging

You can persist your  log messages by creating a logger for externalizing your API logs.  uses the Apache Log4j 2 framework for API-level logging.
calac41
You can persist your 
CA Live API Creator
 log messages by creating a logger for externalizing your API logs. 
CA Live API Creator
 uses the Apache Log4j 2 framework for API-level logging.
Having your API logs in a central repository can help you:
  • Identify API errors.
  • Identify error frequency.
  • Narrow down the rules or SQL execution that are causing the API errors. 
For more information about the Log4j 2 framework, see the Apache Log4j 2 documentation.
In this article:
3
 
 
Configure External Logging
Use the following process to configure external logging:
Create the Logging Configuration File
Create the logging configuration file that includes a logger entry for 
CA Live API Creator
 logging. You can externalize these logs by specifying the logger to use the Log4j 2 appenders or you can create your own appender and point the logger to it.
The following XML snippet shows an example logger entry of a Log4j 2 configuration file that includes a logger entry for 
CA Live API Creator
 logging:
<Logger name="lacapplogger" level="debug" additivity="false">
<AppenderRef ref="file" />
</Logger>
 
CA Live API Creator
 reads the appender you created, the 
lacapplogger
 logger, and dynamically links the appenders of this logger to 
CA Live API Creator
.
The following table shows the Log4j 2 logger's log levels and how these levels map to logging log levels in 
CA Live API Creator
:
Log4j Log Level
Log Level in 
CA Live API Creator
 
ERROR
error
WARN
warning
INFO
info
DEBUG
debug
FINER
finer
TRACE
finest
For example, if you configure the Log4j 2 logger to use the 
debug
 level, 
CA Live API Creator
 logs the logs that are in the 
fine
 log level and below to the logger.
For more information about the Log4j 2 appenders, see the Apache documentation. 
 
Example:
 
The following sample shows a configuration file that specifies the logger to use the log4j 2 appenders to push API log entries to a file in the server:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="error" strict="true" name="Externalconfig">
<Properties>
<Property name="filename">/pathToLogfile/log_test_customer.log</Property>
</Properties>
<Filter type="ThresholdFilter" level="trace" />
<Appenders>
<Appender type="File" name="file" fileName="${filename}" createOnDemand="true">
<Layout type="PatternLayout">
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</Layout>
</Appender>
</Appenders>
<Loggers>
<Logger name="lacapplogger" level="debug" additivity="false">
<AppenderRef ref="file" />
</Logger>
<Root level="error">
<AppenderRef ref="consoleout" />
</Root>
</Loggers>
</Configuration>
Configure the Logging Configuration File
Specify the location of the logging configuration file as the value for the 
lac.logging.config.file
 Java system property.
Create the logger based on the application servers you have installed 
CA Live API Creator
:
 
Create a Logger for a Jetty application server
Add the 
lac.logging.config.file
 Java system property to the API Server startup:
-Dlac.logging.config.file=/<path_to_your_configuration_file>/<configuration_file_name>
A logger for Jetty is created.
 
Create a Logger for an Apache Tomcat application server
 Add the 
lac.logging.config.file
 Java system property to the API Server startup:
-Dlac.logging.config.file=/<path_to_your_configuration_file>/<configuration_file_name>
A logger for Tomcat is created.
 
Create a Logger for an Oracle WebLogic application server
Add the 
lac.logging.config.file
 Java system property to the API Server startup:
-Dlac.logging.config.file=/<path_to_your_configuration_file>/<configuration_file_name>
A logger for WebLogic is created.
 
Create a Logger for a JBoss/WildFly application server
Add the 
lac.logging.config.file
 Java system property to the API Server startup:
-Dlac.logging.config.file=/<path_to_your_configuration_file>/<configuration_file_name
For more information about how to create system properties in JBoss/WildFly, see the JBoss documentation.
A logger for JBoss is created.
Create a Logger for an IBM WebSphere application server
Add your own application logger for 
CA Live API Creator
 deployed on WebSphere application server.
Based on your WebSphere application server setup, you might need to perform extra configuration to create a logger for WebSphere. We recommend that you contact your WebSphere administrator before creating a logger for WebSphere.
In the WebSphere administrative console, navigate to the Java virtual machine (JVM) Custom Properties page and ensure that WebSphere initializes external Log4j 2 configuration by enabling the following system property:
-Dlac.logging.config.file=/<path_to_your_configuration_file>/<configuration_file_name
For more information about how to add system properties to the JVM, see the IBM documentation.
A logger for WebSphere is created.
View your Logs in a Central Repository
The external logs are formatted based on the handler to which your logger is pointing.
The following properties are available in your log message:
Property
Description
date
The timestamp for the log message.
millis
The event time in milliseconds (since 1970) for the log message.
sequence
The unique sequence number for the log message.
logger
The type of logger in 
CA Live API Creator
. For example,
a
dmini
 and 
resrcs
.
level
The log level for the log message.
 
Values:
 (From highest to lowest) error, warning, info, debug, finer, and finest
You can control the level of logging for the auth tokens you have created within your API.
For more information about how to control the logging level, see Auth Tokens.
For more information about logging levels in 
CA Live API Creator
, see View Logging Information.
class
The class for the log message, using the following syntax:
host:<host name> - keyname:<key name> - <full URL>
method
The HTTP method (GET, PUT, POST, DELETE) for the log message.
thread
The thread identifier within the Java VM.
message
The log message. For example:
Resource Read demo:employee SQL: `dblocal_demo`.`employee` select 0 `EL__BATCHNUMBER` ,`employee_id` ,`login` ,`name` from `dblocal_demo`.`employee` `el__this` order by `login` limit 21
Improve Performance by Enabling Asynchronous Logging
If you have deployed 
CA Live API Creator
 to a high-end machine, or to a cluster of high-end machines, that is equipped to handle a lot of traffic, you can improve the performance of 
CA Live API Creator
 by enabling asynchronous logging. With asynchronous logging, 
CA Live API Creator
 executes the input/output (I/O) operations in a separate thread.
 
Prerequisite:
 You have reviewed the drawbacks of Log4j 2 asynchronous loggers. For more information about Log4j 2 asynchronous loggers, see the Apache Log4j 2 documentation.
Before starting API Server, add the following system property to the Java command line for your server:
-DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
Prevent Log Injection by Enabling Log Encoding
You can prevent log injection by enabling log encoding at startup. Log injection is a mechanism whereby unvalidated user input to log files can allow an attacker to forge log entries or inject malicious content into the logs. By default, log encoding is disabled.
For more information about log injection, see the OWSAP org site.
Before starting API Server, add the following system property to the Java command line for your server:
-DLAC_LOG_ENCODING_REQUIRED=true
For more information about this option and other options that you can add at server startup, see Common Installation Options.