public class LogFile
extends com.isti.util.logging.IstiConsoleLogger
Modifier and Type | Field and Description |
---|---|
static boolean |
DEFAULT_GMT_FLAG
Default for 'gmtFlag'.
|
static boolean |
DEFAULT_USE_DATE_IN_FNAME_FLAG
Default for 'useDateInFnameFlag'.
|
static java.lang.String |
FILE_DATE_PATTERNSTR
Pattern string for "file" date formatter ("yyyyMMdd").
|
static java.lang.String |
FNAME_DATE_SEPSTR
Separator used between file name and date code ("_").
|
static java.lang.String |
LONG_DATE_PATTERNSTR
Pattern string for "long" date formatter ("MMMM dd, yyyy HH:mm:ss z").
|
static int |
NO_LEVEL
A message level value used to specify that no log-level indicator
is to be output with the message (998).
|
static java.lang.String |
SHORT_DATE_PATTERNSTR
Pattern string for "short" date formatter ("MMM dd yyyy HH:mm:ss").
|
Constructor and Description |
---|
LogFile(java.lang.String fName,
int logFileLevel,
int consoleLevel)
Creates a new LogFile object, using the local timezone for
timestamps.
|
LogFile(java.lang.String fName,
int logFileLevel,
int consoleLevel,
boolean gmtFlag)
Creates a new LogFile object.
|
LogFile(java.lang.String fName,
int logFileLevel,
int consoleLevel,
boolean gmtFlag,
boolean useDateInFnameFlag)
Creates a new LogFile object.
|
LogFile(java.lang.String fName,
int logFileLevel,
int consoleLevel,
boolean gmtFlag,
boolean useDateInFnameFlag,
boolean writeHdrFdrFlag)
Creates a new LogFile object.
|
Modifier and Type | Method and Description |
---|---|
void |
addTrackedMsgListener(DataChangedListener listenerObj)
Adds the given tracked-message listener.
|
void |
close()
Closes the log file.
|
static LogFile |
getConsoleLogObj()
Gets a handle to the console log file object.
|
java.text.DateFormat |
getDateFormat()
Gets the date formatter for log file entries.
|
java.lang.String |
getFileName()
Returns the current log file name in use.
|
static LogFile |
getGlobalLogObj()
Gets a handle to the "global" log file object.
|
static LogFile |
getGlobalLogObj(boolean consoleFlag)
Gets a handle to the "global" log file object.
|
static java.lang.String[] |
getLevelNamesArray()
Returns an array containing all the valid log-level name strings.
|
static java.lang.String |
getLevelNamesDisplayStr()
Returns an array containing all the valid log-level name strings.
|
static java.util.Vector |
getLevelNamesVector()
Returns a Vector containing all the valid log-level name strings.
|
int |
getLogFileLevel()
Gets the current level for log file output messages.
|
LogOutputStream |
getLogOutputStream()
Returns an 'OutputStream' object whose output is directed to
this log file.
|
int |
getMaxLogFileAge()
Gets the maximum log file age.
|
protected java.lang.String |
getMessage(int level)
Gets the message for the level.
|
int |
getMinLevel()
Get the minimum level for all output messages.
|
static LogFile |
getNullLogObj()
Gets a handle to the null log file object.
|
java.lang.String[] |
getTrackedMessages()
Returns an array of strings containing the tracked messages.
|
java.lang.String[] |
getTrackedMessages(int maxAgeMs)
Returns an array of strings containing the tracked messages.
|
java.lang.String |
getTrackedMsgsAsString(java.lang.String sepStr)
Returns a string containing the tracked messages.
|
java.lang.String |
getTrackedMsgsAsString(java.lang.String sepStr,
int maxAgeMs)
Returns a string containing the tracked messages.
|
static LogFile |
initGlobalLogObj(LogFile logObj)
Initializes the "global" log file object.
|
static LogFile |
initGlobalLogObj(java.lang.String fName,
int logFileLevel,
int consoleLevel)
Initializes the "global" log file object, using the local timezone
for timestamps.
|
static LogFile |
initGlobalLogObj(java.lang.String fName,
int logFileLevel,
int consoleLevel,
boolean gmtFlag)
Initializes the "global" log file object.
|
static LogFile |
initGlobalLogObj(java.lang.String fName,
int logFileLevel,
int consoleLevel,
boolean gmtFlag,
boolean useDateInFnameFlag)
Initializes the "global" log file object.
|
boolean |
isOpen()
Determines if the log file is open.
|
protected boolean |
logMessage(int level,
java.lang.String str,
java.lang.Throwable t)
Sends the given string to the log file.
|
java.io.PrintStream |
logStandardErr()
Set the logger for standard error.
|
java.io.PrintStream |
logStandardErr(int level)
Set the logger for standard error.
|
java.io.PrintStream |
logStandardOut()
Set the logger for standard output.
|
java.io.PrintStream |
logStandardOut(int level)
Set the logger for standard output.
|
boolean |
println(java.lang.String str)
Sends the given string to the log file.
|
void |
removeTrackedMsgListener(DataChangedListener listenerObj)
Removes the given tracked-message listener.
|
void |
setLogFileLevel(int level)
Sets the current level for console output messages.
|
void |
setLogFileSwitchIntervalDays(int numDays)
Sets the minimum number of days between log file switches via
date changes.
|
void |
setMaxLogFileAge(int maxAge)
Sets the maximum log file age, in days.
|
void |
setupMessageTracking(int msgLevel,
int msgCount)
Sets up message tracking.
|
void |
setWriteDatePrefixFlag(boolean flgVal)
Sets whether or not a date-code prefix is inserted before each
entry in the log file.
|
getConsoleLevel, getConsoleOutput, setConsoleLevel, setConsoleOutput
public static final int NO_LEVEL
public static final boolean DEFAULT_GMT_FLAG
public static final boolean DEFAULT_USE_DATE_IN_FNAME_FLAG
public static final java.lang.String FNAME_DATE_SEPSTR
public static final java.lang.String FILE_DATE_PATTERNSTR
public static final java.lang.String SHORT_DATE_PATTERNSTR
public static final java.lang.String LONG_DATE_PATTERNSTR
public LogFile(java.lang.String fName, int logFileLevel, int consoleLevel, boolean gmtFlag, boolean useDateInFnameFlag, boolean writeHdrFdrFlag)
fName
- log file name to use (if a path name then any needed
parent directories will be created), or null for none.logFileLevel
- minimum level of messages to send to the
log file, such as NO_MSGS, INFO, etc.consoleLevel
- minimum level of messages to send to the
console, such as NO_MSGS, INFO, etc.gmtFlag
- true to use GMT for timestamps, false to use the
local timezone.useDateInFnameFlag
- true to use the date in the file name (and
create a new log file everytime the date changes).writeHdrFdrFlag
- true to write header and footer messages
to log file; false for no header and footer messages.public LogFile(java.lang.String fName, int logFileLevel, int consoleLevel, boolean gmtFlag, boolean useDateInFnameFlag)
fName
- log file name to use (if a path name then any needed
parent directories will be created), or null for none.logFileLevel
- minimum level of messages to send to the
log file, such as NO_MSGS, INFO, etc.consoleLevel
- minimum level of messages to send to the
console, such as NO_MSGS, INFO, etc.gmtFlag
- true to use GMT for timestamps, false to use the
local timezone.useDateInFnameFlag
- true to use the date in the file name (and
create a new log file everytime the date changes).public LogFile(java.lang.String fName, int logFileLevel, int consoleLevel, boolean gmtFlag)
fName
- log file name to use (if a path name then any needed
parent directories will be created).logFileLevel
- minimum level of messages to send to the
log file, such as NO_MSGS, INFO, etc.consoleLevel
- minimum level of messages to send to the
console, such as NO_MSGS, INFO, etc.gmtFlag
- true to use GMT for timestamps, false to use the
local timezone.public LogFile(java.lang.String fName, int logFileLevel, int consoleLevel)
fName
- log file name to use (if a path name then any needed
parent directories will be created).logFileLevel
- minimum level of messages to send to the
log file, such as NO_MSGS, INFO, etc.consoleLevel
- minimum level of messages to send to the
console, such as NO_MSGS, INFO, etc.public int getMaxLogFileAge()
public void setMaxLogFileAge(int maxAge)
maxAge
- maximum age (in days) or 0 to disable.public void setLogFileSwitchIntervalDays(int numDays)
numDays
- if > 0 then the minimum number of days between
log file switches; otherwise the log file switching feature is
disabled.public void setWriteDatePrefixFlag(boolean flgVal)
flgVal
- true to have a date-code prefix inserted before
each entry in the log file; false for not.public void setupMessageTracking(int msgLevel, int msgCount)
msgLevel
- minimum message level to be tracked, or NO_MSGS
for none.msgCount
- number of messages to be tracked.public java.lang.String[] getTrackedMessages(int maxAgeMs)
maxAgeMs
- maximum age (in milliseconds) of messages returned,
or 0 for all messages.public java.lang.String[] getTrackedMessages()
public java.lang.String getTrackedMsgsAsString(java.lang.String sepStr, int maxAgeMs)
sepStr
- separator to be placed between each item.maxAgeMs
- maximum age (in milliseconds) of messages returned,
or 0 for all messages.public java.lang.String getTrackedMsgsAsString(java.lang.String sepStr)
sepStr
- separator to be placed between each item.public void addTrackedMsgListener(DataChangedListener listenerObj)
listenerObj
- the 'DataChangedListener' object to be added.public void removeTrackedMsgListener(DataChangedListener listenerObj)
listenerObj
- the 'DataChangedListener' object to be removed.protected boolean logMessage(int level, java.lang.String str, java.lang.Throwable t)
logMessage
in class com.isti.util.logging.IstiConsoleLogger
level
- the message level to be used, or NO_LEVEL for none.str
- the string to be outputted.t
- Throwable associated with a log message or null if none.AbstractIstiLogger.getMessage(String, Throwable)
protected java.lang.String getMessage(int level)
getMessage
in class com.isti.util.logging.AbstractIstiLogger
level
- the message level.public boolean println(java.lang.String str)
println
in interface com.isti.util.logging.IstiLogger
println
in class com.isti.util.logging.AbstractIstiLogger
str
- the string to be outputted.public void close()
public LogOutputStream getLogOutputStream()
public java.lang.String getFileName()
public boolean isOpen()
public int getLogFileLevel()
public int getMinLevel()
getMinLevel
in class com.isti.util.logging.IstiConsoleLogger
AbstractIstiLogger.isLoggable(int)
public java.io.PrintStream logStandardErr()
public java.io.PrintStream logStandardErr(int level)
level
- the level.public java.io.PrintStream logStandardOut()
public java.io.PrintStream logStandardOut(int level)
level
- the level.public void setLogFileLevel(int level)
level
- the log file level to be used.public static java.util.Vector getLevelNamesVector()
public static java.lang.String[] getLevelNamesArray()
public static java.lang.String getLevelNamesDisplayStr()
public static LogFile initGlobalLogObj(LogFile logObj)
logObj
- the log file object.public static LogFile initGlobalLogObj(java.lang.String fName, int logFileLevel, int consoleLevel, boolean gmtFlag, boolean useDateInFnameFlag)
fName
- log file name to use (if a path name then any needed
parent directories will be created).consoleLevel
- minimum level of messages to send to the
console, such as NO_MSGS, INFO, etc.logFileLevel
- minimum level of messages to send to the
log file, such as NO_MSGS, INFO, etc.gmtFlag
- true to use GMT for timestamps, false to use the
local timezone.useDateInFnameFlag
- true to use the date in the file name (and
create a new log file everytime the date changes).public static LogFile initGlobalLogObj(java.lang.String fName, int logFileLevel, int consoleLevel, boolean gmtFlag)
fName
- log file name to use (if a path name then any needed
parent directories will be created).consoleLevel
- minimum level of messages to send to the
console, such as NO_MSGS, INFO, etc.logFileLevel
- minimum level of messages to send to the
log file, such as NO_MSGS, INFO, etc.gmtFlag
- true to use GMT for timestamps, false to use the
local timezone.public static LogFile initGlobalLogObj(java.lang.String fName, int logFileLevel, int consoleLevel)
fName
- log file name to use (if a path name then any needed
parent directories will be created).consoleLevel
- minimum level of messages to send to the
console, such as NO_MSGS, INFO, etc.logFileLevel
- minimum level of messages to send to the
log file, such as NO_MSGS, INFO, etc.public static LogFile getGlobalLogObj()
public static LogFile getGlobalLogObj(boolean consoleFlag)
consoleFlag
- true to return a console log file if
'initGlobalLogObj()' was not called previously, otherwise a null log file
is returned.
NOTE: Console output should be limited to messages that will be displayed
infrequently.public static LogFile getConsoleLogObj()
public static LogFile getNullLogObj()
public java.text.DateFormat getDateFormat()