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:
0
for none (default)1
for ERRORS messages2
for ERRORS and WARNINGS3
for ERRORS, WARNING, and DEBUG messages
Infranet.log.log_name.enable
Enables or disables logging to this log. To disable logging, set to "f", "n", or zero.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Specifies logging by flag.static final int
Specifies logging by priority.protected static SimpleDateFormat
static final String
Specifies a newline character, used in the log file.static final int
Specifies no control styles on logging.static final int
Specifies all flags for flag style logging.static final int
Specifies no flags for flag style logging.static final int
Specifies the highest priority for priority style logging.static final int
static final int
static final int
Specifies the lowest priority for priority style logging. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the log.protected String
controlToString
(int control) boolean
doLog
(int control) Evaluates the control level to determine whether a log call will result in a log entry.int
Retrieves the message priority level or flag, depending on the logging control style.int
Retrieves theLog
control style type that specifies whether logging is controlled by priority or by flag.getLog()
Retrieves theLog
as anInputStream
.protected String
getMessageHeader
(String src, int control) getName()
Retrieves the name of the application doing the logging.boolean
Determines if the message logged is stored in memory rather than on disk.void
Logs information to the log file.void
Logs information to the log file.void
Logs a message to the log file along with a hex dump of the array of bytes.void
Logs a message to the log file along with a hex dump of the array of bytes.void
Logs the error message retrieved from theThrowable
object thrown by an error.protected void
openLog()
void
setControlState
(int state) Sets theLog
priority level or flag, depending on the logging control style specified in thesetControlStyle
method.void
setControlStyle
(int control) Sets theLog
control style that specifies whether logging is controlled by priority or by flag.void
setInMemoryFlagValue
(int logvalue) Sets theLog
inmemorylogvalue Value 0 indicates no in memory logging is not selected any other value indicates in memory logging is selectedvoid
setInMemoryLogSize
(long logsize) Sets theLog
inmemorylogsizevoid
Sets the applicationLog
name.void
void
void
Sets the log file path name.void
Set 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 ofLog
from 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 ofLog
from 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 applicationLog
name.- 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 theLog
control 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 theLog
priority level or flag, depending on the logging control style specified in thesetControlStyle
method.- Parameters:
state
- The priority level or flag.
-
setInMemoryFlagValue
public void setInMemoryFlagValue(int logvalue) Sets theLog
inmemorylogvalue 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 theLog
inmemorylogsize- Parameters:
logsize
- The in memory log size.
-
getControlStyle
public int getControlStyle()Retrieves theLog
control 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 theLog
method.- Returns:
true
if 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 theThrowable
object thrown by an error.- Parameters:
src
- The location of the error. For example, a file name and a line number. Ifsrc
is 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. Ifsrc
is 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. Ifsrc
is 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 ofbuf
bytes 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. IfsrcOb
is 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:
true
if the log is in memory.
-
getLog
Retrieves theLog
as anInputStream
.- Returns:
- An
InputStream
of theLog
object. - Throws:
IOException
- thrown if InputStream cannot be created.
-
openLog
protected void openLog()
-