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 voidclose()Closes the logger.voiddebug(boolean bool)Logs the boolean with a severity level of DEBUG.voiddebug(boolean[] boolArray)Logs the boolean array with severity level of DEBUG.voiddebug(byte byteInteger)Logs the byte with a severity level of DEBUG.voiddebug(byte[] byteArray)Logs the byte array with severity level of DEBUG.voiddebug(char character)Logs the char with a severity level of DEBUG.voiddebug(char[] charArray)Logs the char array with severity level of DEBUG.voiddebug(double fraction)Logs the double with a severity level of DEBUG.voiddebug(double[] doubleArray)Logs the double array with severity level of DEBUG.voiddebug(float floatFraction)Logs the float with a severity level of DEBUG.voiddebug(float[] floatArray)Logs the float array with severity level of DEBUG.voiddebug(int integer)Logs the int with a severity level of DEBUG.voiddebug(int[] intArray)Logs the int array with severity level of DEBUG.voiddebug(long longInteger)Logs the long with a severity level of DEBUG.voiddebug(long[] longArray)Logs the long array with severity level of DEBUG.voiddebug(short shortInteger)Logs the short with a severity level of DEBUG.voiddebug(short[] shortArray)Logs the short array with severity level of DEBUG.voiddebug(Object object)Logs the object with severity level of DEBUG.voiddebug(Object[] objectArray)Logs the object array with severity level DEBUG.voiddebug(Throwable throwable)Logs the throwable with severity level of DEBUG.voiderr(boolean bool)Logs the boolean with a severity level of ERROR.voiderr(boolean[] boolArray)Logs the boolean array with severity level of ERROR.voiderr(byte byteInteger)Logs the byte with a severity level of ERROR.voiderr(byte[] byteArray)Logs the byte array with severity level of ERROR.voiderr(char character)Logs the char with a severity level of ERROR.voiderr(char[] charArray)Logs the char array with severity level of ERROR.voiderr(double fraction)Logs the double with a severity level of ERROR.voiderr(double[] doubleArray)Logs the double array with severity level of ERROR.voiderr(float floatFraction)Logs the float with a severity level of ERROR.voiderr(float[] floatArray)Logs the float array with severity level of ERROR.voiderr(int integer)Logs the int with a severity level of ERROR.voiderr(int[] intArray)Logs the int array with severity level of ERROR.voiderr(long longInteger)Logs the long with a severity level of ERROR.voiderr(long[] longArray)Logs the long array with severity level of ERROR.voiderr(short shortInteger)Logs the short with a severity level of ERROR.voiderr(short[] shortArray)Logs the short array with severity level of ERROR.voiderr(Object object)Logs the object with severity level of ERROR.voiderr(Object[] objectArray)Logs the object array with severity level ERROR.voiderr(Throwable throwable)Logs the throwable with severity level of ERROR.protected voidfinalize()Closes the logger if it is not already when the object is finalized.voidinfo(boolean bool)Logs the boolean with a severity level of INFO.voidinfo(boolean[] boolArray)Logs the boolean array with severity level of INFO.voidinfo(byte byteInteger)Logs the byte with a severity level of INFO.voidinfo(byte[] byteArray)Logs the byte array with severity level of INFO.voidinfo(char character)Logs the char with a severity level of INFO.voidinfo(char[] charArray)Logs the char array with severity level of INFO.voidinfo(double fraction)Logs the double with a severity level of INFO.voidinfo(double[] doubleArray)Logs the double array with severity level of INFO.voidinfo(float floatFraction)Logs the float with a severity level of INFO.voidinfo(float[] floatArray)Logs the float array with severity level of INFO.voidinfo(int integer)Logs the int with a severity level of INFO.voidinfo(int[] intArray)Logs the int array with severity level of INFO.voidinfo(long longInteger)Logs the long with a severity level of INFO.voidinfo(long[] longArray)Logs the long array with severity level of INFO.voidinfo(short shortInteger)Logs the short with a severity level of INFO.voidinfo(short[] shortArray)Logs the short array with severity level of INFO.voidinfo(Object object)Logs the object with severity level of INFO.voidinfo(Object[] objectArray)Logs the object array with severity level INFO.voidinfo(Throwable throwable)Logs the throwable with severity level of INFO.voidwarn(boolean bool)Logs the boolean with a severity level of WARNING.voidwarn(boolean[] boolArray)Logs the boolean array with severity level of WARNING.voidwarn(byte byteInteger)Logs the byte with a severity level of WARNING.voidwarn(byte[] byteArray)Logs the byte array with severity level of WARNING.voidwarn(char character)Logs the char with a severity level of WARNING.voidwarn(char[] charArray)Logs the char array with severity level of WARNING.voidwarn(double fraction)Logs the double with a severity level of WARNING.voidwarn(double[] doubleArray)Logs the double array with severity level of WARNING.voidwarn(float floatFraction)Logs the float with a severity level of WARNING.voidwarn(float[] floatArray)Logs the float array with severity level of WARNING.voidwarn(int integer)Logs the int with a severity level of WARNING.voidwarn(int[] intArray)Logs the int array with severity level of WARNING.voidwarn(long longInteger)Logs the long with a severity level of WARNING.voidwarn(long[] longArray)Logs the long array with severity level of WARNING.voidwarn(short shortInteger)Logs the short with a severity level of WARNING.voidwarn(short[] shortArray)Logs the short array with severity level of WARNING.voidwarn(Object object)Logs the object with severity level of WARNING.voidwarn(Object[] objectArray)Logs the object array with severity level WARNING.voidwarn(Throwable throwable)Logs the throwable with severity level of WARNING.
-
Constructor Details
-
Logger
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
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
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
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
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
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
Creates a logger which writes to the given print stream.- Parameters:
printStream- The print stream.
-
Logger
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
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
-
-
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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
finalize
Closes the logger if it is not already when the object is finalized. -
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
Logs the object with severity level of INFO.- Parameters:
object- The object.
-
info
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
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
Logs the object with severity level of DEBUG.- Parameters:
object- The object.
-
debug
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
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
Logs the object with severity level of WARNING.- Parameters:
object- The object.
-
warn
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
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
Logs the object with severity level of ERROR.- Parameters:
object- The object.
-
err
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
Logs the object array with severity level ERROR.- Parameters:
objectArray- The object array.
-