public class LegacyLogManagerImpl extends HandleResource implements LegacyLogManager
| Modifier and Type | Class and Description |
|---|---|
private static interface |
LegacyLogManagerImpl.FileName
Interface to unite all implementations in returning common file name attributes - file name prefix
(clean name without number sequence or extension) and extension.
|
private static class |
LegacyLogManagerImpl.GenericFileName
A class for generic file names.
|
static class |
LegacyLogManagerImpl.LoggingLevel
Enumeration to list most commonly used logging entry types.
|
private static class |
LegacyLogManagerImpl.SequencedFileName
A parser for log file names including a sequence number for rotation.
|
private static class |
LegacyLogManagerImpl.SequencedFileNameMatcher
A matcher for log file names including certain prefix, extension and sequence number for rotation.
|
static class |
LegacyLogManagerImpl.SupportedEntryType
Enumeration to list all currently supported logging entry types.
|
| Modifier and Type | Field and Description |
|---|---|
private java.util.Map<LegacyLogManagerImpl.SupportedEntryType,java.lang.Integer> |
activatedTypeLevelPairs
The default entry type - logging level pairs.
|
private LegacyLogManagerClientService |
client
Client service.
|
private long |
clientProcessId
The client process id.
|
private static java.text.SimpleDateFormat |
DATETIME_FORMATTER
Formatter for date and time, used by WRITE-MESSAGE().
|
private static int |
HANDLE_CALL_LOGGING_LEVEL
Default logging level for handle execution of WRITE-MESSAGE().
|
private boolean |
isAppserver
A flag to indicate if running in an appserver.
|
private java.util.concurrent.atomic.AtomicBoolean |
isEnabled
Flag to indicate if LOG-MANAGER is enabled by configs.
|
private java.util.concurrent.atomic.AtomicBoolean |
isInitialized
A flag to indicate execution of the method initialize has completed.
|
private static CentralLogger |
LOG
A logger to write messages to server's log.
|
private java.io.File |
logFile
The log file path for clients or servers (AppServer and WebSpeed).
|
private int |
loggingLevel
The default logging level.
|
private int |
logThreshold
The default logging threshold.
|
private java.io.FileWriter |
logWriter
The file writer.
|
private static int |
MAX_LOG_FILE_THRESHOLD_BYTES
The maximum log file size threshold for roll over in bytes.
|
private static int |
MAX_NUM_LOG_FILES
The maximum number of log files for roll over.
|
private int |
maxInputCharacters
Max number of characters supported in one message.
|
private static int |
MIN_LOG_FILE_THRESHOLD_BYTES
The minimum log file size threshold for roll over in bytes.
|
private static java.lang.String |
NUMBER_REGEX
Regex to validate if a string can be parsed to a number.
|
private int |
numLogFiles
The default number of logging files.
|
private java.util.concurrent.atomic.AtomicInteger |
remoteFileSize
Counter for client-side log file size.
|
private Session |
session
Client session.
|
private static java.lang.String |
SUBSYS_APPSERVER_AGENT
Appserver subsystem code for WRITE-MESSAGE().
|
private static java.lang.String |
SUBSYS_DEFAULT
Default subsystem code for WRITE-MESSAGE().
|
static java.lang.String |
SUBSYS_EMPTY
Subsystem for log file header and error (level 1) messages.
|
private static int |
WRITE_MSG_SUBSYS_CHARS_COUNT
Number of characters of subsys column for WRITE-MESSAGE().
|
private LegacyLogWriteExecutor |
writeExecutor
A reference to the queue that handles writing log records.
|
instProc, pm| Constructor and Description |
|---|
LegacyLogManagerImpl(LegacyLogWriteExecutor writeExecutor)
Package private constructor to create an instance of a LOG-MANAGER.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) static void |
cleanupRotation(java.io.File logFile,
int numLogFiles)
Removes the sequenced log files with the same name in the same folder that exceed the max count of
numLogFiles, while preserving the current log file and of its predecessors. |
logical |
clearLog()
Deletes all messages from the currently open log file or deletes all log files in the sequence if
rotation is enabled.
|
logical |
close(boolean isProcedureCall,
boolean closeWriteExecutor)
Closes the currently open log file.
|
logical |
closeLog()
Closes the currently open log file.
|
private java.lang.String |
createLogLine(int logLvl,
java.lang.String subsys,
java.lang.String msg,
long threadId,
java.util.Date date)
Formats the parameters to the 4GL log record format.
|
private java.lang.String |
createLogRecord(java.lang.String msg,
java.lang.String subsys,
java.lang.String[] callStack,
int logLevel,
long threadId,
java.util.Date date)
Formats the input data as a log record.
|
(package private) static boolean |
deleteSequence(java.io.File logFile)
Deletes all files in the sequence in the same folder as the provided log file.
|
private static int |
findLastLogFileNumber(java.io.File dir,
java.lang.String nameNoExt,
java.lang.String ext)
This should reflect the 4GL logic to find the last file that has been written to.
|
private static java.lang.String |
formatFileName(LegacyLogManagerImpl.FileName fileName,
int sequenceNumber)
Concatenates the file name, sequence and extension.
|
private java.lang.String |
formatSubsys(java.lang.String subsys)
Format the subsystem string.
|
private static java.lang.String |
formatSystemId(long id)
Format process or thread id.
|
character |
getEntryTypesList()
Provides the comma-separated list of currently valid entry types that can be assigned to
the
setLogEntryTypes(java.lang.String). |
character |
getLogEntryTypes()
Provides the comma-separated list of entry types that are being actively used for logging.
|
character |
getLogFileName()
Obtains the file path to which log entries and stack traces are written.
|
integer |
getLoggingLevel()
Obtains the default logging level for all logging categories.
|
integer |
getLogThreshold()
Obtains the configured log file size in bytes at which the log file will be renamed and a
new log file started.
|
integer |
getNumLogFiles()
Obtains the configured number of log files that will be stored in total (including both
backed up log files and the current log).
|
void |
initialize(LegacyLogManagerConfigs configs)
Validates and sets configs coming from command line.
|
private void |
initialize(java.lang.String logFile,
java.lang.String levelString,
java.lang.String entryTypes,
java.lang.Integer fileSize,
java.lang.Integer numLogFiles,
long clientProcessId,
int maxInputCharacters,
boolean isAppserver,
boolean isAppServerLoggerInitialized)
Sets configs coming from command line.
|
private boolean |
isRotationEnabled()
Checks if file rotation is enabled.
|
(package private) static boolean |
isWritable(java.io.File file)
Checks if the folder exists and if the JVM process has rights to write to it.
|
(package private) static java.io.File |
makeSequencedLogFile(java.lang.String logFilePath,
int logThreshold)
Adds a dot and a sequence number to the file name before the file extension.
|
private static int |
nextSequenceNumber(int lastNumber)
Get the next number in the sequence valid range.
|
private void |
recordOrShowWarning(int num,
java.lang.String text,
boolean prefix)
Manufacture a warning text based on the given parameters.
|
private void |
recordOrThrowError(int num,
java.lang.String text,
boolean prefix)
Raise an error condition and optionally record the given error.
|
private void |
resetEnabled()
Sets the isEnabled flag.
|
private void |
rotateLogFile()
Creates the next file in the sequence.
|
void |
setLogEntryTypes(character types)
Modifies the list of log entry types that are being actively used for logging.
|
void |
setLogEntryTypes(java.lang.String types)
Modifies the list of log entry types that are being actively used for logging.
|
private void |
setLogFileName(boolean isProcedureCall,
java.lang.String logFileConfig)
Assigns the file path to which log entries and stack traces are written.
|
void |
setLogFileName(character filePath)
Assigns the filename to which log entries and stack traces are written.
|
void |
setLogFileName(java.lang.String logFileConfig)
Assigns the file path to which log entries and stack traces are written.
|
void |
setLoggingLevel(int level)
Assigns the default logging level for all logging categories.
|
void |
setLoggingLevel(integer level)
Assigns the default logging level for all logging categories.
|
private boolean |
setLogThreshold(int fileSize)
Assigns the log file size threshold in bytes for rolling over to a new file.
|
private boolean |
setNumLogFiles(int numLogFiles)
Sets the number of log files that will be stored in total
(including both backed up log files and the current log).
|
private void |
switchLogFile(java.io.File newLogFile)
Updates the field
logFile for resolved path to the log File. |
boolean |
valid()
This object is always valid for use.
|
private boolean |
writeLocal(java.lang.String logRecord)
Writes the log record to the log file server-side.
|
logical |
writeMessage(character msg)
Write a user defined message to the currently open log file using the default subsystem name "APPL".
|
logical |
writeMessage(character msg,
character subsys)
Write a user defined message to the currently open log file using the given subsystem name.
|
logical |
writeMessage(character msg,
java.lang.String subsys)
Write a user defined message to the currently open log file using the given subsystem name.
|
logical |
writeMessage(java.lang.String msg)
Write a user defined message to the currently open log file using the default subsystem name "APPL".
|
logical |
writeMessage(java.lang.String msg,
character subsys)
Write a user defined message to the currently open log file using the given subsystem name.
|
logical |
writeMessage(java.lang.String msg,
java.lang.String subsys)
Write a user defined message to the currently open log file using the given subsystem name.
|
logical |
writeMessage(java.lang.String msg,
java.lang.String subsys,
java.lang.String[] callStack,
int logLevel,
long threadId)
Write an automated message from the given subsystem to the currently open log file.
|
private logical |
writeMessage(java.lang.String msg,
java.lang.String subsys,
java.lang.String[] callStack,
int logLevel,
long threadId,
boolean isAutoLogging)
Write a user defined message from a handle WRITE-MESSAGE call or an automated message to the
currently open log file using the given subsystem name.
|
private boolean |
writeRemote(java.lang.String logRecord,
boolean isAutoLogging)
Writes the log record to the log file client-side.
|
private void |
writeSystemHeader()
Writes the system messages when a new file name is set.
|
_instantiatingProcedure, addToPool, delete, doDelete, equals, hashCode, id, id, implicitDeletion, incrementTrigger, instantiatingProcedure, invalidAttribute, processResource, readOnlyError, readOnlyError, registerResource, resourceDelete, resourceType, setInstantiatingProcedure, toString, type, unableToAssignUnknown, unknownclone, finalize, getClass, notify, notifyAll, wait, wait, waitreadOnlyError, readOnlyError, resourceTypeid, id, unknowninstantiatingProcedureallowDeletepublic static final java.lang.String SUBSYS_EMPTY
private static final java.lang.String SUBSYS_DEFAULT
private static final java.lang.String SUBSYS_APPSERVER_AGENT
private static final int HANDLE_CALL_LOGGING_LEVEL
private static final int WRITE_MSG_SUBSYS_CHARS_COUNT
private static final java.text.SimpleDateFormat DATETIME_FORMATTER
private static final java.lang.String NUMBER_REGEX
private static final int MIN_LOG_FILE_THRESHOLD_BYTES
private static final int MAX_LOG_FILE_THRESHOLD_BYTES
private static final int MAX_NUM_LOG_FILES
private static final CentralLogger LOG
private final LegacyLogWriteExecutor writeExecutor
private final java.util.concurrent.atomic.AtomicBoolean isInitialized
private java.util.concurrent.atomic.AtomicBoolean isEnabled
private int maxInputCharacters
private boolean isAppserver
private long clientProcessId
private java.io.File logFile
private java.io.FileWriter logWriter
private final java.util.Map<LegacyLogManagerImpl.SupportedEntryType,java.lang.Integer> activatedTypeLevelPairs
private int loggingLevel
private int logThreshold
private int numLogFiles
private LegacyLogManagerClientService client
private Session session
private java.util.concurrent.atomic.AtomicInteger remoteFileSize
LegacyLogManagerImpl(LegacyLogWriteExecutor writeExecutor)
writeExecutor - Reference to the executor that actually writes log messages.public void initialize(LegacyLogManagerConfigs configs)
initialize in interface LegacyLogManagerconfigs - Configs.private void initialize(java.lang.String logFile,
java.lang.String levelString,
java.lang.String entryTypes,
java.lang.Integer fileSize,
java.lang.Integer numLogFiles,
long clientProcessId,
int maxInputCharacters,
boolean isAppserver,
boolean isAppServerLoggerInitialized)
logFile - File path for the log.levelString - Default logging level.entryTypes - List of comma-separated log entry types.fileSize - File size in bytes used as threshold for file roll over.numLogFiles - Max number of log files.clientProcessId - The id of the client process.maxInputCharacters - The max number of characters.isAppServerLoggerInitialized - A flag to indicate if the appserver logger has already been initialized in a different.public character getEntryTypesList()
setLogEntryTypes(java.lang.String).getEntryTypesList in interface LegacyLogManagerpublic character getLogEntryTypes()
getLogEntryTypes in interface LegacyLogManagerpublic void setLogEntryTypes(java.lang.String types)
setLogEntryTypes in interface LegacyLogManagertypes - The comma-separated list of active entry types.public void setLogEntryTypes(character types)
setLogEntryTypes in interface LegacyLogManagertypes - The comma-separated list of active entry types.public character getLogFileName()
getLogFileName in interface LegacyLogManagerpublic void setLogFileName(java.lang.String logFileConfig)
setLogFileName in interface LegacyLogManagerlogFileConfig - The log file path.public void setLogFileName(character filePath)
setLogFileName in interface LegacyLogManagerfilePath - The log file path.public integer getLoggingLevel()
getLoggingLevel in interface LegacyLogManagerpublic void setLoggingLevel(int level)
There are 5 valid levels:
setLoggingLevel in interface LegacyLogManagerlevel - The logging level to use by default.public void setLoggingLevel(integer level)
There are 5 valid levels:
setLoggingLevel in interface LegacyLogManagerlevel - The logging level to use by default.public integer getLogThreshold()
getLogThreshold in interface LegacyLogManagerpublic integer getNumLogFiles()
getNumLogFiles in interface LegacyLogManagerpublic logical clearLog()
clearLog in interface LegacyLogManagertrue if the operation succeeded, or false
otherwise.public logical closeLog()
This method should not be used as a manual call, but only automatically from procedure execution.
Use close(boolean,boolean) instead.
closeLog in interface LegacyLogManagertrue if the operation succeeded, or false
otherwise.public logical close(boolean isProcedureCall, boolean closeWriteExecutor)
close in interface LegacyLogManagerisProcedureCall - Flag to identify the method is called by the execution of a converted 4GL procedure.closeWriteExecutor - Flag to identify the manager is not going to use writeExecutor any more. In case
of file being rotated or clearLog() called, this should be false.true if the operation succeeded, or false
otherwise.public boolean valid()
valid in interface WrappedResourcetrue.public logical writeMessage(java.lang.String msg)
HANDLE_CALL_LOGGING_LEVEL.
Should be used only automatically by the converted code or LOG-MANAGER itself.
writeMessage in interface LegacyLogManagermsg - The message to write.true if the operation succeeded, or false
otherwise.public logical writeMessage(character msg)
HANDLE_CALL_LOGGING_LEVEL.
Should be used only automatically by the converted code or LOG-MANAGER itself.
writeMessage in interface LegacyLogManagermsg - The message to write.true if the operation succeeded, or false
otherwise.public logical writeMessage(java.lang.String msg, java.lang.String subsys)
HANDLE_CALL_LOGGING_LEVEL.
Should be used only automatically by the converted code or LOG-MANAGER itself.
writeMessage in interface LegacyLogManagermsg - The message to write.subsys - Subsystem name (up to 10 characters will be used).true if the operation succeeded, or false
otherwise.public logical writeMessage(character msg, java.lang.String subsys)
HANDLE_CALL_LOGGING_LEVEL.
Should be used only automatically by the converted code or LOG-MANAGER itself.
writeMessage in interface LegacyLogManagermsg - The message to write.subsys - Subsystem name (up to 10 characters will be used).true if the operation succeeded, or false
otherwise.public logical writeMessage(java.lang.String msg, character subsys)
HANDLE_CALL_LOGGING_LEVEL.
Should be used only automatically by the converted code or LOG-MANAGER itself.
writeMessage in interface LegacyLogManagermsg - The message to write.subsys - Subsystem name (up to 10 characters will be used).true if the operation succeeded, or false
otherwise.public logical writeMessage(character msg, character subsys)
HANDLE_CALL_LOGGING_LEVEL.
Should be used only automatically by the converted code or LOG-MANAGER itself.
writeMessage in interface LegacyLogManagermsg - The message to write.subsys - Subsystem name (up to 10 characters will be used).true if the operation succeeded, or false
otherwise.public logical writeMessage(java.lang.String msg, java.lang.String subsys, java.lang.String[] callStack, int logLevel, long threadId)
To be used for custom calls / auto logging of entry types.
writeMessage in interface LegacyLogManagermsg - The message to write.subsys - Subsystem name (up to 10 characters will be used).callStack - The call stack.logLevel - The logging level of the message.threadId - The client thread id or server thread id for AppServer and WebSpeed.true if the operation succeeded, or logical false
otherwise.private logical writeMessage(java.lang.String msg, java.lang.String subsys, java.lang.String[] callStack, int logLevel, long threadId, boolean isAutoLogging)
To be used for custom calls / auto logging of entry types.
msg - The message to write.subsys - Subsystem name (up to 10 characters will be used).callStack - The call stack.logLevel - The logging level of the message.threadId - The client thread id or server thread id for AppServer and WebSpeed.isAutoLogging - A flag to indicate if auto logging from a subsystem or a user call from converted procedure.true if the operation succeeded, or logical false
otherwise.private java.lang.String createLogRecord(java.lang.String msg,
java.lang.String subsys,
java.lang.String[] callStack,
int logLevel,
long threadId,
java.util.Date date)
msg - The message to write.subsys - Subsystem name (up to 10 characters will be used).callStack - The call stack.logLevel - The logging level of the message.threadId - The client thread id or server thread id for AppServer and WebSpeed.date - The date of the log record.private void resetEnabled()
static boolean isWritable(java.io.File file)
file - The file to check for.true if the folder is writable, false otherwise.static java.io.File makeSequencedLogFile(java.lang.String logFilePath,
int logThreshold)
logThreshold value, the method increments the last
sequence number or uses 1 if the end of the allowed range 999999 is reached.logFilePath - The log file without sequence number.logThreshold - The log file size threshold for rolling over to a new file.static void cleanupRotation(java.io.File logFile,
int numLogFiles)
numLogFiles, while preserving the current log file and of its predecessors.static boolean deleteSequence(java.io.File logFile)
logFile - The log file to base the sequence finding on.true if all files in the sequence successfully deleted,
false otherwise.private static int nextSequenceNumber(int lastNumber)
lastNumber - The previous number in the sequence.private static java.lang.String formatFileName(LegacyLogManagerImpl.FileName fileName, int sequenceNumber)
fileName - The file name object wrapper for the name prefix (name without extension and sequence number)
and the extension itself.sequenceNumber - The sequence number.private static java.lang.String formatSystemId(long id)
id - The process or thread id.private static int findLastLogFileNumber(java.io.File dir,
java.lang.String nameNoExt,
java.lang.String ext)
dir - The directory to search for log files.nameNoExt - The name of the file without extension and sequence.ext - The extension of the file.private void switchLogFile(java.io.File newLogFile)
logFile for resolved path to the log File. Closes the old log file, does
cleanup of old rotation log files based on numLogFiles, and opens the new file
adding the log header lines.newLogFile - The new log file to be used.private void writeSystemHeader()
private boolean setLogThreshold(int fileSize)
fileSize - The log file size threshold for rolling over to a new file.private boolean isRotationEnabled()
logThreshold has been initialized (having a value
greater than 0), log file rotation is enabled.true if rotation is enabled, false otherwise.private boolean setNumLogFiles(int numLogFiles)
numLogFilesString - The number of log files in total.private void setLogFileName(boolean isProcedureCall,
java.lang.String logFileConfig)
isProcedureCall - Flag to identify the method is called by the execution of a converted 4GL procedure.logFileConfig - The log file path.private java.lang.String createLogLine(int logLvl,
java.lang.String subsys,
java.lang.String msg,
long threadId,
java.util.Date date)
logLvl - The logging level. See LegacyLogManagerImpl.LoggingLevel.subsys - The subsystem name.msg - The message.threadId - The client thread id or server thread id for AppServer and WebSpeed.date - The date of the log record.private boolean writeLocal(java.lang.String logRecord)
logRecord - The record to be written to the log file.true if the record has been written successfully, false otherwise.private boolean writeRemote(java.lang.String logRecord,
boolean isAutoLogging)
logRecord - The record to be written to the log file.isAutoLogging - A flag to indicate if auto logging from a subsystem or a user call from converted procedure.true if the record has been written successfully, false otherwise.private java.lang.String formatSubsys(java.lang.String subsys)
WRITE_MSG_SUBSYS_CHARS_COUNT.subsys - Subsystem name.private void rotateLogFile()
private void recordOrThrowError(int num,
java.lang.String text,
boolean prefix)
num - The error number.text - The text of the error message.prefix - true to prepend a double asterisk prefix to the
formatted error message, false to omit this text.ErrorConditionExceptionprivate void recordOrShowWarning(int num,
java.lang.String text,
boolean prefix)
num - The error number.text - The text of the error message.prefix - true to prepend a double asterisk prefix to the formatted error
message, false to omit this text.