org.wso2.carbon.utils.logging
Class TenantAwarePatternLayout

java.lang.Object
  extended by org.apache.log4j.Layout
      extended by org.apache.log4j.PatternLayout
          extended by org.wso2.carbon.utils.logging.TenantAwarePatternLayout
All Implemented Interfaces:
org.apache.log4j.spi.OptionHandler

public class TenantAwarePatternLayout
extends org.apache.log4j.PatternLayout

A log4j pattern layout implementation capable of capturing tenant details from the Carbon Context. In addition to the default conversion characters, the character 'T' can be used to insert a tenant identifier, the character 'D' can be used to insert a tenant domain, and the character 'U' can be used to insert the username, character 'S' can be used to insert the Service name.

The special character 'P' can be used to insert a pattern layout, that will get printed if tenant information is available. The default layout for this is %U@%D [%T]. If tenant information is not available an empty string will be returned. The tenant pattern can be changed via the log4j configuration. You simply need to add a line in the format, log4j.appender.NAME.layout.TenantPattern=%U@%D [%T]. Available patterns: [%D] - tenant domain [%P] - tenant pattern (TenantPattern as configured in the log4j.properties file. eg: %U%@%D[%T] - will be converted to "username @ tenant_domain [tenant_id]" ) [%T] - tenant id [%S] - server name [%U] - user name [%A] - application name [%H] - host name/address [%I] - instance id How to use these patterns: Configure the log4j.properties file using above patterns. eg: for the console appender, log4j.appender.CARBON_CONSOLE.layout.ConversionPattern=TID: [%T] [%S] [%U] [%A] [%D] [%I] [%H] [%P] [%d] %P%5p {%c} - %x %m%n


Field Summary
static String DEFAULT_TENANT_PATTERN
          The default pattern to be injected in tenant-mode.
 
Fields inherited from class org.apache.log4j.PatternLayout
BUF_SIZE, DEFAULT_CONVERSION_PATTERN, MAX_CAPACITY, TTCC_CONVERSION_PATTERN
 
Fields inherited from class org.apache.log4j.Layout
LINE_SEP, LINE_SEP_LEN
 
Constructor Summary
TenantAwarePatternLayout()
          The default constructor.
TenantAwarePatternLayout(String pattern)
          Constructor accepting a layout pattern.
 
Method Summary
protected  org.apache.log4j.helpers.PatternParser createPatternParser(String pattern)
          
static void setSuperTenantText(String superTenantText)
          Method to set the string that will be put in place of the log pattern layout for the super tenant.
 void setTenantPattern(String tenantPattern)
          Method to set the log pattern layout for tenants.
 
Methods inherited from class org.apache.log4j.PatternLayout
activateOptions, format, getConversionPattern, ignoresThrowable, setConversionPattern
 
Methods inherited from class org.apache.log4j.Layout
getContentType, getFooter, getHeader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TENANT_PATTERN

public static final String DEFAULT_TENANT_PATTERN
The default pattern to be injected in tenant-mode.

See Also:
Constant Field Values
Constructor Detail

TenantAwarePatternLayout

public TenantAwarePatternLayout()
The default constructor.


TenantAwarePatternLayout

public TenantAwarePatternLayout(String pattern)
Constructor accepting a layout pattern.

Parameters:
pattern - the layout pattern.
Method Detail

createPatternParser

protected org.apache.log4j.helpers.PatternParser createPatternParser(String pattern)

Overrides:
createPatternParser in class org.apache.log4j.PatternLayout

setTenantPattern

public void setTenantPattern(String tenantPattern)
Method to set the log pattern layout for tenants.

Parameters:
tenantPattern - the log pattern layout for tenants.

setSuperTenantText

public static void setSuperTenantText(String superTenantText)
Method to set the string that will be put in place of the log pattern layout for the super tenant.

Parameters:
superTenantText - the string that will be put in place of the log pattern layout for the super tenant.


Copyright © 2014 WSO2 Inc. All rights reserved.