public class Log extends Object
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:
You must configure each log you use in the 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:
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:
0
for none (default)1
for ERRORS messages2
for ERRORS and WARNINGS3
for ERRORS, WARNING, and DEBUG messagesInfranet.log.log_name.enable
Enables or disables
logging to this log. To disable logging, set to "f", "n", or zero.Modifier and Type | Field and Description |
---|---|
static int |
CONTROL_BY_FLAG
Specifies logging by flag.
|
static int |
CONTROL_BY_PRIORITY
Specifies logging by priority.
|
protected static SimpleDateFormat |
m_sdf |
static String |
NEWLINE
Specifies a newline character, used in the log file.
|
static int |
NO_LOG_CONTROL
Specifies no control styles on logging.
|
static int |
STATE_FLAG_ALL
Specifies all flags for flag style logging.
|
static int |
STATE_FLAG_NONE
Specifies no flags for flag style logging.
|
static int |
STATE_PRIORITY_HIGHEST
Specifies the highest priority for priority style logging.
|
static int |
STATE_PRIORITY_LOG_ALL |
static int |
STATE_PRIORITY_LOG_NONE |
static int |
STATE_PRIORITY_LOWEST
Specifies the lowest priority for priority style logging.
|
Constructor and Description |
---|
Log()
Constructs an instance of
Log . |
Log(String path)
Constructs an instance of
Log from a path. |
Log(String path,
String name,
int control,
int state)
Constructs an instance of
Log from a given path,
application name, and logging flags. |
Modifier and Type | Method and Description |
---|---|
void |
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 |
getControlState()
Retrieves the message priority level or flag, depending on the logging
control style.
|
int |
getControlStyle()
Retrieves the
Log control style type that specifies whether
logging is controlled by priority or by flag. |
InputStream |
getLog()
Retrieves the
Log as an InputStream . |
protected String |
getMessageHeader(String src,
int control) |
String |
getName()
Retrieves the name of the application doing the logging.
|
boolean |
isLogInMemory()
Determines if the message logged is stored in memory rather than on disk.
|
void |
log(int control,
String message)
Logs information to the log file.
|
void |
log(Object srcOb,
int control,
String message)
Logs information to the log file.
|
void |
log(Object src,
int control,
String message,
byte[] buf)
Logs a message to the log file along with a hex dump of the array of bytes.
|
void |
log(Object src,
int control,
String message,
byte[] buf,
int off,
int len)
Logs a message to the log file along with a hex dump of the array of bytes.
|
void |
log(Object src,
int control,
Throwable thrown)
Logs the error message retrieved from the
Throwable object thrown
by an error. |
protected void |
openLog() |
void |
setControlState(int state)
Sets the
Log priority level or flag, depending on the logging
control style specified in the setControlStyle method. |
void |
setControlStyle(int control)
Sets the
Log control style that specifies whether logging is controlled
by priority or by flag. |
void |
setInMemoryFlagValue(int logvalue)
Sets the
Log inmemorylogvalue
Value 0 indicates no in memory logging is not selected
any other value indicates in memory logging is selected |
void |
setInMemoryLogSize(long logsize)
Sets the
Log inmemorylogsize |
void |
setName(String name)
Sets the application
Log name. |
void |
setNames(int[] priorities,
String[] names) |
void |
setNames(String[] names) |
void |
setPath(String path)
Sets the log file path name.
|
void |
setWriter(Writer writer)
Set log writer
|
public static final int NO_LOG_CONTROL
public static final int CONTROL_BY_PRIORITY
public static final int CONTROL_BY_FLAG
public static final int STATE_FLAG_NONE
public static final int STATE_FLAG_ALL
public static final int STATE_PRIORITY_LOG_NONE
public static final int STATE_PRIORITY_LOG_ALL
public static final int STATE_PRIORITY_HIGHEST
public static final int STATE_PRIORITY_LOWEST
public static final String NEWLINE
protected static SimpleDateFormat m_sdf
public Log()
Log
. The default file name is "JavaLog" and
the default path is "javapcm.log". The default is to log no messages.public Log(String path, String name, int control, int state)
Log
from a given path,
application name, and logging flags.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.public Log(String path)
Log
from a path.
The default file name is "JavaLog". The default is to log no messages.path
- The path for the log file.public void setName(String name)
Log
name.name
- The name of the application doing the logging.public void setPath(String path)
path
- The new log path.public void setWriter(Writer writer)
writer
- The writer for log.public void setControlStyle(int control)
Log
control style that specifies whether logging is controlled
by priority or by flag.control
- The control style. Valid values are CONTROL_BY_PRIORITY and
CONTROL_BY_FLAG.public void setControlState(int state)
Log
priority level or flag, depending on the logging
control style specified in the setControlStyle
method.state
- The priority level or flag.public void setInMemoryFlagValue(int logvalue)
Log
inmemorylogvalue
Value 0 indicates no in memory logging is not selected
any other value indicates in memory logging is selectedlogvalue
- The in memory log value.public void setInMemoryLogSize(long logsize)
Log
inmemorylogsizelogsize
- The in memory log size.public int getControlStyle()
Log
control style type that specifies whether
logging is controlled by priority or by flag.public int getControlState()
public String getName()
public void setNames(String[] names)
public void setNames(int[] priorities, String[] names)
public boolean doLog(int control)
control
- The priority level or flag (depending on logging control style)
that is passed to the Log
method.true
if the specified control level permits writing to
the log file.public void log(int control, String message) throws IOException
control
- The priority level or flag, depending on logging control style.message
- The message to log.IOException
- is thrown if there is an error writing
to the log file.public void log(Object src, int control, Throwable thrown) throws IOException
Throwable
object thrown
by an error.src
- The location of the error. For example, a file name and
a line number. If src
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.IOException
- is thrown if there is an error writing
to the log file.public void log(Object src, int control, String message, byte[] buf) throws IOException
src
- The location of the error. For example, a file name and
a line number. If src
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.IOException
- is thrown if there is an error writing
to the log file.public void log(Object src, int control, String message, byte[] buf, int off, int len) throws IOException
src
- An The location of the error. For example, a file name and
a line number. If src
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 of buf
bytes to log.IOException
- is thrown if there is an error writing
to the log file.public void log(Object srcOb, int control, String message) throws IOException
srcOb
- The location of the error. For example, a file name and
a line number. If srcOb
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.IOException
- is thrown if there is an error writing
to the log file.protected String controlToString(int control)
public void close()
public boolean isLogInMemory()
true
if the log is in memory.public InputStream getLog() throws IOException
Log
as an InputStream
.InputStream
of the Log
object.IOException
- thrown if InputStream cannot be created.protected void openLog()
Copyright © 2003, 2023, Oracle and/or its affiliates.