Class Logger


  • public class Logger
    extends Object
    Logger utility to write log messages to a PrintStream. It is possible to set six different log levels.
    • none Logging disabled
    • error Only error messages will be logged
    • warning Error and warning messages will be logged
    • config Error, warning and config messages will be logged
    • info All messages except debug messages will be logged
    • debug All messages will be logged
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int config
      Indicates a system configuration message.
      static int debug
      Indicates a debug message.
      static int error
      Indicates a error message.
      static int info
      Indicates a information message.
      static int none
      If the log level is none no message will be logged.
      static int warning
      Indicates a warning message.
    • Constructor Summary

      Constructors 
      Constructor Description
      Logger​(PrintStream stream)
      Creates a new Logger object which write log messages to the PrintStream stream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getLevel()
      Returns the actual level of the logger.
      void log​(int level, String msg)
      Writes a log message to the PrintStream if the parameter level is greater than the logger level.
      With % it is possible to add some arguments to the message.
      void log​(int level, String msg, int val)
      Writes a log message to the PrintStream if the parameter level is greater than the logger level.
      With % it is possible to add some arguments to the message.
      void log​(int level, String msg, int... values)
      Writes a log message to the PrintStream if the parameter level is greater than the logger level.
      With % it is possible to add some arguments to the message.
      void setLevel​(int level)
      Set the log level.
    • Field Detail

      • none

        public static final int none
        If the log level is none no message will be logged. Don't use this level to indicate a message by a log method call, because this level is only used to disable all messages.
        See Also:
        Constant Field Values
      • config

        public static final int config
        Indicates a system configuration message.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Logger

        public Logger​(PrintStream stream)
        Creates a new Logger object which write log messages to the PrintStream stream. The standard log level is warning.
        Parameters:
        stream - The output stream of the logger.
    • Method Detail

      • setLevel

        public void setLevel​(int level)
        Set the log level. Possible levels are:
        Parameters:
        level - the level of the logger.
      • getLevel

        public int getLevel()
        Returns the actual level of the logger.
        Returns:
        the actual level.
      • log

        public void log​(int level,
                        String msg)
        Writes a log message to the PrintStream if the parameter level is greater than the logger level.
        With % it is possible to add some arguments to the message.
        • %t adds the actual date and time to the message
        • %l adds the level description to the message
        Example:
        log(Logger.error,"%l My log message %t",12); will log following message.
        [Erro] My log message 12.11.2009 08:57:13.
        Parameters:
        level - the log level of the message.
        msg - the message. %d.
      • log

        public void log​(int level,
                        String msg,
                        int val)
        Writes a log message to the PrintStream if the parameter level is greater than the logger level.
        With % it is possible to add some arguments to the message.
        • %t adds the actual date and time to the message
        • %l adds the level description to the message
        • %d adds the parameter val to the message
        Example:
        log(Logger.error,"%l My log message with parameter value: %d",12); will log following message.
        [Erro] My log message with parameter value: 12.
        Parameters:
        level - the log level of the message.
        msg - the message.
        val - an integer value which can be added to the message with %d.
      • log

        public void log​(int level,
                        String msg,
                        int... values)
        Writes a log message to the PrintStream if the parameter level is greater than the logger level.
        With % it is possible to add some arguments to the message.
        • %t adds the actual date and time to the message
        • %l adds the level description to the message
        • %d adds the parameters values to the message
        Please use this method only if you really need to add more than one value to the message. This because every call will allocate new integer array. Example:
        log(Logger.error,"%l My log message with parameter values: %d, %d, %d,",12,13,14); will log following message.
        [Erro] My log message with parameter value: 12, 13, 14.
        Parameters:
        level - the log level of the message.
        msg - the message.
        values - n integer values which can be added to the message with %d.