Package com.iizix

Class Loggers


  • public class Loggers
    extends java.lang.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 TypeFieldDescription
      static java.lang.StringINDENT
      The indent string used when parameters are on new lines.
      static java.lang.StringprependString
      The string that is prepended to all logged messages when written to System.out when no ILoggerRedirector is present.
    • Constructor Summary

      Constructors 
      ConstructorDescription
      Loggers()
      Constructs a Loggers instance, without name.
      Loggers​(java.lang.String name)
      Constructs a Loggers instance with the specified name.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      static java.lang.ThreadcreateThread​(java.lang.Runnable r, java.lang.String name)
      Creates a new Thread with a specific name and an associated logger.
      static java.lang.ThreadcreateThread​(java.lang.Runnable r, java.lang.String name, java.lang.Object o)
      Creates a new Thread with a specific name and an associated logger along with an attached thread object, typically an instance of SessionInfo.
      static java.lang.ThreadcreateThread​(java.lang.ThreadGroup tg, java.lang.Runnable r, java.lang.String name)
      Creates a new Thread with a specific name and an associated logger.
      static java.lang.ThreadcreateThread​(java.lang.ThreadGroup tg, java.lang.Runnable r, java.lang.String name, java.lang.Object o)
      Creates a new Thread with a specific name and an associated logger.
      static java.lang.ThreadGroupcreateThreadGroup​(java.lang.String name)
      Creates a new Thread Group with a specific name and an associated logger.
      static java.lang.ThreadGroupcreateThreadGroup​(java.lang.String name, java.lang.Object o)
      Creates a new Thread Group with a specific name and an associated logger.
      static java.lang.ThreadGroupcreateThreadGroup​(java.lang.ThreadGroup parent, java.lang.String name)
      Creates a new Thread Group with a specific name and an associated logger.
      static java.lang.ThreadGroupcreateThreadGroup​(java.lang.ThreadGroup parent, java.lang.String name, java.lang.Object o)
      Creates a new Thread Group with a specific name and an associated logger.
      static java.lang.StringdeepToString​(java.lang.Object[] o)
      Returns a string representation of the "deep contents" of the specified array.
      static LoggersgetCurrent()
      Method to get the Loggers instance from the calling thread.
      static LoggersgetDefault()
      Gets the default instance of the Loggers.
      static java.lang.StringgetLevelString​(int level)
      Gets the level string.
      static java.lang.StringgetLevelStringFormatted​(int level)
      Gets the formatted level string that is adjusted with spaces and surrounded with [].
      java.lang.StringgetName()
      Gets the name of this logger.
      static ILoggerRedirectorgetRedirector()
      Sets the log redirector used when redirecting an event from client to server.
      static java.lang.ObjectgetTObject()
      Gets the thread object or thread group object for the calling thread.
      static voidlog​(int level, java.lang.String clazz, java.lang.String msg, java.lang.Object[] params)
      Logs an event.
      static booleansetRedirector​(ILoggerRedirector newRedirector)
      Sets the log redirector used when redirecting an event from client to server.
      static java.lang.StringtoString​(java.lang.Object o)
      Cracks the "Object" using toString, or special handling if it's an array or throwable.
      • Methods inherited from class java.lang.Object

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

      • INDENT

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

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

      • Loggers

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

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

      • getLevelString

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

        public static java.lang.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.
        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,
                               java.lang.String clazz,
                               java.lang.String msg,
                               java.lang.Object[] params)
        Logs an event.
        Parameters:
        level - The log level.
        clazz - Event originates from class.
        msg - The message.
        params - The list of parameters, or null for none.
      • createThread

        public static java.lang.Thread createThread​(java.lang.Runnable r,
                                                    java.lang.String name)
        Creates a new Thread with a specific name and an associated logger.
        Parameters:
        r - The Runnable.
        name - The name of the thread and the Loggers instance.
        Returns:
        A new Loggers enabled thread.
      • createThread

        public static java.lang.Thread createThread​(java.lang.Runnable r,
                                                    java.lang.String name,
                                                    java.lang.Object o)
        Creates a new Thread with a specific name and an associated logger along with an attached thread object, typically an instance of SessionInfo.
        Parameters:
        r - The Runnable.
        name - The name of the thread and the Loggers instance.
        o - An object or null for none.
        Returns:
        A new Loggers enabled thread.
      • createThread

        public static java.lang.Thread createThread​(java.lang.ThreadGroup tg,
                                                    java.lang.Runnable r,
                                                    java.lang.String name)
        Creates a new Thread with a specific name and an associated logger.
        Parameters:
        tg - The ThreadGroup.
        r - The Runnable.
        name - The name of the thread and the Loggers instance.
        Returns:
        A new Loggers enabled thread.
      • createThread

        public static java.lang.Thread createThread​(java.lang.ThreadGroup tg,
                                                    java.lang.Runnable r,
                                                    java.lang.String name,
                                                    java.lang.Object o)
        Creates a new Thread with a specific name and an associated logger.
        Parameters:
        tg - The ThreadGroup.
        r - The Runnable.
        name - The name of the thread and the Loggers instance.
        o - An object or null for none.
        Returns:
        A new Loggers enabled thread.
      • createThreadGroup

        public static java.lang.ThreadGroup createThreadGroup​(java.lang.String name)
        Creates a new Thread Group with a specific name and an associated logger.
        Parameters:
        name - The name of the thread and the Loggers instance.
        Returns:
        A new Loggers enabled thread group.
      • createThreadGroup

        public static java.lang.ThreadGroup createThreadGroup​(java.lang.String name,
                                                              java.lang.Object o)
        Creates a new Thread Group with a specific name and an associated logger.
        Parameters:
        name - The name of the thread and the Loggers instance.
        o - An object or null for none.
        Returns:
        A new Loggers enabled thread group.
      • createThreadGroup

        public static java.lang.ThreadGroup createThreadGroup​(java.lang.ThreadGroup parent,
                                                              java.lang.String name)
        Creates a new Thread Group with a specific name and an associated logger.
        Parameters:
        parent - The parent thread group.
        name - The name of the thread and the Loggers instance.
        Returns:
        A new Loggers enabled thread group.
      • createThreadGroup

        public static java.lang.ThreadGroup createThreadGroup​(java.lang.ThreadGroup parent,
                                                              java.lang.String name,
                                                              java.lang.Object o)
        Creates a new Thread Group with a specific name and an associated logger.
        Parameters:
        parent - The parent thread group.
        name - The name of the thread and the Loggers instance.
        o - An object or null for none.
        Returns:
        A new Loggers enabled thread group.
      • getTObject

        public static java.lang.Object getTObject()
        Gets the thread object or thread group object for the calling thread. If the thread has been created in this class using createThread, but without a thread object (or if it is null), the thread group (and parent thread groups) will be searched for such an object.
        Returns:
        Object The object of the thread or thread group, or null for none.
      • getName

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

        public static java.lang.String toString​(java.lang.Object o)
        Cracks the "Object" using toString, or special handling if it's an array or throwable.
        Parameters:
        o - The Object to expand.
        Returns:
        The expanded string of the object.
      • deepToString

        public static java.lang.String deepToString​(java.lang.Object[] o)
        Returns a string representation of the "deep contents" of the specified array. If the array contains other arrays as elements, the string representation contains their contents and so on. This method is designed for converting multidimensional arrays to strings.

        The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are converted to strings as by ILog.toString(Object), unless they are themselves arrays.

        If an element e is an array of a primitive type, it is converted to a string as by invoking the appropriate overloading of Arrays.toString(e). If an element e is an array of a reference type, it is converted to a string as by invoking this method recursively.

        To avoid infinite recursion, if the specified array contains itself as an element, or contains an indirect reference to itself through one or more levels of arrays, the self-reference is converted to the string "[...]". For example, an array containing only a reference to itself would be rendered as "[[...]]".

        This method returns "null" if the specified array is null.

        Parameters:
        o - The array whose string representation to return.
        Returns:
        a string representation of a.