9 Configuring Logging and Tracing

This chapter describes how to configure and manage logging and tracing for Oracle Communications Services Gatekeeper.

The Services Gatekeeper trace/logging system is derived from the WebLogic logging system. For background, see ”Configuring WebLogic Logging Services” in Fusion Middleware Configuring Log Files and Filtering Log Messages for Oracle WebLogic Server.

Using Log4j

Oracle recommends that you use Apache Log4j 2 for OCSG only.

The Log4j 2 logging mechanism is intended for some OCSG product functionality, including use of the Oracle WebLogic v12.2.1.x Coherence caching layer. Your use of Log4j 2 logging is primarily driven by your needs for troubleshooting application issues.

Classpath

With Log4j 2, instead of a single org.apache.log4j.jar file within the ./ocsg/modules folder, there are two jar files: org.apache.log4j-api.jar and org.apache.log4j-core.jar. The Class-Path attribute inside MANIFEST.MF of ./ocsg/modules/features/com.bea.wlcp.wlng.modules.jar references the two JAR files.

Configuration File

Runtime configuration changes are specified through the monitorInterval attribute of the Configuration element. Log4j2 uses the Log4j-config.xsd XSD Schema located within Log4j2 core jar, for example log4j-core-2.8.2.jar, for validation of the configuration file syntax.

Example 9-1 shows an Log4j 2.x configuration file, log4j2config.xml.

Example 9-1 Log4j 2.x Configuration File

<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="30">
  <Appenders>
    <!--
    <RollingFile name="oauth2" fileName="servers/${sys:weblogic.Name}/oauth2_log/oauth2.log" filePattern="servers/${sys:weblogic.Name}/oauth2_log/oauth2-%i.log">
      <PatternLayout>
        <Pattern>[%d{MM-dd hh:mm:ss}:%p %F] %m%n%n</Pattern>
      </PatternLayout>
      <Policies>
        <SizeBasedTriggeringPolicy size="10 MB" />
      </Policies>
      <DefaultRolloverStrategy max="10" />
    </RollingFile>
    -->
 
    <RollingFile name="edr" fileName="servers/${sys:weblogic.Name}/edr_log/edr.json"
     filePattern="servers/${sys:weblogic.Name}/edr_log/edr-%d{MM-dd-yyyy}.json">
     <PatternLayout>
       <Pattern>%m%n</Pattern>
     </PatternLayout>
     <Policies>
      <TimeBasedTriggeringPolicy interval="1"/>
     </Policies>
     <DefaultRolloverStrategy max="7" />
    </RollingFile>

    <RollingFile name="cdr" fileName="servers/${sys:weblogic.Name}/cdr_log/cdr.json"
     filePattern="servers/${sys:weblogic.Name}/cdr_log/cdr-%d{MM-dd-yyyy}.json">
     <PatternLayout>
      <Pattern>%m%n</Pattern>
     </PatternLayout>
     <Policies>
      <TimeBasedTriggeringPolicy interval="1"/>
     </Policies>
     <DefaultRolloverStrategy max="7" />
    </RollingFile>
 
    <RollingFile name="alarm" fileName="servers/${sys:weblogic.Name}/alarm_log/alarm.json"
     filePattern="servers/${sys:weblogic.Name}/alarm log/alarm-%d{MM-dd-yyyy}.json">
     <PatternLayout>
      <Pattern>%m%n</Pattern>
     </PatternLayout>
     <Policies>
      <TimeBasedTriggeringPolicy interval="1"/>
     </Policies>
     <DefaultRolloverStrategy max="7" />
    </RollingFile>
 
    <RollingFile name="qos" fileName="servers/${sys:weblogic.Name}/qos_log/qos.log" filePattern="servers/${sys:weblogic.Name}/qos_log/qos.log.%i">
      <PatternLayout>
        <Pattern>[%d{MM-dd hh:mm:ss}:%p %F] %m%n%n</Pattern>
      </PatternLayout>
      <Policies>
        <SizeBasedTriggeringPolicy size="10 MB" />
      </Policies>
      <DefaultRolloverStrategy max="10" />
    </RollingFile>
 
    <!-- Initially for root logger output -->
    <RollingFile name="trace" fileName="servers/${sys:weblogic.Name}/trace/default.log" filePattern="servers/${sys:weblogic.Name}/trace/default.log.%i">
      <PatternLayout>
        <Pattern>[%d{MM-dd hh:mm:ss}:%p %F] %m%n</Pattern>
      </PatternLayout>
      <Policies>
        <SizeBasedTriggeringPolicy size="10 MB" />
      </Policies>
      <DefaultRolloverStrategy max="10" />
    </RollingFile>
  </Appenders>
 
  <Loggers>
    <!--
    <Logger name="oracle.ocsg.oauth2" level="debug" additivity="false">
      <AppenderRef ref="oauth2" />
    </Logger>
    -->
 
    <!-- change 'info' to 'debug' to log EDRs -->
    <Logger name="OCSG.EdrLogger" level="info" additivity="false">
     <AppenderRef ref="edr" />
    </Logger>
 
    <Logger name="OCSG.CdrLogger" level="info" additivity="false">
     <AppenderRef ref="cdr" />
    </Logger>
 
   <Logger name="OCSG.AlarmLogger" level="info" additivity="false">
    <AppenderRef ref="alarm" />
   </Logger>

   <Logger name="oracle.ocsg.plugin.qos.diameter" level="info" additivity="false">
    <AppenderRef ref="qos" />
   </Logger>

   <Root level="info">
    <AppenderRef ref="trace" />
   </Root>
  </Loggers>
</Configuration>

Configuring Logging Using the Administration Console

This section explains how to change the Services Gatekeeper logging level. The default logging level is INFO. By default, errors are logged to the domain_home/servers/servername/trace/default.log file.

You will select a log4j severity level during this task. See the log4j documentation for descriptions of the logging levels at the Apache web site here:

https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html

To Configure Logging for a Services Gatekeeper server: 

  1. Start the Administration Console. This is the default URL:

    IP_Addr:7001/console
    

    Where IP_addr is the IP address of the system running Services Gatekeeper, and 7001 is the default port.

  2. Navigate to OCSG, then servername, then log4j, then log4j:Location=sername, logger=rootdefault

    Where servername is the name of the server you are configuring logging for.

    The Configuration and Provisioning on servername pane appears.

  3. Click Lock & Edit.

  4. Select the priority: checkbox.

  5. Enter a log severity level in the priority text field. The options are:

    • ALL

    • DEBUG

    • ERROR

    • FATAL

    • INFO

    • OFF

    • TRACE

    • WARN

  6. Click Update Attributes.

  7. Click Release Configuration.

Changing the Logging Level

For troubleshooting, you can change the logging level of a specific Services Gatekeeper managed-server logger. For example, you might want to change the level from INFO to DEBG.

To change the logging level, click the specific logger and then click the Attributes tab and specify the logging level.

Log4J Hierarchies, Loggers, and Appenders

You can view the logging hierarchy in the WebLogic Server administration console by selecting the OCSG managed-server instance and expanding the Log4j node. This displays the OCSG Log4j 2 loggers and appenders.

There is a set of Log4J Dynamic MBeans shipped with Services Gatekeeper that come by default with appenders. Appenders deliver LogEvents to their destination.

One Log4J hierarchy and one location are defined and displayed in the Services Gatekeeper Administration Console under Log4J as:

  • log4j:hiearchy=default,Location=AdminServer

The rootDefault logger is connected to the default hierarchy:

  • log4j:Location=AdminServer,logger=rootDefault

You can add loggers, and add appenders to the loggers. You can change both the priority of the logger and the appender to use. You can also configure parameters for the loggers and appenders.

To persist Log4J settings, use this configuration file:

domain_home/log4j/log4j2config.xml

Understanding the Trace Service

The trace service is based on Log4J. Services Gatekeeper maintains a log file, default.log, and each service instance writes to this log file on its local file system. The trace service writes log files in the domain_home/servers/server name/trace directory.

Understanding Basic Tracing

For basic tracing, the root logger rootdefault maintains the trace file.

Use these fields and methods to the TraceServiceMBean to configure and maintain basic tracing:

  • TracingEnabled field

  • attachAppender method

  • flushBuffers method

  • rollOver method

See "TraceServiceMBean Reference" for information on using this MBean.

Understanding Context Tracing

Services Gatekeeper uses context tracing to generate log messages filtered on the context of a request, for example for a certain service provider or application. This is in addition to basic tracing. A context filter has predefined filter types that define what to filter on. This enables you to trace on individual service providers, applications, and so on.

You can add new context trace files and context filters, and then apply context categories to these files to log messages from one or more Services Gatekeeper services.

To define a context trace file:

  1. In the Services Gatekeeper Administration Console, choose Container Services then TraceService.

  2. Select createContextTraceFile, or createRootContextTraceFile.

  3. For each context category to add for the context trace file, use the addContextCategory method to TraceServiceMBean

  4. For each context filter to add, use the addContextFilter method

See "TraceServiceMBean Reference" for information on using this MBean.

Configuring Trace for Access Tier servers

Trace configuration for network tier servers is performed through the Services Gatekeeper Administration Console by accessing Log4J for a server. For access tier servers, there are no management attributes or operations exposed in the Administration Console. This configuration must be done directly on the MBeans using a JMX-based Administration Console such as JConsole or using WLST.

For example, if you are using WLST, connect to the MBean server as described in "WebLogic Scripting Tool (WSLT)" and change to the custom tree where Services Gatekeeper MBeans are located. Change to the Log4J directory: cd('log4J').

The settings for the access tier servers can be changed in these directories:

  • log4j:appender=default

  • log4j:appender=default,layout=org.apache.log4j.TTCCLayout

  • log4j:hiearchy=default

  • log4j:logger=rootdefault

For example, to change the trace level for the access tier servers for the appender log4j:appender=default to WARN:

cd('log4j:appender=default')
set('threshold','WARN')

Using the Log4J Configuration File

In addition to using the Log4J MBeans, trace can be configured using the config.xml file a this location:

domain_home/log4j/log4jconfig.xml

The file contains an empty skeleton, by default.

The settings defined in this file are read every 30 seconds.

The ordering of the elements must be taken into account. Appenders must be declared before categories.

When using appenders that write to a file, the files are stored in domain_home.

Example Log4J Configuration file

Example 9-2 declares these appenders:

  • oauth2

  • edr

  • qos

  • trace

These appenders all use the same class, org.apache.log4j.FileAppender.

Each appender writes to a file whose name is given in the filename attribute. The appenders also use the same layout class, org.apache.log4j.PatternLayout, and ConversionPattern.

The appenders are used by a set of categories, where the name attribute defines which class to trace. The categories also define which Log4J priority is logged.

In the example, the following services are logged:

  • oracle.ocsg.oath2

  • com.bea.wlcp.wlng.edr.publisher

  • oracle.ocsg.plugin.qos.diameter

Example 9-2 Example log4jconfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="30">
  <Appenders>
    <!--
    <RollingFile name="oauth2" fileName="servers/${sys:weblogic.Name}/oauth2_log/oauth2.log"    filePattern="servers/${sys:weblogic.Name}/oauth2_log/oauth2-%i.log">
      <PatternLayout>
        <Pattern>[%d{MM-dd hh:mm:ss}:%p %F] %m%n%n</Pattern>
      </PatternLayout>
      <Policies>
        <SizeBasedTriggeringPolicy size="10 MB" />
      </Policies>
      <DefaultRolloverStrategy max="10" />
    </RollingFile>
    -->
 
    <RollingFile name="edr" fileName="servers/${sys:weblogic.Name}/edr_log/edr.log" filePattern="servers/${sys:weblogic.Name}/edr_log/edr-%i.log">
      <PatternLayout>
        <Pattern>[%d{MM-dd hh:mm:ss}:%p %F] %m%n%n</Pattern>
      </PatternLayout>
      <Policies>
        <SizeBasedTriggeringPolicy size="10 MB" />
      </Policies>
      <DefaultRolloverStrategy max="10" />
    </RollingFile>
 
    <RollingFile name="qos" fileName="servers/${sys:weblogic.Name}/qos_log/qos.log" filePattern="servers/${sys:weblogic.Name}/qos_log/qos-%i.log">
      <PatternLayout>
        <Pattern>[%d{MM-dd hh:mm:ss}:%p %F] %m%n%n</Pattern>
      </PatternLayout>
      <Policies>
        <SizeBasedTriggeringPolicy size="10 MB" />
      </Policies>
      <DefaultRolloverStrategy max="10" />
    </RollingFile>
 
    <!-- Initially for root logger output -->
    <RollingFile name="trace" fileName="servers/${sys:weblogic.Name}/trace/default.log" filePattern="servers/${sys:weblogic.Name}/trace/default-%i.log">
      <PatternLayout>
        <Pattern>[%d{MM-dd hh:mm:ss}:%p %F] %m%n</Pattern>
      </PatternLayout>
      <Policies>
        <SizeBasedTriggeringPolicy size="10 MB" />
      </Policies>
      <DefaultRolloverStrategy max="10" />
    </RollingFile>
  </Appenders>
 
  <Loggers>
    <!--
    <Logger name="oracle.ocsg.oauth2" level="debug" additivity="false">
      <AppenderRef ref="oauth2" />
    </Logger>
    -->
 
    <!-- change 'info' to 'debug' to log EDRs -->
    <Logger name="com.bea.wlcp.wlng.edr.publisher" level="info" additivity="false">
      <AppenderRef ref="edr" />
    </Logger>
 
    <Logger name="oracle.ocsg.plugin.qos.diameter" level="info" additivity="false">
      <AppenderRef ref="qos" />
    </Logger>
 
    <Root level="info">
      <AppenderRef ref="trace" />
    </Root>
  </Loggers>
</Configuration>

TraceServiceMBean Reference

TraceService MBean is exposed through the WebLogic Server administration console under the OCSG node's MBean heirarchy. Set field values and use methods from the Administration Console by selecting Container, then Services followed by TraceService. Alternately, use a Java application. For information on the methods and fields of the supported MBeans, see the ”All Classes” section of Services Gatekeeper OAM Java API Reference.

TraceService MBean Attributes

The TraceService MBean has the following attributes:

  • AspectTracingEnabled: True or False. If true, tracing of aspects is enabled. Disable to improve performance. Scope: cluster.

  • TracingEnabled: True or False. If true, tracing is enabled. Scope: cluster.

TraceService MBean Operations

The TraceService MBean supports the following operations:

  • addContextCategory

    Adds a category to an existing context trace file.

  • addContextFilter

    Adds one of the predefined filter types to the appender with the identified name.

  • attachAppender

    Allows adding a named appender to named loggers.

  • createContextTraceFile

    Creates a context trace file under root trace directory.

  • createRootContextTraceFile

    Creates a new root context trace file.

  • flushBuffers

    Flushes log buffers.

  • removeContextTraceFile

    Removes a context trace file.

  • resetContextFilters

    Removes all filters associated with a context trace file.

  • rollOver

    Rotates the log files.

For more information about these operations, see the TraceServiceMBean interface in Oracle Communications Services Gatekeeper OAM Java API Reference.