Class QBPFileLogger


  • public class QBPFileLogger
    extends AQBPLogger
    An implementation of AQBPLogger that logs to a standard file or stream. This logs to either a file system file or to a given PrintStream. The log messages are on separate lines, each log message having the format:

    time-stamp level 'message [reason]'

    Where:

    time-stamp is a time stamp with the format:
    [yyyy-MM-ddTHH-mm-ss.SSS]
    This records the time the log call was made.

    level is the log level. It is one of:

    • ERROR
    • CONFIG_ERROR
    • WARNING
    • INFO
    • TRACE

    message is the log message.

    reason is included only if a throwable reason object was included in the log call. It has the format:
    Reason: 'throwable-message'
    where throwable-message is the message from the reason object.

    • Constructor Detail

      • QBPFileLogger

        public QBPFileLogger​(java.io.File log_file)
                      throws java.lang.IllegalArgumentException
        Create a logger that logs to the given file. If the file already exists log messages are appended to the end. If it does not exist it is created.
        Parameters:
        log_file - log messages are appended to this file.
        Throws:
        java.lang.IllegalArgumentException - if could not create or open for writting this file for any reason.
      • QBPFileLogger

        public QBPFileLogger​(java.io.PrintStream log_stream)
        Log to an existing stream. Create a logger that logs messages to an existing, open stream.

        Caution! If other data is being written to the stream log messages could be lost. Write operations are synchronized on the given stream, but the logger cannot enforce others to also synchronize on the stream.

        The close method of this object will not close the given stream.

        Parameters:
        log_stream - the stream for all log messages.
    • Method Detail

      • close

        public void close()
        Close the logger. This closes the stream to the log file, if the stream was opened by this logger. All log attempts after this call will fail, regardless of whether the stream was closed or not.
      • sendError

        protected java.lang.String sendError​(java.lang.String raw_msg)
        Format an error message and send it to the log. This formats a raw error message and sends it to the error log. It returns the formatted message. The time stamp can be used to link the message in the log to any thrown exception or notation including the message.
        Specified by:
        sendError in class AQBPLogger
        Parameters:
        raw_msg - the error message.
        Returns:
        the formatted error message. If there is a failure sending the log message null should be returned; this triggers a thrown exception.
      • sendError

        protected java.lang.String sendError​(java.lang.String raw_msg,
                                             java.lang.Throwable reason)
        Format an error message and send it to the log with a reason. This formats a raw error message and sends it to the error log. A throwable object that triggered the exception is included. It returns the formatted message. The time stamp can be used to link the message in the log to any thrown exception or notation including the message.
        Specified by:
        sendError in class AQBPLogger
        Parameters:
        raw_msg - the error message.
        reason - the thrown exception that triggered this call.
        Returns:
        the formatted error message. If there is a failure sending the log message null should be returned, this will trigger a thrown exception.
      • sendConfigError

        protected java.lang.String sendConfigError​(java.lang.String raw_msg)
        Format a configuration error message and send it to the log. This formats a raw error message and sends it to the error log. It returns the formatted message. The time stamp can be used to link the message in the log to any thrown exception or notation including the message.
        Specified by:
        sendConfigError in class AQBPLogger
        Parameters:
        raw_msg - the error message.
        Returns:
        the formatted error message. If there is a failure sending the log message null should be returned, this will trigger a thrown exception.
      • sendConfigError

        protected java.lang.String sendConfigError​(java.lang.String raw_msg,
                                                   java.lang.Throwable reason)
        Format a configuration error message and send it to the log with a reason. This formats a raw error message and sends it to the error log. A throwable object that triggered the exception is included. It returns the formatted message. The time stamp can be used to link the message in the log to any thrown exception or notation including the message.
        Specified by:
        sendConfigError in class AQBPLogger
        Parameters:
        raw_msg - the error message.
        reason - the thrown exception that triggered this call.
        Returns:
        the formatted error message. If there is a failure sending the log message null should be returned, this will trigger a thrown exception.
      • sendWarning

        protected java.lang.String sendWarning​(java.lang.String raw_msg)
        Format a warning message and send it to the log. This formats a raw warning message and sends it to the warning log. It returns the formatted message. The time stamp can be used to link the message in the log to any thrown exception or notation including the message. (Note: currently warnings do not trigger exceptions or notations, but may in the future.)
        Specified by:
        sendWarning in class AQBPLogger
        Parameters:
        raw_msg - the error message.
        Returns:
        the formatted warning message. If there is a failure sending the log message null should be returned.
      • sendWarning

        protected java.lang.String sendWarning​(java.lang.String raw_msg,
                                               java.lang.Throwable reason)
        Format a warning message with a reason and send it to the log. This formats a raw warning message along with a throwable object that triggered the warning, and sends it to the warning log. It returns the formatted message. The time stamp can be used to link the message in the log to any thrown exception or notation including the message. (Note: currently warnings do not trigger exceptions or notations, but may in the future.)
        Specified by:
        sendWarning in class AQBPLogger
        Parameters:
        raw_msg - the error message.
        reason - the thrown exception that triggered this call.
        Returns:
        the formatted warning message. If there is a failure sending the log message null should be returned.
      • sendInfo

        protected java.lang.String sendInfo​(java.lang.String raw_msg)
        Format an information message and send it to the log. This formats a raw information message and sends it to the info log. It returns the formatted message. The time stamp can be used to link the message in the log to any thrown exception or notation including the message. (Note: currently information messages do not trigger notations, but they may in the future.)
        Specified by:
        sendInfo in class AQBPLogger
        Parameters:
        raw_msg - the error message.
        Returns:
        the formatted error message. If there is a failure sending the log message null should be returned.
      • sendTrace

        protected java.lang.String sendTrace​(java.lang.String raw_msg)
        Format a Trace message and send it to the log. This formats a raw trace message and sends it to the info log. It returns the formatted message.
        Specified by:
        sendTrace in class AQBPLogger
        Parameters:
        raw_msg - the error message.
        Returns:
        the formatted error message. If there is a failure sending the log message null should be returned.