This documentation is for WSO2 API Manager 2.6.0. View documentation for the latest release.

All docs This doc

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updated to DOCUMENTATION-7979

...

  1. Add the following entry in the <API-M_HOME>/repository/conf/log4j.properties configuration file.

    Code Block
    languagexml
    log4j.logger.org.apache.synapse.transport.http.access=INFO
  2. Create a file named <API-M_HOME>/repository/conf/access-log.properties with the following configuration and customize it as required.
    You can customize the format of your PassThrough or NIO access logs based on the configurations in your  access-log.properties file.

    Note
    All the supported options are in the following file. Therefore, make sure to uncomment the required options to enable them as required.
    Code Block
    # Default access log pattern
    #access_log_pattern=%{X-Forwarded-For}i %h %l %u %t \”%r\” %s %b \”%{Referer}i\” \”%{User-Agent}i\”
    # combinded log pattern
    #access_log_pattern=%h %l %u %t \”%r\” %s %b \”%{Referer}i\” \”%{User-Agent}i\”
    access_log_pattern=time=%t remoteHostname=%h localPort=%p localIP=%A requestMethod=%m requestURL=%U remoteIP=%a requestProtocol=%H HTTPStatusCode=%s queryString=%q
    # common log pattern
    #access_log_pattern=%h %l %u %t \”%r\” %s %b
    # file prefix
    access_log_prefix=http_gw
    # file suffix
    access_log_suffix=.log
    # file date format
    access_log_file_date_format=yyyy-MM-dd
    #access_log_directory=”/logs”
    access_log_directoryAdd this property ONLY if you want to change the default location of the log file.
    By default, the product is configured to store access logs in the <API-M_HOME>/repository/logs directory.
    access_log_prefixThe prefix added to the name of the log file.
    access_log_suffixThe suffix added to the name of the log file.
    access_log_file_date_formatThe date format used in access logs.
    access_log_pattern

    The attribute defines the format for the log pattern, which consists of the information fields from the requests and responses that should be logged. The pattern format is created using the following attributes:

    • A standard value to represent a particular string. For example, "%h" represents the remote host name in the request. Note that all the string replacement values supported by Tomcat are NOT supported for the passthrough transport's access logs. The list of supported values are given below.

    • %{xxx}i is used to represent the header in the incoming request (xxx=header value).
    • %{xxx}o is used to represents the header in the outgoing request (xxx=header value).

    While you can use the above attributes to define a custom pattern, the standard patterns shown below can be used.

    By default, a modified version of the Apache combined log format is enabled in WSO2 API-M as shown below. Note that the "X-Forwarded-For" header is appended to the beginning of the usually combined log format. This correctly identifies the original node that sent the request (in situations where requests go through a proxy such as a load balancer). The "X-Forwarded-For" header must be present in the incoming request for this to be logged.


    Code Block
    access_log_pattern=%{X-Forwarded-For}i %h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-Agent}i\"
  3. Add the following configuration in the <API-M_HOME>/repository/conf/nhttp.properties file.
    You need to add this configuration in order to make sure that the access logs related to the PassThrough and NIO transports are rotated on a daily basis. If this configuration is not set, all the access log details related to the PassThrough and NIO transports will get logged in a single file. The date will be appended to the access log when it is rotated.

    Code Block
    nhttp.is.log.rotatable=true
  4. Restart the server. 

  5. Invoke an API in WSO2 APIM.
    For testing purposes, use the artifacts in the quick start guide
    The access log file for the service/API will be created in the <API-M_HOME>/repository/logs directory .  in the following format.

    <access_log_prefix>.log 

    For example, http_gw.log file. 

    Note

    Note that there will be delay in printing the logs to the access log file.

...