External Logging

You can persist your  log messages by creating a logger for externalizing your API logs.  uses the java.util.logging framework for API-level logging.
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 
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 
 framework, see the Oracle documentation.
In this article:
Configure External Logging
Use the following process to configure external logging:
Create the Logging Property File
Create a logging property file that includes a logger entry for
CA Live API Creator
 logging. You can specify the logger to use the built-in
 handler or point it to a custom handler, such as a database handler. Prefix the logger entry in the logging property file with the
 keyword, including the period (.).
The following code snippet shows an example logger entry:
lacapplogging.<YOUR LOGGER NAME>.level = FINEST
lacapplogging.<YOUR LOGGER NAME>.handlers = java.util.logging.FileHandler
The logging property file is created and is available to API Server. 
CA Live API Creator
 reads the logger that is prefixed with the 
keyword and dynamically links the logger to 
CA Live API Creator
The following sample logging property file uses a file handler to push API log entries to a file in the server:
# root handlers
handlers = java.util.logging.ConsoleHandler
# Set the default logging level for the root logger
.level = FINEST
# -- Logging to File -- #
lacapplogging.file.logger.level = FINEST
lacapplogging.file.logger.handlers = java.util.logging.FileHandler
java.util.logging.FileHandler.level     = FINEST
java.util.logging.FileHandler.limit     = 0
java.util.logging.FileHandler.append    = true
java.util.logging.FileHandler.pattern   = /yourpath/applog.%u.%g.txt
java.util.logging.SimpleFormatter.format="%1$tc %2$s%n%4$s: %5$s%6$s%n"
Sample Database Handler
You can create a custom handler that logs to a database instead of to a file or a socket. The following code sample is an example of a database handler. You can use the following code sample as an example to create your own handler:
Code sample
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
* This is a sample Database handler for Java.util.logging. --CUSTOMIZE and TEST BEFORE USE--
* Schema for the log table.
* CREATE TABLE lacapplog (
level integer NOT NULL,
logger varchar(64) NOT NULL,
message varchar(255) NOT NULL,
sequence integer NOT NULL,
sourceClass varchar(64) NOT NULL,
sourceMethod varchar(32) NOT NULL,
threadID integer NOT NULL,
timeEntered datetime NOT NULL)
public class LACDBHandler extends Handler{
  private String driverClassName;
  private String connectionURL;
  private Connection con;
  private String username;
  private String password;
  private PreparedStatement pStmt;
  * Parameters to be passed to the constructor
  * @param driverClassName - Class of the driver.
  * @param connectionUrl - Full JDBC connectionURL
  * @param username - DB access Username
  * @param password - DB access password
  public LACDBHandler(String driverClassName, String connectionUrl,String username, String password){
    this.driverClassName = driverClassName;
    this.connectionURL = connectionUrl;
    this.username = username;
    this.password = password;
    System.out.println("Driver :"+driverClassName);
    System.out.println("Connection URL :"+connectionURL);
  public LACDBHandler(){
  private void connect() {
    try {
      con = DriverManager.getConnection(connectionURL, username, password);
      String insertQuery = "INSERT INTO `laclogging`.`lacapplog`" + "(`level`," + "`logger`,"
        + "`message`," + "`sequence`," + "`sourceClass`," + "`sourceMethod`," + "`threadId`," + "`timeEntered`)"
        + "VALUES" + "(?,?,?,?,?,?,?,?);";
      pStmt = con.prepareStatement(insertQuery);
    } catch (ClassNotFoundException e) {
        System.out.println("Driver class not found for Database Log Handler.");
    } catch (SQLException e) {
        System.out.println("SQL Exception while connecting to the database for Logging.");
* Publish log record.
* @param record
  public void publish(LogRecord record) {
    try {
      Timestamp ts = new Timestamp(record.getMillis());
      pStmt.setInt(1, record.getLevel().intValue());
      pStmt.setString(2, record.getLoggerName());
      pStmt.setString(3, record.getMessage());
      pStmt.setLong(4, record.getSequenceNumber());
      pStmt.setString(5, record.getSourceClassName());
      pStmt.setString(6, record.getSourceMethodName());
      pStmt.setTimestamp(8, ts);
    } catch (SQLException e) {
        System.out.println("Exception inserting :"+record.toString());
  public void flush() {
  // Nothing here.
  public void close() throws SecurityException {
    try {
    } catch (SQLException e) {
Create the Logger
Specify the location of the logging property file as the value for the 
 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 
 Java system property to the API Server startup:
A logger for Jetty is created.
Create a Logger for an Apache Tomcat application server
  1.  Add the 
     Java system property to the API Server startup:
  2. Complete one of the following:
    • Add the logger entry for 
      CA Live API Creator
       logging to Tomcat’s JULI framework to the 
      Tomcat uses JULI for logging. For more information about logging in Tomcat, including JULI, see Apache Tomcat documentation.
    • Add the logging property file to the 
A logger for Tomcat is created.
Create a Logger for an Oracle WebLogic application server
Add the 
 Java system property to the API Server startup:
A logger for WebLogic is created.
Create a Logger for a JBoss/WildFly application server
For more information about how to configure logging in JBoss/WildFly, see the JBoss documentation.
  1. From the JBoss/WildFly admin console, complete the following:
    1. Create the logging property file, 
       Java system property.
      For more information about how to create a Java system property in JBoss/WildFly, see the JBoss documentation.
    2. Add the 
       Java system property as the
      and add the absolute path to the property file as the
  2. Open the <
     file and complete the following:
    1. Add the handler configuration for
      CA Live API Creator
       logging that matches the logger name in the logging properties file:
      <periodic-rotating-file-handler name="<YOUR HANDLER NAME>" autoflush="true"> <formatter> <named-formatter name="PATTERN"/> </formatter> <file path="/pathtothelogfile/server.log"/> <suffix value=".yyyy-MM-dd"/> <append value="true"/> </periodic-rotating-file-handler>
    2. Add a logger entry for 
      CA Live API Creator
       logging that matches the logger name in the logging properties file:
      <logger category="<YOUR LOGGER NAME>" use-parent-handlers="false">
      <level name="FINEST"/>
      <handler name=" CALAC_FILE_HANDLER "/>
    3. Add a formatter for the log entries:
      <formatter name="PATTERN">
      <pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"/>
    The logging property file is added to JBoss/WildFly’s logging subsystem.
  3. Reload the server.
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, there might be extra configuration that is required 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 
 by enabling the following properties:
-Djava.util.logging.config.file=/opt/laclog/laclogging.properties -Djava.util.logging.configureByLoggingPropertiesFile=true
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:
The timestamp for the log message.
The event time in milliseconds (since 1970) for the log message.
The unique sequence number for the log message.
The type of logger in
CA Live API Creator
. For example,
The log level for the log message.
(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 The apikeys Endpoint.
For more information about logging levels in
CA Live API Creator
, see View Logging Information.
The class for the log message, using the following syntax:
host:<host name> - keyname:<key name> - <full URL>
The HTTP method (GET, PUT, POST, DELETE) for the log message.
The thread identifier within the Java VM.
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