Package logger

Class Logger

java.lang.Object
logger.Logger
All Implemented Interfaces:
Closeable, AutoCloseable

public class Logger
extends Object
implements Closeable, AutoCloseable
A simple logger for java.

The logger can log to standart output streams or to a .log file. When logging to the standart streams, there is an option to enable ANSI codes. When logging to a .log file, the logger will create a .log file with the given name if there is no .log file with the same name. The path to a folder can be specified to search for the .log file there.

The logger can log in 4 different levels:

  • INFO: used to log information.
  • DEBUG: used to log debugging information.
  • WARNING: used to log warnings.
  • ERROR: used to log errors.
  • Constructor Summary

    Constructors 
    Constructor Description
    Logger​(PrintStream printStream)
    Creates a logger which writes to the given print stream.
    Logger​(PrintStream printStream, boolean ansi)
    Creates a logger which writes to the given print stream.
    Logger​(PrintStream printStream, Locale locale)
    Creates a logger whhich writes to the given print stream.
    Logger​(PrintStream printStream, Locale locale, boolean ansi)  
    Logger​(String name)
    Creates a logger with the given name.
    Logger​(String name, boolean ansi)
    Creates a logger with the given name.
    Logger​(String name, Locale locale)
    Creates a logger with the given name.
    Logger​(String name, Locale locale, boolean ansi)
    Creates a logger with the given name.
    Logger​(String name, Locale locale, String path)
    Creates a logger with the given name.
    Logger​(String name, Locale locale, String path, boolean ansi)
    Creates a logger with the given name.
  • Method Summary

    Modifier and Type Method Description
    void close()
    Closes the logger.
    void debug​(boolean bool)
    Logs the boolean with a severity level of DEBUG.
    void debug​(boolean[] boolArray)
    Logs the boolean array with severity level of DEBUG.
    void debug​(byte byteInteger)
    Logs the byte with a severity level of DEBUG.
    void debug​(byte[] byteArray)
    Logs the byte array with severity level of DEBUG.
    void debug​(char character)
    Logs the char with a severity level of DEBUG.
    void debug​(char[] charArray)
    Logs the char array with severity level of DEBUG.
    void debug​(double fraction)
    Logs the double with a severity level of DEBUG.
    void debug​(double[] doubleArray)
    Logs the double array with severity level of DEBUG.
    void debug​(float floatFraction)
    Logs the float with a severity level of DEBUG.
    void debug​(float[] floatArray)
    Logs the float array with severity level of DEBUG.
    void debug​(int integer)
    Logs the int with a severity level of DEBUG.
    void debug​(int[] intArray)
    Logs the int array with severity level of DEBUG.
    void debug​(long longInteger)
    Logs the long with a severity level of DEBUG.
    void debug​(long[] longArray)
    Logs the long array with severity level of DEBUG.
    void debug​(short shortInteger)
    Logs the short with a severity level of DEBUG.
    void debug​(short[] shortArray)
    Logs the short array with severity level of DEBUG.
    void debug​(Object object)
    Logs the object with severity level of DEBUG.
    void debug​(Object[] objectArray)
    Logs the object array with severity level DEBUG.
    void debug​(Throwable throwable)
    Logs the throwable with severity level of DEBUG.
    void err​(boolean bool)
    Logs the boolean with a severity level of ERROR.
    void err​(boolean[] boolArray)
    Logs the boolean array with severity level of ERROR.
    void err​(byte byteInteger)
    Logs the byte with a severity level of ERROR.
    void err​(byte[] byteArray)
    Logs the byte array with severity level of ERROR.
    void err​(char character)
    Logs the char with a severity level of ERROR.
    void err​(char[] charArray)
    Logs the char array with severity level of ERROR.
    void err​(double fraction)
    Logs the double with a severity level of ERROR.
    void err​(double[] doubleArray)
    Logs the double array with severity level of ERROR.
    void err​(float floatFraction)
    Logs the float with a severity level of ERROR.
    void err​(float[] floatArray)
    Logs the float array with severity level of ERROR.
    void err​(int integer)
    Logs the int with a severity level of ERROR.
    void err​(int[] intArray)
    Logs the int array with severity level of ERROR.
    void err​(long longInteger)
    Logs the long with a severity level of ERROR.
    void err​(long[] longArray)
    Logs the long array with severity level of ERROR.
    void err​(short shortInteger)
    Logs the short with a severity level of ERROR.
    void err​(short[] shortArray)
    Logs the short array with severity level of ERROR.
    void err​(Object object)
    Logs the object with severity level of ERROR.
    void err​(Object[] objectArray)
    Logs the object array with severity level ERROR.
    void err​(Throwable throwable)
    Logs the throwable with severity level of ERROR.
    protected void finalize()
    Closes the logger if it is not already when the object is finalized.
    void info​(boolean bool)
    Logs the boolean with a severity level of INFO.
    void info​(boolean[] boolArray)
    Logs the boolean array with severity level of INFO.
    void info​(byte byteInteger)
    Logs the byte with a severity level of INFO.
    void info​(byte[] byteArray)
    Logs the byte array with severity level of INFO.
    void info​(char character)
    Logs the char with a severity level of INFO.
    void info​(char[] charArray)
    Logs the char array with severity level of INFO.
    void info​(double fraction)
    Logs the double with a severity level of INFO.
    void info​(double[] doubleArray)
    Logs the double array with severity level of INFO.
    void info​(float floatFraction)
    Logs the float with a severity level of INFO.
    void info​(float[] floatArray)
    Logs the float array with severity level of INFO.
    void info​(int integer)
    Logs the int with a severity level of INFO.
    void info​(int[] intArray)
    Logs the int array with severity level of INFO.
    void info​(long longInteger)
    Logs the long with a severity level of INFO.
    void info​(long[] longArray)
    Logs the long array with severity level of INFO.
    void info​(short shortInteger)
    Logs the short with a severity level of INFO.
    void info​(short[] shortArray)
    Logs the short array with severity level of INFO.
    void info​(Object object)
    Logs the object with severity level of INFO.
    void info​(Object[] objectArray)
    Logs the object array with severity level INFO.
    void info​(Throwable throwable)
    Logs the throwable with severity level of INFO.
    void warn​(boolean bool)
    Logs the boolean with a severity level of WARNING.
    void warn​(boolean[] boolArray)
    Logs the boolean array with severity level of WARNING.
    void warn​(byte byteInteger)
    Logs the byte with a severity level of WARNING.
    void warn​(byte[] byteArray)
    Logs the byte array with severity level of WARNING.
    void warn​(char character)
    Logs the char with a severity level of WARNING.
    void warn​(char[] charArray)
    Logs the char array with severity level of WARNING.
    void warn​(double fraction)
    Logs the double with a severity level of WARNING.
    void warn​(double[] doubleArray)
    Logs the double array with severity level of WARNING.
    void warn​(float floatFraction)
    Logs the float with a severity level of WARNING.
    void warn​(float[] floatArray)
    Logs the float array with severity level of WARNING.
    void warn​(int integer)
    Logs the int with a severity level of WARNING.
    void warn​(int[] intArray)
    Logs the int array with severity level of WARNING.
    void warn​(long longInteger)
    Logs the long with a severity level of WARNING.
    void warn​(long[] longArray)
    Logs the long array with severity level of WARNING.
    void warn​(short shortInteger)
    Logs the short with a severity level of WARNING.
    void warn​(short[] shortArray)
    Logs the short array with severity level of WARNING.
    void warn​(Object object)
    Logs the object with severity level of WARNING.
    void warn​(Object[] objectArray)
    Logs the object array with severity level WARNING.
    void warn​(Throwable throwable)
    Logs the throwable with severity level of WARNING.

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Logger

      public Logger​(String name)
      Creates a logger with the given name. The name is used to find the .log file where to log messages. If the file does not exist, it will be created.
      Parameters:
      name - The name of the logger.
    • Logger

      public Logger​(String name, boolean ansi)
      Creates a logger with the given name. The name is used to find the .log file where to log messages. If the file does not exist, it will be created.
      Parameters:
      name - The name of the logger.
      ansi - Whether or not to use ANSI text coloring.
    • Logger

      public Logger​(String name, Locale locale)
      Creates a logger with the given name. The name is used to find the .log file where to log messages. If the file does not exist, it will be created.
      Parameters:
      name - The name of the logger.
      locale - The locale of the machine. The locale is used to create the date.
      See Also:
      DateMaker
    • Logger

      public Logger​(String name, Locale locale, boolean ansi)
      Creates a logger with the given name. The name is used to find the .log file where to log messages. If the file does not exist, it will be created.
      Parameters:
      name - The name of the logger.
      locale - The locale of the machine. The locale is used to create the date.
      ansi - Whether or not to use ANSI text coloring.
      See Also:
      DateMaker
    • Logger

      public Logger​(String name, Locale locale, String path)
      Creates a logger with the given name. The name is used to find the .log file where to log messages. If the file does not exist, it will be created.
      Parameters:
      name - The name of the logger.
      locale - The locale of the machine. The locale is used to create the date.
      path - The path to the directory where to search for the .log file.
      See Also:
      DateMaker
    • Logger

      public Logger​(String name, Locale locale, String path, boolean ansi)
      Creates a logger with the given name. The name is used to find the .log file where to log messages. If the file does not exist, it will be created.
      Parameters:
      name - The name of the logger.
      locale - The locale of the machine. The locale is used to create the date.
      path - The path to the directory where to search for the .log file.
      ansi - Whether or not to use ANSI text coloring.
      See Also:
      DateMaker
    • Logger

      public Logger​(PrintStream printStream)
      Creates a logger which writes to the given print stream.
      Parameters:
      printStream - The print stream.
    • Logger

      public Logger​(PrintStream printStream, boolean ansi)
      Creates a logger which writes to the given print stream.
      Parameters:
      printStream - The print stream.
      ansi - Whether or not the logger should use ANSI colors.
    • Logger

      public Logger​(PrintStream printStream, Locale locale)
      Creates a logger whhich writes to the given print stream.
      Parameters:
      printStream - The print stream.
      locale - The locale of the machine. The locale is used to create the date.
    • Logger

      public Logger​(PrintStream printStream, Locale locale, boolean ansi)
  • Method Details

    • close

      public void close()
      Closes the logger. Once the logger is closed, it cannot be used again. it is recommended to close the logger at the end of execution
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • finalize

      protected void finalize() throws Throwable
      Closes the logger if it is not already when the object is finalized.
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • info

      public void info​(boolean bool)
      Logs the boolean with a severity level of INFO.
      Parameters:
      bool - The boolean.
    • info

      public void info​(byte byteInteger)
      Logs the byte with a severity level of INFO.
      Parameters:
      byteInteger - The byte.
    • info

      public void info​(short shortInteger)
      Logs the short with a severity level of INFO.
      Parameters:
      shortInteger - The short.
    • info

      public void info​(int integer)
      Logs the int with a severity level of INFO.
      Parameters:
      integer - The int.
    • info

      public void info​(long longInteger)
      Logs the long with a severity level of INFO.
      Parameters:
      longInteger - The long.
    • info

      public void info​(float floatFraction)
      Logs the float with a severity level of INFO.
      Parameters:
      floatFraction - The float.
    • info

      public void info​(double fraction)
      Logs the double with a severity level of INFO.
      Parameters:
      fraction - The double.
    • info

      public void info​(char character)
      Logs the char with a severity level of INFO.
      Parameters:
      character - The char.
    • info

      public void info​(Object object)
      Logs the object with severity level of INFO.
      Parameters:
      object - The object.
    • info

      public void info​(Throwable throwable)
      Logs the throwable with severity level of INFO.
      Parameters:
      throwable - The throwable.
    • info

      public void info​(boolean[] boolArray)
      Logs the boolean array with severity level of INFO.
      Parameters:
      boolArray - The boolean array.
    • info

      public void info​(byte[] byteArray)
      Logs the byte array with severity level of INFO.
      Parameters:
      byteArray - The byte array.
    • info

      public void info​(short[] shortArray)
      Logs the short array with severity level of INFO.
      Parameters:
      shortArray - The short array.
    • info

      public void info​(int[] intArray)
      Logs the int array with severity level of INFO.
      Parameters:
      intArray - The int array.
    • info

      public void info​(long[] longArray)
      Logs the long array with severity level of INFO.
      Parameters:
      longArray - The long array.
    • info

      public void info​(float[] floatArray)
      Logs the float array with severity level of INFO.
      Parameters:
      floatArray - The float array.
    • info

      public void info​(double[] doubleArray)
      Logs the double array with severity level of INFO.
      Parameters:
      doubleArray - The double array.
    • info

      public void info​(char[] charArray)
      Logs the char array with severity level of INFO.
      Parameters:
      charArray - The char array.
    • info

      public void info​(Object[] objectArray)
      Logs the object array with severity level INFO.
      Parameters:
      objectArray - The object array.
    • debug

      public void debug​(boolean bool)
      Logs the boolean with a severity level of DEBUG.
      Parameters:
      bool - The boolean.
    • debug

      public void debug​(byte byteInteger)
      Logs the byte with a severity level of DEBUG.
      Parameters:
      byteInteger - The byte.
    • debug

      public void debug​(short shortInteger)
      Logs the short with a severity level of DEBUG.
      Parameters:
      shortInteger - The short.
    • debug

      public void debug​(int integer)
      Logs the int with a severity level of DEBUG.
      Parameters:
      integer - The int.
    • debug

      public void debug​(long longInteger)
      Logs the long with a severity level of DEBUG.
      Parameters:
      longInteger - The long.
    • debug

      public void debug​(float floatFraction)
      Logs the float with a severity level of DEBUG.
      Parameters:
      floatFraction - The float.
    • debug

      public void debug​(double fraction)
      Logs the double with a severity level of DEBUG.
      Parameters:
      fraction - The double.
    • debug

      public void debug​(char character)
      Logs the char with a severity level of DEBUG.
      Parameters:
      character - The char.
    • debug

      public void debug​(Object object)
      Logs the object with severity level of DEBUG.
      Parameters:
      object - The object.
    • debug

      public void debug​(Throwable throwable)
      Logs the throwable with severity level of DEBUG.
      Parameters:
      throwable - The throwable.
    • debug

      public void debug​(boolean[] boolArray)
      Logs the boolean array with severity level of DEBUG.
      Parameters:
      boolArray - The boolean array.
    • debug

      public void debug​(byte[] byteArray)
      Logs the byte array with severity level of DEBUG.
      Parameters:
      byteArray - The byte array.
    • debug

      public void debug​(short[] shortArray)
      Logs the short array with severity level of DEBUG.
      Parameters:
      shortArray - The short array.
    • debug

      public void debug​(int[] intArray)
      Logs the int array with severity level of DEBUG.
      Parameters:
      intArray - The int array.
    • debug

      public void debug​(long[] longArray)
      Logs the long array with severity level of DEBUG.
      Parameters:
      longArray - The long array.
    • debug

      public void debug​(float[] floatArray)
      Logs the float array with severity level of DEBUG.
      Parameters:
      floatArray - The float array.
    • debug

      public void debug​(double[] doubleArray)
      Logs the double array with severity level of DEBUG.
      Parameters:
      doubleArray - The double array.
    • debug

      public void debug​(char[] charArray)
      Logs the char array with severity level of DEBUG.
      Parameters:
      charArray - The char array.
    • debug

      public void debug​(Object[] objectArray)
      Logs the object array with severity level DEBUG.
      Parameters:
      objectArray - The object array.
    • warn

      public void warn​(boolean bool)
      Logs the boolean with a severity level of WARNING.
      Parameters:
      bool - The boolean.
    • warn

      public void warn​(byte byteInteger)
      Logs the byte with a severity level of WARNING.
      Parameters:
      byteInteger - The byte.
    • warn

      public void warn​(short shortInteger)
      Logs the short with a severity level of WARNING.
      Parameters:
      shortInteger - The short.
    • warn

      public void warn​(int integer)
      Logs the int with a severity level of WARNING.
      Parameters:
      integer - The int.
    • warn

      public void warn​(long longInteger)
      Logs the long with a severity level of WARNING.
      Parameters:
      longInteger - The long.
    • warn

      public void warn​(float floatFraction)
      Logs the float with a severity level of WARNING.
      Parameters:
      floatFraction - The float.
    • warn

      public void warn​(double fraction)
      Logs the double with a severity level of WARNING.
      Parameters:
      fraction - The double.
    • warn

      public void warn​(char character)
      Logs the char with a severity level of WARNING.
      Parameters:
      character - The char.
    • warn

      public void warn​(Object object)
      Logs the object with severity level of WARNING.
      Parameters:
      object - The object.
    • warn

      public void warn​(Throwable throwable)
      Logs the throwable with severity level of WARNING.
      Parameters:
      throwable - The throwable.
    • warn

      public void warn​(boolean[] boolArray)
      Logs the boolean array with severity level of WARNING.
      Parameters:
      boolArray - The boolean array.
    • warn

      public void warn​(byte[] byteArray)
      Logs the byte array with severity level of WARNING.
      Parameters:
      byteArray - The byte array.
    • warn

      public void warn​(short[] shortArray)
      Logs the short array with severity level of WARNING.
      Parameters:
      shortArray - The short array.
    • warn

      public void warn​(int[] intArray)
      Logs the int array with severity level of WARNING.
      Parameters:
      intArray - The int array.
    • warn

      public void warn​(long[] longArray)
      Logs the long array with severity level of WARNING.
      Parameters:
      longArray - The long array.
    • warn

      public void warn​(float[] floatArray)
      Logs the float array with severity level of WARNING.
      Parameters:
      floatArray - The float array.
    • warn

      public void warn​(double[] doubleArray)
      Logs the double array with severity level of WARNING.
      Parameters:
      doubleArray - The double array.
    • warn

      public void warn​(char[] charArray)
      Logs the char array with severity level of WARNING.
      Parameters:
      charArray - The char array.
    • warn

      public void warn​(Object[] objectArray)
      Logs the object array with severity level WARNING.
      Parameters:
      objectArray - The object array.
    • err

      public void err​(boolean bool)
      Logs the boolean with a severity level of ERROR.
      Parameters:
      bool - The boolean.
    • err

      public void err​(byte byteInteger)
      Logs the byte with a severity level of ERROR.
      Parameters:
      byteInteger - The byte.
    • err

      public void err​(short shortInteger)
      Logs the short with a severity level of ERROR.
      Parameters:
      shortInteger - The short.
    • err

      public void err​(int integer)
      Logs the int with a severity level of ERROR.
      Parameters:
      integer - The int.
    • err

      public void err​(long longInteger)
      Logs the long with a severity level of ERROR.
      Parameters:
      longInteger - The long.
    • err

      public void err​(float floatFraction)
      Logs the float with a severity level of ERROR.
      Parameters:
      floatFraction - The float.
    • err

      public void err​(double fraction)
      Logs the double with a severity level of ERROR.
      Parameters:
      fraction - The double.
    • err

      public void err​(char character)
      Logs the char with a severity level of ERROR.
      Parameters:
      character - The char.
    • err

      public void err​(Object object)
      Logs the object with severity level of ERROR.
      Parameters:
      object - The object.
    • err

      public void err​(Throwable throwable)
      Logs the throwable with severity level of ERROR.
      Parameters:
      throwable - The throwable.
    • err

      public void err​(boolean[] boolArray)
      Logs the boolean array with severity level of ERROR.
      Parameters:
      boolArray - The boolean array.
    • err

      public void err​(byte[] byteArray)
      Logs the byte array with severity level of ERROR.
      Parameters:
      byteArray - The byte array.
    • err

      public void err​(short[] shortArray)
      Logs the short array with severity level of ERROR.
      Parameters:
      shortArray - The short array.
    • err

      public void err​(int[] intArray)
      Logs the int array with severity level of ERROR.
      Parameters:
      intArray - The int array.
    • err

      public void err​(long[] longArray)
      Logs the long array with severity level of ERROR.
      Parameters:
      longArray - The long array.
    • err

      public void err​(float[] floatArray)
      Logs the float array with severity level of ERROR.
      Parameters:
      floatArray - The float array.
    • err

      public void err​(double[] doubleArray)
      Logs the double array with severity level of ERROR.
      Parameters:
      doubleArray - The double array.
    • err

      public void err​(char[] charArray)
      Logs the char array with severity level of ERROR.
      Parameters:
      charArray - The char array.
    • err

      public void err​(Object[] objectArray)
      Logs the object array with severity level ERROR.
      Parameters:
      objectArray - The object array.