soap tutorial

adriani.jws.template.util
Class SystemLogger

java.lang.Object
  extended by adriani.jws.template.util.SystemLogger
All Implemented Interfaces:
LoggerManager

public class SystemLogger
extends java.lang.Object
implements LoggerManager

This class creates an unique Java Logger object shared by the whole application. This object is created within a static code block in the ServiceLogic, in this way we create only one logger no matters how many children of ServiceLogic are used in the project.

This Logger writes directly on the file system. By default the logs files will be produced into the logs folder in the parentDir directory, which is usually the path where the Virtual Machine in launched. If this class is created by a webapp within the Apache-Tomcat server, the parentDir should be the TOMCAT_HOME directory itself. If the class is used within a web service using Axis2, then the parentDir should be work\Catalina\localhost\axis2\_axis2.
For this reason is strongly recommended to specify a custom log path when calling the init() method.

See Also:
Settings.LOGDIR

Field Summary
protected  java.lang.String leadingName
          Beginning of each logging message produced by this class.
protected  java.util.logging.Level level
          The threshold logging level (default is Level.INFO).
protected  java.lang.String loggerPath
          The absolute log path retrieved from the configuration file.
protected  boolean mode
          If true this object handles the standard logger, if false it refers to the benchmark logger.
protected  java.lang.String parentDir
          Used only when the loggerPath is not specified and the logging path must be generated automatically by this class.
protected  RotateThread rotateThread
          The thread class responsible for rotation of the log file.
 
Constructor Summary
SystemLogger()
           
 
Method Summary
protected  java.lang.String climbPath(java.lang.String path, int levels)
          Goes up in the directory tree, starting from the input path directory and climbing the specified number of levels.
 boolean close()
          Close the logger by closing all related handlers.
 void createLogger(java.lang.String path, java.util.logging.Level level, boolean mode)
          This method is called within the init() method to create the Logger and the related StreamHandler objects.
protected  java.lang.String getFileName(java.util.GregorianCalendar calendar, boolean mode, java.lang.String ext)
          Produce the file name (without the path) for the log file.
protected  java.lang.String getLocationPath()
          Return the file path describing location of this class, using a platform independent syntax.
protected  java.lang.String getLogFile(java.lang.String optionalPath, boolean mode)
          Produce the complete qualified name (path and file name) for the log file.
 java.lang.String getParentDir(java.lang.Object logger)
          Return the parentDir path used as base directory to locate the log file.
protected  java.lang.String getResourcePath()
          Return the file path describing location of this class, considering the class itself as a project resource, using mypackage.MyClass.class.getResource().
 RotateThread getRotateThread()
          Return the RotateThread object used to rotate the log file.
 java.lang.String getRotationTime(java.lang.Object logger)
          Return the rotation time set for this logger, already formatted and ready to print.
protected  boolean hasExtension(java.lang.String path)
          Check if a given path refers to a JAR, EAR or AAR archive.
 void init(java.lang.String path, java.lang.String logLevel, int rotate, boolean mode)
          This method should be called when initializing the application, webapp or service, in order to create and configure the proper Logger object.
protected  java.lang.String parseExtension(java.lang.String path)
          If the class is running inside a JAR, EAR or AAR the path returned by getLocationPath() or getResourcePath() will contain the full name of the package, for example:

/C:/Develop/webapps/test/WEB-INF/classes/myservice.aar!
 void rotate()
          Discards the old Handler used by the default Logger and creates a new one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

loggerPath

protected java.lang.String loggerPath
The absolute log path retrieved from the configuration file.


level

protected java.util.logging.Level level
The threshold logging level (default is Level.INFO).


rotateThread

protected RotateThread rotateThread
The thread class responsible for rotation of the log file.


mode

protected boolean mode
If true this object handles the standard logger, if false it refers to the benchmark logger.


parentDir

protected java.lang.String parentDir
Used only when the loggerPath is not specified and the logging path must be generated automatically by this class. This value is stored as class field to ease test or debug of the path generation mechanism.


leadingName

protected java.lang.String leadingName
Beginning of each logging message produced by this class.

Constructor Detail

SystemLogger

public SystemLogger()
Method Detail

init

public void init(java.lang.String path,
                 java.lang.String logLevel,
                 int rotate,
                 boolean mode)
This method should be called when initializing the application, webapp or service, in order to create and configure the proper Logger object.

Input parameters are not mandatory. Calling this method passing a null path will create the logger file in the default directory (stored in the parentDir class field).
This method does not create the log folder abruptly in the parentDir directory, instead the log folder is created some levels above this directory, using the climbPath() method.

This method takes also care to create and run the thread used by RotateThread class.

Specified by:
init in interface LoggerManager
Parameters:
path - an ALREADY existing path from which logging folders must be created, in the form C:\\Project\\Temp (Windows) or /home/temp (Unix)
logLevel - the logging minimal level as a String (INFO, WARNING or SEVERE)
rotate - the timeout (in minutes) for rotation of the log file
mode - if true initializes the standard log file, if false initializes the benchmark analysis file
See Also:
climbPath(String path, int levels)

createLogger

public void createLogger(java.lang.String path,
                         java.util.logging.Level level,
                         boolean mode)
This method is called within the init() method to create the Logger and the related StreamHandler objects. Before calling this method, the code within the init() method must produce a proper path for the log file, for example using the getLogFile() method.
Notice that this method could be private or protected, since usually is used only internally. We choose to define it public to allow a more flexible way to write the code that will call the init() method.

Specified by:
createLogger in interface LoggerManager
Parameters:
path - the MANDATORY path reference for the log file
level - the logging minimal level as a Logger.Level value (INFO, WARNING or SEVERE)
mode - if true creates the standard log file, if false creates the benchmark analysis file
See Also:
getLogFile(String optionalPath, boolean mode)

rotate

public void rotate()
Discards the old Handler used by the default Logger and creates a new one. This method is called periodically by the RotateThread.

Specified by:
rotate in interface LoggerManager
See Also:
RotateThread

close

public boolean close()
Close the logger by closing all related handlers. The rotation thread will execute just another cycle, then will exit. This method should be required only by the SystemLogger class.

Specified by:
close in interface LoggerManager

getParentDir

public java.lang.String getParentDir(java.lang.Object logger)
Return the parentDir path used as base directory to locate the log file.

Specified by:
getParentDir in interface LoggerManager
Parameters:
logger - should be null, since is not necessary any logger instance
Returns:
the automatically generated parent directory for the logger

getRotateThread

public RotateThread getRotateThread()
Return the RotateThread object used to rotate the log file.

Specified by:
getRotateThread in interface LoggerManager
Returns:
a reference to the RotateThread object

getRotationTime

public java.lang.String getRotationTime(java.lang.Object logger)
Return the rotation time set for this logger, already formatted and ready to print.

Specified by:
getRotationTime in interface LoggerManager
Parameters:
logger - should be null, since is not necessary any logger instance
Returns:
a string describing the rotation time set for this logger

getLogFile

protected java.lang.String getLogFile(java.lang.String optionalPath,
                                      boolean mode)
Produce the complete qualified name (path and file name) for the log file. If the directories structure does not exist the method creates also the required sub-directories. The logging file path should be set manually specifying a valid path with the parameter optionalPath. In current implementation the optionalPath is stored in the loggerPath class field.

Parameters:
optionalPath - the path that should be specified manually in the configuration file
mode - if true provides the standard log file, if false provides the "Performances Analysis" file
Returns:
the produced complete path of the log file

getFileName

protected java.lang.String getFileName(java.util.GregorianCalendar calendar,
                                       boolean mode,
                                       java.lang.String ext)
Produce the file name (without the path) for the log file.

Parameters:
calendar - a valid GregorianCalendar instance
mode - if true produces the name of standard log file, if false produces the name for the "Performances Analysis" file
ext - the extension to be used for the log file
Returns:
the log file name, for example: d11_h10_m30.txt

getLocationPath

protected java.lang.String getLocationPath()
Return the file path describing location of this class, using a platform independent syntax.

Returns:
a path of the type /C:/Develop/webapps/test/WEB-INF/classes/webapp/util

getResourcePath

protected java.lang.String getResourcePath()
Return the file path describing location of this class, considering the class itself as a project resource, using mypackage.MyClass.class.getResource(). The returned path can be absolute or relative, depending by the runtime platform. Furthermore, the file separator char used to produce the path depends by the runtime platform. For example:

Result on Windows: C:\Programs\apache-tomcat-6.0.18\webapps\test\WEB-INF.
Result on Unix: /home/apache-tomcat-6.0.18/webapps/test/WEB-INF.

For this reason when the cross-platform feature is a crucial issue, the method getLocationPath should be used instead.

Returns:
the path as obtained by the getResource() method
See Also:
getLocationPath()

climbPath

protected java.lang.String climbPath(java.lang.String path,
                                     int levels)
Goes up in the directory tree, starting from the input path directory and climbing the specified number of levels.
For example, if the startin path is /home/apache/webapps/test/WEB-INF and levels equals 3, this method returns /home/apache.

Parameters:
path - the starting path, referring to a directory (not a file)
levels - the number of levels to climb on the file system tree
Returns:
the new path (after climbing)

parseExtension

protected java.lang.String parseExtension(java.lang.String path)
If the class is running inside a JAR, EAR or AAR the path returned by getLocationPath() or getResourcePath() will contain the full name of the package, for example:

/C:/Develop/webapps/test/WEB-INF/classes/myservice.aar!

This method looks for the last '/' character in the input path and checks if this path ends with an archive extension of the type JAR, EAR or AAR. If this is the case, the archive element is removed from the path.

Parameters:
path - the input path as obtained by the getLocationPath() method
Returns:
the input path unchanged OR the input path without the archive element
See Also:
getLocationPath(), hasExtension(String path)

hasExtension

protected boolean hasExtension(java.lang.String path)
Check if a given path refers to a JAR, EAR or AAR archive.
This method compares the last path string element with the extensions specified in the Settings class: if the path matches one of these extensions the method return true.

Parameters:
path - the input path as obtained by the getLocationPath() method
Returns:
true if the path refers to a JAR, EAR or AAR archive
See Also:
getLocationPath(), parseExtension(String path)

Build 19/03/2014

Morpheus Technologies - making the Zion software
Copyright © 2009-2014 Morpheus Technologies. All Rights Reserved