Class Log
- Direct Known Subclasses:
ErrorLog
There are two types of logging styles: by priority and by flag. Each type has a choice
of control levels that determine which messages are logged. You configure
logging by setting the log entries in the Infranet.properties file.
Logging by priority:
In priority style, you assign each message a priority level. All messages with a priority level lower than the log control level are logged. (A lower number equals a higher priority.) If the priority control level is not configured, all messages are logged.
Logging by flag:
In flag style, each message is tagged with a flag that specifies the error message
type. Possible flag values are defined in ErrorLog.
You specify which flags will result in a message being logged in the
Infranet.properties file.
Configuring the Infranet.properties file:
Infranet.properties file.
Log entries consist of:
Infranet.log.log_name.file: Full path to the log file for the application. To log messages, you must set the log path.Infranet.log.log_name.name: The name of the log to write to.Infranet.log.log_name.style: Specifies the logging control style. The values for this entry can be:- priority: Logs messages according to their priority level, specified by the .level entry.
- flag: Logs messages according to their type, specified by the .level entry.
Infranet.log.log_name.level: Specifies how much information the application should log. Possible values depend on the log control style specified by the .style entry. Values for this entry can be:- For control by priority style, use a decimal value.
- For control by flag style, values can be:
0for none (default)1for ERRORS messages2for ERRORS and WARNINGS3for ERRORS, WARNING, and DEBUG messages
Infranet.log.log_name.enableEnables or disables logging to this log. To disable logging, set to "f", "n", or zero.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intSpecifies logging by flag.static final intSpecifies logging by priority.protected static SimpleDateFormatstatic final StringSpecifies a newline character, used in the log file.static final intSpecifies no control styles on logging.static final intSpecifies all flags for flag style logging.static final intSpecifies no flags for flag style logging.static final intSpecifies the highest priority for priority style logging.static final intstatic final intstatic final intSpecifies the lowest priority for priority style logging. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the log.protected StringcontrolToString(int control) booleandoLog(int control) Evaluates the control level to determine whether a log call will result in a log entry.intRetrieves the message priority level or flag, depending on the logging control style.intRetrieves theLogcontrol style type that specifies whether logging is controlled by priority or by flag.getLog()Retrieves theLogas anInputStream.protected StringgetMessageHeader(String src, int control) getName()Retrieves the name of the application doing the logging.booleanDetermines if the message logged is stored in memory rather than on disk.voidLogs information to the log file.voidLogs information to the log file.voidLogs a message to the log file along with a hex dump of the array of bytes.voidLogs a message to the log file along with a hex dump of the array of bytes.voidLogs the error message retrieved from theThrowableobject thrown by an error.protected voidopenLog()voidsetControlState(int state) Sets theLogpriority level or flag, depending on the logging control style specified in thesetControlStylemethod.voidsetControlStyle(int control) Sets theLogcontrol style that specifies whether logging is controlled by priority or by flag.voidsetInMemoryFlagValue(int logvalue) Sets theLoginmemorylogvalue Value 0 indicates no in memory logging is not selected any other value indicates in memory logging is selectedvoidsetInMemoryLogSize(long logsize) Sets theLoginmemorylogsizevoidSets the applicationLogname.voidvoidvoidSets the log file path name.voidSet log writer
-
Field Details
-
NO_LOG_CONTROL
public static final int NO_LOG_CONTROLSpecifies no control styles on logging. This logs no messages.- See Also:
-
CONTROL_BY_PRIORITY
public static final int CONTROL_BY_PRIORITYSpecifies logging by priority.- See Also:
-
CONTROL_BY_FLAG
public static final int CONTROL_BY_FLAGSpecifies logging by flag.- See Also:
-
STATE_FLAG_NONE
public static final int STATE_FLAG_NONESpecifies no flags for flag style logging. This logs no messages.- See Also:
-
STATE_FLAG_ALL
public static final int STATE_FLAG_ALLSpecifies all flags for flag style logging. This logs all messages.- See Also:
-
STATE_PRIORITY_LOG_NONE
public static final int STATE_PRIORITY_LOG_NONE- See Also:
-
STATE_PRIORITY_LOG_ALL
public static final int STATE_PRIORITY_LOG_ALL- See Also:
-
STATE_PRIORITY_HIGHEST
public static final int STATE_PRIORITY_HIGHESTSpecifies the highest priority for priority style logging.- See Also:
-
STATE_PRIORITY_LOWEST
public static final int STATE_PRIORITY_LOWESTSpecifies the lowest priority for priority style logging.- See Also:
-
NEWLINE
Specifies a newline character, used in the log file. -
m_sdf
-
-
Constructor Details
-
Log
public Log()Constructs an instance ofLog. The default file name is "JavaLog" and the default path is "javapcm.log". The default is to log no messages. -
Log
Constructs an instance ofLogfrom a given path, application name, and logging flags.- Parameters:
path- The path for the log file.name- The name of the application doing the logging.control- The logging control style. Valid control values are CONTROL_BY_PRIORITY and CONTROL_BY_FLAG.state- The priority level or flag, depending on the control style.
-
Log
Constructs an instance ofLogfrom a path. The default file name is "JavaLog". The default is to log no messages.- Parameters:
path- The path for the log file.
-
-
Method Details
-
setName
Sets the applicationLogname.- Parameters:
name- The name of the application doing the logging.
-
setPath
Sets the log file path name.- Parameters:
path- The new log path.
-
setWriter
Set log writer- Parameters:
writer- The writer for log.
-
setControlStyle
public void setControlStyle(int control) Sets theLogcontrol style that specifies whether logging is controlled by priority or by flag.- Parameters:
control- The control style. Valid values are CONTROL_BY_PRIORITY and CONTROL_BY_FLAG.
-
setControlState
public void setControlState(int state) Sets theLogpriority level or flag, depending on the logging control style specified in thesetControlStylemethod.- Parameters:
state- The priority level or flag.
-
setInMemoryFlagValue
public void setInMemoryFlagValue(int logvalue) Sets theLoginmemorylogvalue Value 0 indicates no in memory logging is not selected any other value indicates in memory logging is selected- Parameters:
logvalue- The in memory log value.
-
setInMemoryLogSize
public void setInMemoryLogSize(long logsize) Sets theLoginmemorylogsize- Parameters:
logsize- The in memory log size.
-
getControlStyle
public int getControlStyle()Retrieves theLogcontrol style type that specifies whether logging is controlled by priority or by flag.- Returns:
- The control style.
-
getControlState
public int getControlState()Retrieves the message priority level or flag, depending on the logging control style.- Returns:
- The level or flag.
-
getName
Retrieves the name of the application doing the logging.- Returns:
- The application name.
-
setNames
-
setNames
-
doLog
public boolean doLog(int control) Evaluates the control level to determine whether a log call will result in a log entry.- Parameters:
control- The priority level or flag (depending on logging control style) that is passed to theLogmethod.- Returns:
trueif the specified control level permits writing to the log file.
-
log
Logs information to the log file.- Parameters:
control- The priority level or flag, depending on logging control style.message- The message to log.- Throws:
IOException- is thrown if there is an error writing to the log file.
-
log
Logs the error message retrieved from theThrowableobject thrown by an error.- Parameters:
src- The location of the error. For example, a file name and a line number. Ifsrcis a string, it is used to describe the source. Otherwise, the name of the object class is used.control- The priority level or flag, depending on logging control style.thrown- The thrown error or exception to log.- Throws:
IOException- is thrown if there is an error writing to the log file.
-
log
Logs a message to the log file along with a hex dump of the array of bytes.- Parameters:
src- The location of the error. For example, a file name and a line number. Ifsrcis a string, it is used to describe the source. Otherwise, the name of the object class is used.control- The priority level or flag, depending on logging control style.message- The message to log.buf- The array of bytes to append to the message.- Throws:
IOException- is thrown if there is an error writing to the log file.
-
log
public void log(Object src, int control, String message, byte[] buf, int off, int len) throws IOException Logs a message to the log file along with a hex dump of the array of bytes.- Parameters:
src- An The location of the error. For example, a file name and a line number. Ifsrcis a string, it is used to describe the source. Otherwise, the name of the object class is used.control- The priority level or flag, depending on logging control style.message- The message to log.buf- The array of bytes to append to the message.off- Offset into the buffer; the position at which to start the hex dump.len- Number ofbufbytes to log.- Throws:
IOException- is thrown if there is an error writing to the log file.
-
log
Logs information to the log file.- Parameters:
srcOb- The location of the error. For example, a file name and a line number. IfsrcObis a string, it is used to describe the source. Otherwise, the name of the object class is used.control- The priority level or flag, depending on logging control style.message- The message to log.- Throws:
IOException- is thrown if there is an error writing to the log file.
-
getMessageHeader
-
controlToString
-
close
public void close()Closes the log. -
isLogInMemory
public boolean isLogInMemory()Determines if the message logged is stored in memory rather than on disk.- Returns:
trueif the log is in memory.
-
getLog
Retrieves theLogas anInputStream.- Returns:
- An
InputStreamof theLogobject. - Throws:
IOException- thrown if InputStream cannot be created.
-
openLog
protected void openLog()
-