public class LogWriter
extends java.lang.Object
implements java.io.Serializable
All message keys retrieved by this class are assumed to be prefixed with "MSG.". Message keys supplied to this class' methods that are not already prefixed with "MSG." will be automatically prefixed when the key is retrieved.
Modifier and Type | Field and Description |
---|---|
protected static org.apache.log4j.Level |
cvAlert
The minimum severity level for triggering alert emails.
|
protected static java.util.Properties |
cvConfig
The log4j configuration properties.
|
protected static LogConsole |
cvConsole
A reference to the console logging class.
|
protected static org.apache.log4j.Logger |
cvMainLog
A reference to the MAIN log file.
|
static org.apache.log4j.Level |
DEBUG
The debug severity level.
|
static org.apache.log4j.Level |
ERROR
The error severity level.
|
static org.apache.log4j.Level |
FATAL
The fatal severity level.
|
protected static java.lang.String |
GENPREFIX
Generic text used to prefix an exception stack trace when no message id
or other text is supplied.
|
static org.apache.log4j.Level |
INFO
The information severity level.
|
private static long |
serialVersionUID
The class' serialization version id.
|
static org.apache.log4j.Level |
WARN
The warning severity level.
|
Constructor and Description |
---|
LogWriter() |
Modifier and Type | Method and Description |
---|---|
static void |
dumpPropertiesToFile()
Dumps a sorted list of the logger's configuration property keys and
values to a file named "_properties.log4j.txt" in the application's
temp folder.
|
static java.util.ArrayList<java.lang.String> |
dumpPropertiesToList()
Returns a sorted list of the logger's configuration property keys and
values.
|
static org.apache.log4j.Level |
getAlertLevel()
Returns the minimum severity level for sending alert emails.
|
static java.lang.String |
getLogFileFolder()
Returns the configured file path for MAIN log files.
|
static java.lang.String |
getLogFileName()
Returns the configured file name for MAIN log files.
|
static org.apache.log4j.Level |
getLogLevel()
Returns the current log level for the MAIN log.
|
static java.lang.String |
getStackTrace(java.lang.Exception ex)
Returns the stack trace for an exception as a string.
|
static void |
log(java.lang.Exception e)
Writes a MAIN log file entry for the given exception.
|
static void |
log(MailException mex)
Writes a MAIN log file entry for the given mail exception.
|
static void |
log(java.lang.String msgid)
Writes a MAIN log file entry for the given message id.
|
static void |
log(java.lang.String msgid,
java.lang.Exception ex)
Writes a MAIN log file entry for the given message id and exception.
|
static void |
log(java.lang.String msgid,
java.lang.Exception ex,
java.lang.String... values)
Writes a MAIN log file entry for the given message id and exception.
|
static void |
log(java.lang.String msgid,
java.lang.String... values)
Writes a MAIN log file entry for the given message id.
|
protected static void |
logMessage(org.apache.log4j.Level severity,
java.lang.String msgtext)
Writes a MAIN log file entry for the given severity level and message text
and sends an email if the message severity is configured for alert emails.
|
static void |
logSeparator()
Writes a MAIN log file entry for a separator (a series of dashes).
|
static java.lang.Object[] |
parseMessage(java.lang.String msgtext)
Parses the given message text to determine if the text contains a valid
severity level indicator.
|
static java.lang.Object[] |
parseMessage(java.lang.String msgtext,
org.apache.log4j.Level severity)
Parses the given message text to determine if the text contains a valid
severity level indicator.
|
protected static void |
sendAlertEmail(org.apache.log4j.Level severity,
java.lang.String msgtext)
Sends an email if the message severity is configured for alert emails.
|
static void |
setAlertLevel(org.apache.log4j.Level severity)
Sets the minimum severity level for sending alert emails.
|
private static void |
setLogFileFolder()
Sets the full file path for log files.
|
static void |
setLogLevel(org.apache.log4j.Level severity)
Sets the current log level for the MAIN log.
|
static void |
write(java.lang.String s)
Writes a MAIN log file entry for the given string.
|
static void |
write(java.lang.String s,
org.apache.log4j.Level severity)
Writes a MAIN log file entry for the given string and severity level.
|
private static final long serialVersionUID
protected static java.util.Properties cvConfig
protected static LogConsole cvConsole
protected static org.apache.log4j.Logger cvMainLog
protected static final java.lang.String GENPREFIX
public static final org.apache.log4j.Level DEBUG
public static final org.apache.log4j.Level INFO
public static final org.apache.log4j.Level WARN
public static final org.apache.log4j.Level ERROR
public static final org.apache.log4j.Level FATAL
protected static org.apache.log4j.Level cvAlert
public static void log(java.lang.String msgid)
msgid
- (String) The id for the message to log. If necessary,
the msgid is automatically prefixed with "MSG.".public static void log(java.lang.String msgid, java.lang.String... values)
msgid
- (String) The id for the message to log. If necessary,
the msgid is automatically prefixed with "MSG.".values
- (String) The value(s) to replace in the message text.
This parameter uses the varargs feature and can therefore be
passed as multiple parms (msgid, value1, value2, value3, valueN)
or as an array (msgid, values[]).public static void log(java.lang.String msgid, java.lang.Exception ex)
msgid
- (String) The id for the message to log. If necessary,
the msgid is automatically prefixed with "MSG.".ex
- (Exception) The exception to log.public static void log(java.lang.String msgid, java.lang.Exception ex, java.lang.String... values)
msgid
- (String) The id for the message to log. If necessary,
the msgid is automatically prefixed with "MSG.".ex
- (Exception) The exception to log.values
- (String) The value(s) to replace in the message text.
This parameter uses the varargs feature and can therefore be
passed as multiple parms (msgid, value1, value2, value3, valueN)
or as an array (msgid, values[]).public static void log(java.lang.Exception e)
e
- (Exception) The exception to log.public static void log(MailException mex)
mex
- (MailException) The exception to log.protected static void logMessage(org.apache.log4j.Level severity, java.lang.String msgtext)
severity
- (Level) The severity of the message. Must be one of
the defined constants (DEBUG, INFO, WARN, ERROR or FATAL).msgtext
- (String) The text for the message to log and email.public static void logSeparator()
public static void dumpPropertiesToFile()
public static java.util.ArrayList<java.lang.String> dumpPropertiesToList()
public static org.apache.log4j.Level getAlertLevel()
public static void setAlertLevel(org.apache.log4j.Level severity)
severity
- (Level) The minimum severity level. Must be one of
the defined constants (DEBUG, INFO, WARN, ERROR or FATAL) or
OFF.public static java.lang.String getLogFileFolder()
private static void setLogFileFolder()
Profile.SITE_PATH
.public static java.lang.String getLogFileName()
public static org.apache.log4j.Level getLogLevel()
public static void setLogLevel(org.apache.log4j.Level severity)
severity
- (Level) The current log level. Must be one of the
defined constants (DEBUG, INFO, WARN, ERROR or FATAL) or OFF.public static java.lang.String getStackTrace(java.lang.Exception ex)
ex
- (Exception) An exception.public static java.lang.Object[] parseMessage(java.lang.String msgtext)
msgtext
- (String) The text to parse.public static java.lang.Object[] parseMessage(java.lang.String msgtext, org.apache.log4j.Level severity)
msgtext
- (String) The text to parse.severity
- (Level) The default severity of the message if the
message does not contain its own severity. Must be one of the
defined constants (DEBUG, INFO, WARN, ERROR or FATAL).protected static void sendAlertEmail(org.apache.log4j.Level severity, java.lang.String msgtext)
severity
- (Level) The severity of the message. Must be one of
the defined constants (DEBUG, INFO, WARN, ERROR or FATAL).msgtext
- (String) The text for the message email.public static void write(java.lang.String s)
s
- (String) The string to write.public static void write(java.lang.String s, org.apache.log4j.Level severity)
s
- (String) The string to write.severity
- (Level) The severity of the message. Must be one of
the defined constants (DEBUG, INFO, WARN, ERROR or FATAL).