Enabling Logs for Services

The advantage of having per-service log files is that it is very easy to analyze/monitor what went wrong in this particular service (proxy service, data service etc.) by looking at the service log. Enabling this feature will not terminate the wso2carbon.log file. This file will contain the complete log with every log statement, including the service logs that you have configured to be logged into a different log file. In other words, the service log is an additional log file, which will contain a copy of the logs to that particular service.

Follow the instructions below to configure the logs of a particular service to be logged into a given log file.  The following steps explain how to enable logs for a sample proxy service deployed in WSO2 Micro Integrator.

  1. Consider a proxy service named StockQuoteProxy.
  2. Configure log4j to log the service specific logs to a file called stock-quote-proxy-service.log in the logs directory of the product installation directory.

    1. Open up the log4j2.properties file found in the conf directory of the product installation directory using your favorite text editor and add the following section to the end of the file starting in a new line.

      # SQ_PROXY_APPENDER is set to be a DailyRollingFileAppender using a PatternLayout.
      appender.SQ_PROXY_APPENDER.type = RollingFile
      appender.SQ_PROXY_APPENDER.name = SQ_PROXY_APPENDER
      appender.SQ_PROXY_APPENDER.fileName = ${sys:carbon.home}/repository/logs/stock-quote-proxy-service.log
      appender.SQ_PROXY_APPENDER.filePattern = ${sys:carbon.home}/repository/logs/stock-quote-proxy-service-%d{MM-dd-yyyy}.log
      appender.SQ_PROXY_APPENDER.layout.type = PatternLayout
      appender.SQ_PROXY_APPENDER.layout.pattern = TID: [%d] %5p {%c} [%logger] - %m%ex%n
      appender.SQ_PROXY_APPENDER.policies.type = Policies
      appender.SQ_PROXY_APPENDER.policies.time.type = TimeBasedTriggeringPolicy
      appender.SQ_PROXY_APPENDER.policies.time.interval = 1
      appender.SQ_PROXY_APPENDER.policies.time.modulate = true
      appender.SQ_PROXY_APPENDER.policies.size.type = SizeBasedTriggeringPolicy
      appender.SQ_PROXY_APPENDER.policies.size.size=10MB
      appender.SQ_PROXY_APPENDER.strategy.type = DefaultRolloverStrategy
      appender.SQ_PROXY_APPENDER.strategy.max = 20
      appender.SQ_PROXY_APPENDER.filter.threshold.type = ThresholdFilter
      appender.SQ_PROXY_APPENDER.filter.threshold.level = DEBUG        
    2. Add SQ_PROXY_APPENDER as an appender

      appenders = CARBON_CONSOLE, CARBON_LOGFILE, AUDIT_LOGFILE, SQ_PROXY_APPENDER, 
    3. Add a logger to filter out StockQuoteProxy related logs

      logger.StockQuoteProxy.name = SERVICE_LOGGER.StockQuoteProxy
      logger.StockQuoteProxy.level = INFO
      logger.StockQuoteProxy.appenderRef.SQ_PROXY_APPENDER.ref = SQ_PROXY_APPENDER
      logger.StockQuoteProxy.additivity = false

    4. Add StockQuoteProxy as a logger
      loggers = AUDIT_LOG, StockQuoteProxy, SERVICE_LOGGER,
    5. Save the file.
  3. Try it out. By default, the configuration does not do any logging at runtime, so configure the Proxy Service in-sequence to contain a log mediator to log the message at "Full" log level.

Further, to demonstrate the log file rotation; this particular logger was configured to rotate the file in each minute whenever there is a log going into the service log. Therefore, if you execute the sample client once again after 1 minute, you will be able to see the service log file rotation as well.

Top