Simple logging connection handlers

Two logging connection handlers are included with the connection infrastructure. The handlers are designed for simple scenarios and as aids to problem determination when using the Connection API to work with a remote service.

Overview

The supplied simple logging connection handlers are:

simpleJavaLogger
Writes values read from the global context using the Java™ logging API.
simpleDestinationLogger
Sends values read from the global context to a destination using the POST operation of the Connection API.

The deployment and configuration requirements of the simple loggers are similar to each other, with the differences being related to the configuration to which the logging information is sent.

The simpleJavaLogger connection handler

When configured, the simpleJavaLogger writes a log entry corresponding to each request and response using the Java logging API. The contents of the log entry is controlled by the configuration supplied to the simpleJavaLogger handler, and can include the values of one or more global context keys. The log message text represents these as a readable set of name-value pairs, using toString().

The following example demonstrates the configuration for the simpleJavaLogger handler:

/config/connection/destinations += {
    "http://www.projectzero.org/*" : {
        "handlers" : [{
            "name" : "simpleJavaLogger",
            "config" : {
                "logger" : "mylogger",
                "source" : "mySource",
                "level" : "INFO",
                "request" : {
                    "method" : "myMethodName",
                    "keys" : ["/connection/request/target", "/connection/request/operation"]
                },
                "response" : {
                    "method" : "myMethodName",
                    "keys" : ["/connection/response/body"]
                }
            }
        }]
    }
}

All of the configuration parameters for the simpleJavaLogger are optional.

logger
The name of the java.util.logging.Logger to be written to. The logger name is used as an argument to Logger.getLogger(logger). The default value is zero.core.connection.handlers.logger.SimpleJavaLoggerHandler.
source
Name to be used as the source class for logging. The default value is zero.core.connection.handlers.logger.SimpleJavaLoggerHandler.
level
The logging Level to be used for logging. The default value is INFO.
request
Specification of the request message log:
method
Method name to be used when logging request. The default value is request.
keys
List of GlobalContext keys to be logged for request. The default value a list containing the single value, /connection/request/body.
response
Specification of the response message log:
method
Method name to be used when logging response. The default value is response.
keys
List of GlobalContext keys to be logged for response. The default value a list containing the single value, /connection/response/body.

For more information about connection destination processing and configuration, see Configuring destinations. For a description of connection handler configuration, see Configuring connection handlers.

This connection handler can alternatively be configured using the class attribute of the connection handler configuration, instead of name. New applications should normally use the name attribute for convenience but older applications might still use the class attribute. The class value for the simpleJavaLogger connection handler is zero.core.connection.handlers.logger.SimpleJavaLoggerHandler

The simpleDestinationLogger connection handler

When configured, the simpleDestinationLogger connection handler sends a message corresponding to each request and response invocation using the Connection API POST operation. The log destination and contents of the message are controlled by the configuration supplied to the simpleDestinationLogger handler, and can include the values of one or more global context keys.

The message body contains a Map of global context key to value Object. The representation of this Map received by the log destination depends on the configuration of connection handlers for the log destination and the protocol used. For example, the default representation of the message sent using the http protocol is a readable set of name-value pairs, using toString().

The the simpleDestinationLogger handler does not guarantee that every request or response passing through the destination is successfully logged. If the simpleDestinationLogger handler is unable to complete the POST to the log destination, the processing of the request or response continues without a corresponding entry being placed in the log.

The following example demonstrates the configuration for the simpleDestinationLogger handler:

/config/connection/destinations += {
    "http://www.projectzero.org/*" : {
       "handlers" : [{
           "name" : "simpleDestinationLogger",
           "config" : {
                "destination" : "http://localhost:8080/loggerservice",
                "request" : {
                    "keys" : ["/connection/request/target", "/connection/request/operation"]
                },
                "response" : {
                    "keys" : ["/connection/response/body"]
                }
           }
       }]
    }
}]
destination
The parameter is required and specifies the target resource name for the log destination. This can be any connection destination using a protocol that supports the POST operation and is able to accept Map request bodies. Examples include HTTP and SMTP.
request
Specification of the request message log:
keys
List of GlobalContext keys to be logged for request. The default value a list containing the single value, /connection/request/body.
response
Specification of the response message log:
keys
List of GlobalContext keys to be logged for response. The default value a list containing the single value, /connection/response/body.

For more information about connection destination processing and configuration, see Configuring destinations. For a description of connection handler configuration, see Configuring connection handlers.

This connection handler can alternatively be configured using the class attribute of the connection handler configuration, instead of name. New applications should normally use the name attribute for convenience but older applications might still use the class attribute. The class value for the simpleDestinationLogger connection handler is zero.core.connection.handlers.logger.SimpleDestinationLoggerHandler

Version 1.1.30763