|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.adventnet.afp.log.LogFactory
The Logging Framework is governed by the LogFactory. It manages the
LogWriters and
the Loggers. This class manages the printing of log out and log error
messages. The
LogFactory reads the initial configuration details from the LogConfigReader.
After
getting the details, it creates the Loggers and LogWriters. In the
LogFactory, the
Log writers and their corresponding Loggers are stored.
The LogFactory carries out a check for the Logger class name and LogWriter
class
name. If the class names are null, the default class names will be taken.
The Loggers
and LogWriters are created only at the time of logging. Loggers
in turn create
LogWriters. The LogFactory facilitates adding LogWriters and Loggers
at runtime.
If you want the runtime addition of the LogWriters and Loggers
to be included in
the configuration itself, then it can also be done. Loggers and LogWriters
can be
removed at Runtime. These changes can also be included in the configuration,
if you
so wish through the LogConfigWriter.
Getting Started |
This section explains how you can start working with the Logging Framework.
The following code snippet explains the procedure in detail. For ease of
reference, explanation has been provided alongside the code snippet itself.
/**
* An example file which explains how to start with Logging framework and how to log the messages to a log file with the default implementation. The default Configuration reader is the LogConfigFileReader which reads the details from the file as properties. Add the following xml tags in the configuration file logging.xml file. *<LOGGER>
|
//To create a Logger with instance name "TestLogger" public class Example
// Before initializing the LogFactory, configuration
details for Logging have to be read by the LogConfigReader from the destination
where the details are available. So, mention the destination.
// NOTE : Replace the parameters with the actual directory and fileName. LogConfigReader reader = new LogConfigFileReader("G:/log/logging.xml");
//To get the Instance of the LogFactory
//To initialize the LogFactory.
//Get the Logger instance of the example Logger
. Only after this, the Logger will be created.
//To set the LogLevel of the Logger to some desired
value.
// Log some messages with a level less than the
Logger's level. The message will be displayed in the following format <TimeStamp>:<DisplayName>:<Message>.
Here, in this example, the displayName will be "MyLogger"
// Here the InstanceName of Logger is 'SERVEROUT'. So, the log messages will be displayed in the Writer which has the same InstanceName. (i.e)'SERVEROUT'. logger.out("This
is message with number : " + i, LogLevel.LEVEL1);
}
// To disable the logging and then to log some
messages
// Since Logging is disabled, the following messages will not be logged in the respective Writer. for (int i = 100; i < 200; i++) {
}
} |
Method Summary | |
Logger |
createLogger(LoggerProperties loggerProps,
boolean updateInConfFile)
The createLogger method is used to add a Logger. |
LogWriter |
createLogWriter(LogWriterProperties logWriterProps,
boolean updateInConfFile)
The method createLogWriters is used to create a new LogWriter. |
static LogFactory |
getInstance()
Used to get the reference of LogFactory. |
Logger |
getLogger(java.lang.String loggerInstanceName)
The getLogger method is used to get the instance of the Logger specified by loggerInstanceName. |
java.util.Hashtable |
getLoggers()
This method is used to get the instances of all the Loggers that are created for performing the Logging operation. |
LogWriter |
getLogWriter(java.lang.String logWriterInstanceName)
Gives instance of the LogWriter which has the logWriterInstanceName. |
java.util.Hashtable |
getLogWriters()
This method is used to get the instance of all the LogWriters that are created for performing the Logging operation. |
void |
init(LogConfigReader reader,
LogConfigWriter writer)
|
void |
removeLogger(java.lang.String loggerInstanceName,
boolean updateInConfFile)
The removeLogger method is used to remove a Logger from the Logfactory. |
void |
removeLogWriter(java.lang.String logWriterInstanceName,
boolean updateInConfFile)
The removeLogWriter method is used to remove a LogWriter. |
void |
stop()
Method for stopping Loggers. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public void init(LogConfigReader reader, LogConfigWriter writer) throws LogException
public static LogFactory getInstance()
public void stop() throws LogException
LogException
- if an error occurs in removing the Loggers or LogWriterspublic LogWriter createLogWriter(LogWriterProperties logWriterProps, boolean updateInConfFile) throws LogException
createLogWriters
is used to create a new LogWriter. The properties of the module
are specified in the LogWriter. The method returns true only if all the
Loggers in the module are created properly. False will be returned if LogWriter could not be created.logWriterProps
- specifies the properties of the LogWriter
and Loggers.updateInConfFile
- denotes whether the properties of the newly added LogWriter
and its Loggers are to be writen to the logging configuration file.LogException
- if an error occurs during the creation of a Logger/LogWriter or while
processing the XML file.public void removeLogWriter(java.lang.String logWriterInstanceName, boolean updateInConfFile) throws LogException
removeLogWriter
method is used to remove a LogWriter.
This method can be called when the LogWriter and all the Loggers asscociated with
it are no longer needed. On calling this method, the contents will be flushed and
all the Loggers that used the LogWriter will be removed.logWriterInstanceName
- a String
value denoting the LogWriter to be removedupdateInConfFile
- a boolean
value denoting if the change has to be done in the conf file.LogException
- if an error occurs during the removal of a LogWriter or during
processing of Conf file.public Logger createLogger(LoggerProperties loggerProps, boolean updateInConfFile) throws LogException
createLogger
method is used to add a Logger. The Logger will be created
only if there are no other Loggers with the same LoggerInstanceName. Otherwise, LogException
will be thrown.loggerProps
- specifies the properties for the LoggerupdateInConfFile
- a boolean
value denoting whether the newly created Logger has to
be written to the logging configuration file.LogException
- if an error occurs during the creation of the Loggerpublic void removeLogger(java.lang.String loggerInstanceName, boolean updateInConfFile) throws LogException
removeLogger
method is used to remove a Logger from the Logfactory.
This can be called when the Logger is no longer needed. On calling this method,
the contents of the LogWriter of that Logger will be flushed and then the
Logger will be destroyed.loggerInstanceName
- a String
value denoting the Logger to be removedupdateInConfFile
- a boolean
value denoting if the change has to be updated in the conf fileLogException
- if an error occurs while removing the Logger or updating the conf file.public LogWriter getLogWriter(java.lang.String logWriterInstanceName) throws LogException
logWriterInstanceName
- Key for which log file writer is to be returnedpublic Logger getLogger(java.lang.String loggerInstanceName) throws LogException
getLogger
method is used to get the instance of the Logger specified by loggerInstanceName.
It will check whether the Logger with this instance name is already created. if the logger is not
created, it will check whether the corresponding writer is created. If the writer is not created, it
will create the Writer and then Logger is created. After creating the Logger and corresponding writer,
it returns the instance of the Logger. The Logger instance can be used
for changing the Logger's attributes at runtime.loggerInstanceName
- a String
value denoting the Logger's unique InstanceNameLogger
instance.public java.util.Hashtable getLoggers()
Hashtable
containing the instance of all the Loggers with their
LoggerInstanceName as key.public java.util.Hashtable getLogWriters()
Hashtable
with the LogWriter instance with key as
LogWriterInstanceName
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |