|
soap tutorial | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectadriani.jws.template.util.SystemLogger
public class SystemLogger
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.
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 |
---|
protected java.lang.String loggerPath
protected java.util.logging.Level level
Level.INFO
).
protected RotateThread rotateThread
protected boolean mode
true
this object handles the standard logger, if false
it refers to
the benchmark logger.
protected java.lang.String parentDir
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.
protected java.lang.String leadingName
Constructor Detail |
---|
public SystemLogger()
Method Detail |
---|
public void init(java.lang.String path, java.lang.String logLevel, int rotate, boolean mode)
Logger
object.path
will create
the logger file in the default directory (stored in the parentDir
class field).parentDir
directory,
instead the log folder is created some levels above this directory, using the climbPath()
method.RotateThread
class.
init
in interface LoggerManager
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 filemode
- if true
initializes the standard log file, if false
initializes the
benchmark analysis fileclimbPath(String path, int levels)
public void createLogger(java.lang.String path, java.util.logging.Level level, boolean mode)
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.init()
method.
createLogger
in interface LoggerManager
path
- the MANDATORY path reference for the log filelevel
- 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 filegetLogFile(String optionalPath, boolean mode)
public void rotate()
Handler
used by the default Logger
and creates a new one.
This method is called periodically by the RotateThread
.
rotate
in interface LoggerManager
RotateThread
public boolean close()
SystemLogger
class.
close
in interface LoggerManager
public java.lang.String getParentDir(java.lang.Object logger)
parentDir
path used as base directory to locate the log file.
getParentDir
in interface LoggerManager
logger
- should be null
, since is not necessary any logger instance
public RotateThread getRotateThread()
RotateThread
object used to rotate the log file.
getRotateThread
in interface LoggerManager
RotateThread
objectpublic java.lang.String getRotationTime(java.lang.Object logger)
getRotationTime
in interface LoggerManager
logger
- should be null
, since is not necessary any logger instance
protected java.lang.String getLogFile(java.lang.String optionalPath, boolean mode)
optionalPath
. In current implementation
the optionalPath
is stored in the loggerPath
class field.
optionalPath
- the path that should be specified manually in the configuration filemode
- if true
provides the standard log file, if false
provides the
"Performances Analysis" file
protected java.lang.String getFileName(java.util.GregorianCalendar calendar, boolean mode, java.lang.String ext)
calendar
- a valid GregorianCalendar
instancemode
- if true
produces the name of standard log file, if false
produces
the name for the "Performances Analysis" fileext
- the extension to be used for the log file
d11_h10_m30.txt
protected java.lang.String getLocationPath()
/C:/Develop/webapps/test/WEB-INF/classes/webapp/util
protected java.lang.String getResourcePath()
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:C:\Programs\apache-tomcat-6.0.18\webapps\test\WEB-INF
./home/apache-tomcat-6.0.18/webapps/test/WEB-INF
.getLocationPath
should be used instead.
getResource()
methodgetLocationPath()
protected java.lang.String climbPath(java.lang.String path, int levels)
path
directory and climbing
the specified number of levels./home/apache/webapps/test/WEB-INF
and levels
equals 3, this method returns /home/apache
.
path
- the starting path, referring to a directory (not a file)levels
- the number of levels to climb on the file system tree
protected java.lang.String parseExtension(java.lang.String path)
getLocationPath()
or
getResourcePath()
will contain the full name of the package, for example:/C:/Develop/webapps/test/WEB-INF/classes/myservice.aar!
'/'
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.
path
- the input path as obtained by the getLocationPath()
method
getLocationPath()
,
hasExtension(String path)
protected boolean hasExtension(java.lang.String path)
Settings
class: if the path matches one of these extensions the method return true
.
path
- the input path as obtained by the getLocationPath()
method
true
if the path refers to a JAR, EAR or AAR archivegetLocationPath()
,
parseExtension(String path)
|
Build 18/09/2012 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |