Skip to content
Kelly McLaughlin edited this page Aug 19, 2014 · 4 revisions

Overview

The information on this page only applies to version 1.10.0 or greater of Webmachine.

Logging in Webmachine is accomplished by an event manager process that generates event messages that may be handled by any registered event handler.

The default mode of operation does not include any registered event handler so no logging is enabled without explicit configuration.

Available log handlers

Webmachine comes with two built-in log handlers.

webmachine_access_log_handler

Logs all webmachine access events.

An example log entry is:

127.0.0.1 - - [18/Dec/2012:22:29:35 -0700] "GET /riak HTTP/1.1" 200 2 "" "curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5"

This is a very similar output format to the access logging done by Apache httpd for anyone familiar with that common webserver.

A sequential description of the fields is listed below:

  1. Source IP of the request
  2. '-'
  3. User (currently hard-coded to a '-')
  4. A date and time string
  5. A string containing the HTTP request verb, the request path, the protocol and protocol version.
  6. The response status code
  7. The response size in bytes
  8. The value of the User-Agent header sent by the orginator of the request

webmachine_perf_log_handler

Logs performance information about all webmachine access events.

An example log entry is:

127.0.0.1 -  [18/Dec/2012:22:29:35 -0700] "GET /riak HTTP/1.1" 200 2 riak_kv_wm_buckets 647 6

The fields of performance log entries are as follows:

  1. Source IP of the request
  2. '-'
  3. A date and time string
  4. A string containing the HTTP request verb, the request path, the protocol and protocol version.
  5. The response status code
  6. The response size in bytes
  7. The resource module that handled the request
  8. The time to process the request and send the response in milliseconds
  9. The time to handle any post-request processing including gathering any notes added during the request and th log data generated by the request.

Configuration

Adding a section like the following to the app.config file enables Webmachine logging when the application starts.

{webmachine, [
    {log_handlers, [
        {webmachine_log_handler, ["log"]},
        {webmachine_perf_log_handler, ["log"]}
    ]}
]},

Dynamically adding or removing log handlers

Log handlers may be added or removed while Webmachine is running using the following API.

  • Add a log handler - webmachine_log:add_handler(HandlerMod, Args)
  • Delete a log handler - webmachine_log:delete_handler(HandlerMod)

In the two function calls above, HandlerMod is an atom() reprsenting the name of the log handler module to be added or deleted. Args is a list of initialization parameters for the log handler being added.

e.g. The HandlerMod for the included access logging module is webmachine_log_handler and Args would be a single item list to indicate the directory where the access log files should be written such as ["/tmp"].