Fields Summary |
---|
private static FileandSyslogHandler | handlerSingleton |
private static ConsoleHandler | consoleHandler |
private static SystemLogHandler | syslogHandler |
private static DeploymentAuditLogHandler | deploymentAuditHandler |
private static boolean | syslogLibraryLoadError |
private static Handler | customHandler |
private static Filter | customFilter |
private static ServerLogManager | thisInstance |
private static List | listOfUnInitializedLoggers |
private static Boolean | verboseMode |
private static boolean | customFilterError |
private static boolean | customHandlerError |
private static final String | SUN_OS |
private static final String | LINUX_OS |
private static final String | OS_NAME_PROPERTY |
private Object | lockObj |
private static final String | ORG_APACHE_CATALINA |
private static final String | ORG_APACHE_COYOTE |
private static final String | ORG_APACHE_JASPER |
private static final String | SYNCHRONIZATION |
Methods Summary |
---|
public static java.util.logging.Level | getConfiguredLogLevel(java.lang.String loggerName)Given a logger name, this method returns its level as defined
in domain.xml (the app server config file).
_REVISIT_:
1. Replace multiple if (loggerName) checks with a Hashmap
ServerContext sc = ApplicationServer.getServerContext();
if (sc == null) {
if (loggerName.startsWith(SYNCHRONIZATION)) {
try {
String level = System.getProperty(SYNCHRONIZATION, "INFO");
return Level.parse(level);
} catch (Exception e) {
return Level.INFO;
}
} else {
return Level.INFO;
}
}
if (loggerName.equals(LogDomains.DPLAUDIT_LOGGER)) {
try {
Level level = DeploymentAuditLogHandler.getConfiguredLevel();
return level;
} catch (Throwable thr) {
return Level.OFF;
}
}
Level logLevel = null;
try {
Config cfg =
ServerBeansFactory.getConfigBean(sc.getConfigContext());
ModuleLogLevels allModulesLogLevels =
cfg.getLogService().getModuleLogLevels( );
// _REVISIT_: Right now ModuleLogLevels element in Log-Service
// is optional. If the user doesn't specify any module log levels
// then we will use 'INFO' as the default. For 8.1 this should
// be a required element.
if( allModulesLogLevels == null ) { return Level.INFO; }
if( allModulesLogLevels.getRoot( ).equals( "OFF" ) ) {
return Level.OFF;
}
// _REVISIT_: This is a bad way of searching for a loggername match
// clean this up after Technology Preview
ElementProperty[] elementProperties =
cfg.getLogService().getModuleLogLevels().getElementProperty( );
if( elementProperties != null ) {
for( int i = 0; i < elementProperties.length; i++ ) {
if( elementProperties[i].getName().equals(loggerName) ) {
return Level.parse( elementProperties[i].getValue());
}
}
}
String logModName = ModuleToLoggerNameMapper.getModuleName(loggerName);
if (logModName!=null) {
try {
String val = allModulesLogLevels.getAttributeValue(logModName);
logLevel = Level.parse(val);
} catch (Exception noSuch) { //no such module name,such as "core", in <module-log-levels>
}
}
} catch ( Exception e ) {
new ErrorManager().error( "Error In Setting Initial Loglevel", e,
ErrorManager.GENERIC_FAILURE );
}
return logLevel;
|
private static synchronized java.util.logging.Handler | getConsoleHandler()This is a Singleton factory method to get an instance of ConsoleHandler.
if( consoleHandler == null ) {
try {
consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.ALL);
consoleHandler.setFormatter(new UniformLogFormatter());
} catch( Exception e ) {
new ErrorManager().error(
"Exception caught in getConsoleHandler ",
e, ErrorManager.GENERIC_FAILURE );
}
}
return consoleHandler;
|
private static java.util.logging.Filter | getCustomFilter()If there is any Custom Filter we will use that.
if(( customFilter != null )
||( customFilterError ) )
{
return customFilter;
}
LogService logService = getLogService( );
if( logService == null ) {
return null;
}
String customFilterClassName = null;
try {
customFilterClassName = logService.getLogFilter( );
customFilter = (Filter) getInstance( customFilterClassName );
} catch( Exception e ) {
customFilterError = true;
new ErrorManager().error( "Error In Instantiating Custom Filter " +
customFilterClassName, e, ErrorManager.GENERIC_FAILURE );
}
return customFilter;
|
private static synchronized java.util.logging.Handler | getCustomHandler()If there is any custom handler we will use that.
if( (customHandler != null )
||(customHandlerError) )
{
return customHandler;
}
LogService logService = getLogService( );
if( logService == null ) {
return null;
}
String customHandlerClassName = null;
try {
customHandlerClassName = logService.getLogHandler( );
customHandler = (Handler) getInstance( customHandlerClassName );
// We will plug in our UniformLogFormatter to the custom handler
// to provide consistent results
if( customHandler != null ) {
customHandler.setFormatter( new UniformLogFormatter( ) );
}
} catch( Exception e ) {
customHandlerError = true;
new ErrorManager().error( "Error In Initializing Custom Handler " +
customHandlerClassName, e, ErrorManager.GENERIC_FAILURE );
}
return customHandler;
|
private static synchronized java.util.logging.Handler | getDeploymentAuditHandler()This is a Singleton factory method to get an instance of
DeploymentLogHandler.
if( deploymentAuditHandler == null ) {
try {
deploymentAuditHandler = DeploymentAuditLogHandler.getInstance();
deploymentAuditHandler.setLevel(DeploymentAuditLogHandler.getConfiguredLevel());
} catch( Exception e ) {
new ErrorManager().error( "Exception caught in getHandler ",
e, ErrorManager.GENERIC_FAILURE );
}
}
return deploymentAuditHandler;
|
private static synchronized java.util.logging.Handler | getFileandSyslogHandler()This is a Singleton factory method to get and instance of
FileandSyslogHandler.
if( handlerSingleton == null ) {
try {
handlerSingleton = FileandSyslogHandler.getInstance();
handlerSingleton.setLevel( Level.ALL );
} catch( Exception e ) {
new ErrorManager().error( "Exception caught in getHandler ",
e, ErrorManager.GENERIC_FAILURE );
}
}
return handlerSingleton;
|
private static java.lang.Object | getInstance(java.lang.String className)A Utility method to instantiate Custom Log Handler and Log Filter.
if( className == null ) return null;
return java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
try {
ClassLoader cl =
Thread.currentThread().getContextClassLoader();
if (cl == null)
cl = ClassLoader.getSystemClassLoader();
return Class.forName( className, true,cl).newInstance();
} catch( Exception e ) {
new ErrorManager().error(
"Error In Instantiating Class " + className, e,
ErrorManager.GENERIC_FAILURE );
}
return null;
}
}
);
|
public static synchronized com.sun.enterprise.server.logging.ServerLogManager | getInstance()
if ( thisInstance == null ) {
thisInstance = new ServerLogManager();
}
return thisInstance;
|
static com.sun.enterprise.config.serverbeans.LogService | getLogService()A Utility method to get the LogService Configuration element.
try {
ServerContext sc = ApplicationServer.getServerContext();
if( sc == null ) {
return null;
}
return ServerBeansFactory.getConfigBean(
sc.getConfigContext()).getLogService( );
} catch( Exception e ) {
new ErrorManager().error( "Error In getLogService ", e,
ErrorManager.GENERIC_FAILURE );
}
return null;
|
private static synchronized java.util.logging.Handler | getSyslogHandler()
if( syslogLibraryLoadError ) return null;
if( syslogHandler == null ) {
try {
syslogHandler = new SystemLogHandler();
syslogHandler.setLevel(Level.ALL);
syslogHandler.setFormatter(new UniformLogFormatter());
} catch( Exception e ) {
syslogLibraryLoadError = true;
// WE WILL EAT AWAY THE EXCEPTION, IF SOME ONE TURNS ON SYSLOG
// ON WINDOWS or LINUX, They will not see any error.
}
}
return syslogHandler;
|
protected void | initializeLogger(java.util.logging.Logger logger)When a new logger is created in the system, this method will be invoked
to intialize the log level appropriately and also to set the required
LogHandlers.
synchronized(lockObj) {
internalInitializeLogger( logger );
if( getLogService() == null ) {
listOfUnInitializedLoggers.add( logger );
}
}
|
public static void | initializeServerLogger(java.util.logging.Logger logger)_REVISIT_: Talk to JDO team to see if we can nuke this method and
rely on the generic framework for the Logger initialization..
|
private void | internalInitializeLogger(java.util.logging.Logger logger)Internal Method to initialize a list of unitialized loggers.
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
// Explicitly remove all handlers.
Handler[] h = logger.getHandlers();
for (int i = 0; i < h.length; i++) {
logger.removeHandler(h[i]);
}
if (logger.getName().equals(LogDomains.DPLAUDIT_LOGGER)) {
// redirect to deployment audit log
logger.addHandler(getDeploymentAuditHandler());
logger.setUseParentHandlers(false);
}
if( logger.getName().intern() == "".intern() ) {
logger.addHandler(getFileandSyslogHandler() );
if ( logToStderr() ) {
logger.addHandler(getConsoleHandler());
}
if( logToSyslog() ) {
Handler syslogHandler = getSyslogHandler();
if( syslogHandler != null ) {
logger.addHandler( syslogHandler );
}
}
logger.setUseParentHandlers( false );
}
Level logLevel = getConfiguredLogLevel(logger.getName());
if( logLevel != null ) {
logger.setLevel( logLevel );
}
postInitializeLogger( logger );
return null;
}
}
);
|
private static boolean | logToStderr()
try {
// Check if server was started with "asadmin start-domain --verbose"
// This system property is set in PELaunchFilter.
if ( verboseMode == null ) {
verboseMode = Boolean.FALSE;
String verbose = System.getProperty("com.sun.aas.verboseMode");
if ( verbose != null && verbose.equals("true") ) {
verboseMode = Boolean.TRUE;
}
}
if ( verboseMode.booleanValue() == true ) {
return true;
}
// check if log-console / echo-log-messages-to-stderr is true
ServerContext sc = ApplicationServer.getServerContext();
if (sc == null) {
// This can happen before ApplicationServer.onInitialization()
// has been called.
return false;
}
Config cfg =
ServerBeansFactory.getConfigBean(sc.getConfigContext());
return cfg.getLogService().isLogToConsole();
} catch ( Exception ex ) {
new ErrorManager().error(
"Error while geting echo-log-messages-to-stderr attribute of " +
" log-service ", ex, ErrorManager.GENERIC_FAILURE );
return false;
}
|
private static boolean | logToSyslog()
boolean sunOS =
System.getProperty( OS_NAME_PROPERTY ).equals( SUN_OS );
boolean linuxOS =
System.getProperty( OS_NAME_PROPERTY ).equals( LINUX_OS );
// If it is not SUN OS, then logToSyslog should return false
if( !sunOS && !linuxOS ) {
return false;
}
if( syslogLibraryLoadError )
return false;
LogService logService = getLogService( );
if( logService != null ) {
return logService.isUseSystemLogging( );
}
return false;
|
private void | postInitializeLogger(java.util.logging.Logger logger)This is where we plug in any custom Log Handler and Log Filter.
final Handler customHandler = getCustomHandler( );
final Filter customFilter = getCustomFilter( );
if( ( customHandler == null)
&&( customFilter == null ) ) {
return;
}
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
if( customHandler != null ) {
logger.addHandler( customHandler );
}
if( customFilter != null ) {
logger.setFilter( customFilter );
}
return null;
}
}
);
|
public static void | reInitializeServerLoggers()Here's an oppurtunity to reInitialize the Loggers, if they are
initialized before the admin service started.
try {
FileandSyslogHandler handler=
(FileandSyslogHandler)getFileandSyslogHandler();
// If there is a file name specified by the administrator for
// Log File, then here's a first oppurtunity to change the
// file name because the Log Handles may have been initialized
// before the configuration data is completely read.
handler.changeFileName( getLogService().getFile() );
Long rotationTimeLimitValue = new Long(
getLogService().getLogRotationTimelimitInMinutes().trim() );
if( rotationTimeLimitValue.longValue( ) != 0 ) {
// If there is a value specified for the rotation based on
// time we set that first, if not then we will fall back to
// size based rotation
LogRotationTimer.getInstance().startTimer(
new LogRotationTimerTask(
rotationTimeLimitValue.longValue( ) ) );
// Disable the Size Based Rotation if the Time Based
// Rotation is set.
handler.setLimitForRotation( 0 );
} else {
Integer rotationLimitAttrValue = new Integer(
getLogService().getLogRotationLimitInBytes().trim() );
// We set the LogRotation limit here. The rotation limit is the
// Threshold for the number of bytes in the log file after which
// it will be rotated.
handler.setLimitForRotation(
rotationLimitAttrValue.intValue() );
}
if( listOfUnInitializedLoggers.size() == 0 ) {
return;
}
Iterator listIterator = listOfUnInitializedLoggers.iterator( );
final ServerLogManager mgr = getInstance();
while( listIterator.hasNext( ) ) {
mgr.initializeLogger( (Logger) listIterator.next() );
}
} catch( Exception e ) {
new ErrorManager().error(
"Exception caught in reInitializeServerLoggers ",
e, ErrorManager.GENERIC_FAILURE );
}
|