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 contained in the following list:

SimpleJavaLoggerHandler
Writes values read from the global context using the Java™ logging API.
SimpleDestinationLoggerHandler
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.

SimpleJavaLoggerHandler

When configured, SimpleJavaLoggerHandler writes a log entry corresponding to each onRequest() and onResponse() invocation using the Java logging API. The contents of the log entry is controlled by the configuration supplied to SimpleJavaLoggerHandler, 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 SimpleJavaLoggerHandler:

/config/connection/destinations += {
    "http://www.projectzero.org/*" : {
        "handlers" : [{
            "class" : "zero.core.connection.handlers.logger.SimpleJavaLoggerHandler",
            "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 SimpleJavaLoggerHandler 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.

SimpleDestinationLoggerHandler

When configured, SimpleDestinationLoggerHandler POST a message corresponding to each onRequest() and onResponse() invocation using the Connection API. The log destination and contents of the message are controlled by the configuration supplied to SimpleDestinationLoggerHandler, 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 SimpleDestinationLoggerHandler does not guarantee that every request or response passing through the destination is successfully logged. If the SimpleDestinationLoggerHandler 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 SimpleDestinationLoggerHandler:

/config/connection/destinations += {
    "http://www.projectzero.org/*" : {
       "handlers" : [{
           "class" : "zero.core.connection.handlers.logger.SimpleDestinationLoggerHandler",
           "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.

Version 1.0.0.3.25591