Class Logger


  • public class Logger
    extends Object

    This class can be used for writing log output. It has a number of static methods to send a log message at a specific level. The supported levels in order from most urgent to least urgent are:

    The actual behaviour of the logger is determined by the LogDelegate which is set with setLogDelegate(). The default is a DefaultLogDelegate, which writes messages to standard output or standard error. Normally the log delegate should be set and configured once at the start of the application.

    Each log method takes a tag parameter. This should be a tag that identifies the source of the log. A log delegate may apply different log levels for different tags. For example one tag may be logged up to the level DEBUG, while another tag is only logged up to the level WARN.

    Note that it may require computation time and resources to construct a log message, and this is not necessary if eventually the message is not written because of the log level. To avoid the construction costs, you may check isLoggable() first.

    • Constructor Detail

      • Logger

        public Logger()
    • Method Detail

      • setLogDelegate

        public static void setLogDelegate​(LogDelegate delegate)
        Sets the log delegate. See the top of this page for more information.
        Parameters:
        delegate - the log delegate
      • getLogDelegate

        public static LogDelegate getLogDelegate()
        Returns the log delegate.
        Returns:
        the log delegate
      • d

        public static int d​(String tag,
                            String msg,
                            Throwable tr)
        Writes a message at level DEBUG.
        Parameters:
        tag - the tag
        msg - the message
        tr - an exception
        Returns:
        0 if no error occurred, an error code otherwise
      • d

        public static int d​(String tag,
                            String msg)
        Writes a message at level DEBUG.
        Parameters:
        tag - the tag
        msg - the message
        Returns:
        0 if no error occurred, an error code otherwise
      • e

        public static int e​(String tag,
                            String msg)
        Writes a message at level ERROR.
        Parameters:
        tag - the tag
        msg - the message
        Returns:
        0 if no error occurred, an error code otherwise
      • e

        public static int e​(String tag,
                            String msg,
                            Throwable tr)
        Writes a message at level ERROR.
        Parameters:
        tag - the tag
        msg - the message
        tr - an exception
        Returns:
        0 if no error occurred, an error code otherwise
      • getStackTraceString

        public static String getStackTraceString​(Throwable tr)
        Returns the stack trace string for the specified exception. The returned string probably contains new lines, but it does not have a trailing new line.
        Parameters:
        tr - the exception
        Returns:
        the stack trace string
      • i

        public static int i​(String tag,
                            String msg,
                            Throwable tr)
        Writes a message at level INFO.
        Parameters:
        tag - the tag
        msg - the message
        tr - an exception
        Returns:
        0 if no error occurred, an error code otherwise
      • i

        public static int i​(String tag,
                            String msg)
        Writes a message at level INFO.
        Parameters:
        tag - the tag
        msg - the message
        Returns:
        0 if no error occurred, an error code otherwise
      • isLoggable

        public static boolean isLoggable​(String tag,
                                         int level)
        Determines if messages at the specified level are logged for the specified tag.
        Parameters:
        tag - the tag
        level - the level
        Returns:
        true if the message will be logged, false otherwise
      • println

        public static int println​(int priority,
                                  String tag,
                                  String msg)
        Writes a log message.
        Parameters:
        priority - the log level
        tag - the tag
        msg - the message
        Returns:
        0 if no error occurred, an error code otherwise
      • v

        public static int v​(String tag,
                            String msg,
                            Throwable tr)
        Writes a message at level VERBOSE.
        Parameters:
        tag - the tag
        msg - the message
        tr - an exception or null
        Returns:
        0 if no error occurred, an error code otherwise
      • v

        public static int v​(String tag,
                            String msg)
        Writes a message at level VERBOSE.
        Parameters:
        tag - the tag
        msg - the message
        Returns:
        0 if no error occurred, an error code otherwise
      • w

        public static int w​(String tag,
                            String msg)
        Writes a message at level WARN.
        Parameters:
        tag - the tag
        msg - the message
        Returns:
        0 if the message was written successfully, an error code otherwise
      • w

        public static int w​(String tag,
                            Throwable tr)
        Writes a message at level WARN.
        Parameters:
        tag - the tag
        tr - an exception or null
        Returns:
        0 if no error occurred, an error code otherwise
      • w

        public static int w​(String tag,
                            String msg,
                            Throwable tr)
        Writes a message at level WARN.
        Parameters:
        tag - the tag
        msg - the message
        tr - an exception or null
        Returns:
        0 if no error occurred, an error code otherwise
      • wtf

        public static int wtf​(String tag,
                              String msg)
        Writes a message at level ASSERT.
        Parameters:
        tag - the tag
        msg - the message
        Returns:
        0 if no error occurred, an error code otherwise
      • wtf

        public static int wtf​(String tag,
                              Throwable tr)
        Writes a message at level ASSERT.
        Parameters:
        tag - the tag
        tr - an exception or null
        Returns:
        0 if no error occurred, an error code otherwise
      • wtf

        public static int wtf​(String tag,
                              String msg,
                              Throwable tr)
        Writes a message at level ASSERT.
        Parameters:
        tag - the tag
        msg - the message
        tr - an exception or null
        Returns:
        0 if no error occurred, an error code otherwise