Package com.iizix

Class Loggers

java.lang.Object
com.iizix.Loggers

public class Loggers extends Object
The class that manages all ILog instances in the process and it's threads or thread groups. If no special assigned Loggers instance is found using the ILoggers interface, the default one is used.

The following arguments are converted using "deep-toString" meaning their contents and subcontents are deep-toString'eg if possible, otherwise just as "toString()".

  • null: "null".
  • Array of primitives: the entire array is expanded.
  • com.iizix.prop.StringMapProp or java.util.Map: lists all the contents on new lines as " - key = value".
  • Throwable: expanded throwable with stack trace, including potential ignored exception and cause.
Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The indent string used when parameters are on new lines.
    static String
    The string that is prepended to all logged messages when written to System.out when no ILoggerRedirector is present.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a Loggers instance, without name.
    Constructs a Loggers instance with the specified name.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the unredirected console standard error.
    Gets the unredirected console standard output.
    static Loggers
    Method to get the Loggers instance from the calling thread.
    static Loggers
    Gets the default instance of the Loggers.
    static String
    getLevelString(int level)
    Gets the level string.
    static String
    Gets the formatted level string that is adjusted with spaces and surrounded with [].
    int
    Gets the log level.
    Gets the name of this logger.
    Sets the log redirector used when redirecting an event from client to server.
    static void
    log(int level, String clazz, String msg)
    Logs an event to the logger of the current thread or thread group.
    static void
    log(int level, String clazz, String msg, Object param)
    Logs an event to the logger of the current thread or thread group.
    static void
    log(int level, String clazz, String msg, Object... params)
    Logs an event to the logger of the current thread or thread group.
    static void
    log(int level, String clazz, String msg, Object param1, Object param2)
    Logs an event to the logger of the current thread or thread group.
    static void
    logForced(int level, String clazz, String msg)
    Logs an event to the logger of the current thread or thread group.
    static void
    logForced(int level, String clazz, String msg, Object param)
    Forces logging of an event to the logger of the current thread or thread group.
    static void
    logForced(int level, String clazz, String msg, Object... params)
    Forces logging of an event to the logger of the current thread or thread group.
    static void
    logForced(int level, String clazz, String msg, Object param1, Object param2)
    Forces logging of an event to the logger of the current thread or thread group.
    void
    logInternal(Thread thread, int level, String who, String msg, Object[] params)
    Logs an event, possibly using the redirector using this Loggers instance name and possible additional information.
    void
    logInternalForced(Thread thread, int level, String who, String msg, Object[] params)
    Logs an event, possibly using the redirector using this Loggers instance name and possible additional information.
    void
    setLogLevel(int level)
    Changes the log level.
    static boolean
    Sets the log redirector used when redirecting an event from client to server.
    static void
    Logs to console standard error.
    static void
    Logs to console standard output.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • INDENT

      public static final String INDENT
      The indent string used when parameters are on new lines.
      See Also:
    • prependString

      public static String prependString
      The string that is prepended to all logged messages when written to System.out when no ILoggerRedirector is present.
  • Constructor Details

    • Loggers

      public Loggers()
      Constructs a Loggers instance, without name.
    • Loggers

      public Loggers(String name)
      Constructs a Loggers instance with the specified name.
      Parameters:
      name - The name of the logger.
  • Method Details

    • stdout_println

      public static void stdout_println(String text)
      Logs to console standard output. Please avoid using this method for other purposes than debug output.
      Parameters:
      text - Prints a text with line feed to the console bypassing a potential redirection.
    • stderr_println

      public static void stderr_println(String text)
      Logs to console standard error. Please avoid using this method for other purposes than debug output.
      Parameters:
      text - Prints a text with line feed to the console bypassing a potential redirection.
    • get_stdout

      public static PrintStream get_stdout()
      Gets the unredirected console standard output. Please avoid using this method for other purposes than debug output.
      Returns:
      The print stream that is not redirected to the loggers.
    • get_stderr

      public static PrintStream get_stderr()
      Gets the unredirected console standard error. Please avoid using this method for other purposes than debug output.
      Returns:
      The print stream that is not redirected to the loggers.
    • getLevelString

      public static String getLevelString(int level)
      Gets the level string.
      Parameters:
      level - The level.
      Returns:
      The string, or UNKNOWN if level is wrong.
    • getLevelStringFormatted

      public static String getLevelStringFormatted(int level)
      Gets the formatted level string that is adjusted with spaces and surrounded with [].
      Parameters:
      level - The log level (1-7).
      Returns:
      The formatted log string.
    • getDefault

      public static Loggers getDefault()
      Gets the default instance of the Loggers.
      Returns:
      The default Loggers instance.
    • getRedirector

      public static ILoggerRedirector getRedirector()
      Sets the log redirector used when redirecting an event from client to server.
      Returns:
      logRedirector, the log redirector or null for none.
    • setRedirector

      public static boolean setRedirector(ILoggerRedirector newRedirector)
      Sets the log redirector used when redirecting an event from client to server.
      Parameters:
      newRedirector - the new redirector or null for none. The previous logger
      Returns:
      true if the setting changed, false if same value was present.
    • getCurrent

      public static Loggers getCurrent()
      Method to get the Loggers instance from the calling thread.
      Returns:
      The current Loggers instance of the calling thread.
    • log

      public static void log(int level, String clazz, String msg)
      Logs an event to the logger of the current thread or thread group.
      Parameters:
      level - The log level.
      clazz - Event originates from class or logger name.
      msg - The message.
    • log

      public static void log(int level, String clazz, String msg, Object param)
      Logs an event to the logger of the current thread or thread group.
      Parameters:
      level - The log level.
      clazz - Event originates from class or logger name.
      msg - The message.
      param - The parameter, or null for none.
    • log

      public static void log(int level, String clazz, String msg, Object param1, Object param2)
      Logs an event to the logger of the current thread or thread group.
      Parameters:
      level - The log level.
      clazz - Event originates from class or logger name.
      msg - The message.
      param1 - The first parameter, or null for none.
      param2 - The second parameter, or null for none.
    • log

      public static void log(int level, String clazz, String msg, Object... params)
      Logs an event to the logger of the current thread or thread group.
      Parameters:
      level - The log level.
      clazz - Event originates from class or logger name.
      msg - The message.
      params - The list of parameters, or null for none.
    • logForced

      public static void logForced(int level, String clazz, String msg)
      Logs an event to the logger of the current thread or thread group.
      Parameters:
      level - The log level.
      clazz - Event originates from class or logger name.
      msg - The message.
    • logForced

      public static void logForced(int level, String clazz, String msg, Object param)
      Forces logging of an event to the logger of the current thread or thread group.
      Parameters:
      level - The log level.
      clazz - Event originates from class or logger name.
      msg - The message.
      param - The parameter, or null for none.
    • logForced

      public static void logForced(int level, String clazz, String msg, Object param1, Object param2)
      Forces logging of an event to the logger of the current thread or thread group.
      Parameters:
      level - The log level.
      clazz - Event originates from class or logger name.
      msg - The message.
      param1 - The first parameter, or null for none.
      param2 - The second parameter, or null for none.
    • logForced

      public static void logForced(int level, String clazz, String msg, Object... params)
      Forces logging of an event to the logger of the current thread or thread group.
      Parameters:
      level - The log level.
      clazz - Event originates from class or logger name.
      msg - The message.
      params - The list of parameters, or null for none.
    • getName

      public String getName()
      Gets the name of this logger.
      Returns:
      A String that is never null, but empty string.
    • setLogLevel

      public void setLogLevel(int level)
      Changes the log level.
      Parameters:
      level - The new level as:
      Throws:
      IllegalArgumentException - If the value is less than (0) zero or larger than (7) seven.
    • getLogLevel

      public int getLogLevel()
      Gets the log level.
      Returns:
      A value of:
    • logInternal

      public void logInternal(Thread thread, int level, String who, String msg, Object[] params)
      Logs an event, possibly using the redirector using this Loggers instance name and possible additional information.
      Parameters:
      thread - The thread logging, or null for current thread.
      level - The log level.
      who - Who is logging.
      msg - Message to log.
      params - The list of parameters, or null for none.
    • logInternalForced

      public void logInternalForced(Thread thread, int level, String who, String msg, Object[] params)
      Logs an event, possibly using the redirector using this Loggers instance name and possible additional information.
      Parameters:
      thread - The thread logging, or null for current thread.
      level - The log level.
      who - Who is logging.
      msg - Message to log.
      params - The list of parameters, or null for none.