Package ch.k43.util

Klasse KLog

java.lang.Object
ch.k43.util.KLog

public class KLog extends Object
Static class for simple logging.

Notes:
- The logging framework is automatically initialized during the first call.
- To enable logging, the file KLog.properties must be present in the current directory.
- The syntax follows the rules set by the java.util.logging framework (Java Logging API).
- This class only supports Java Logger levels FINEST, INFO and SEVERE thru KLog.debug(), KLog.info() and KLog.error().
- The message text is prepended with the called code location (e.g. main[1]:Test:main:15) and delimited by KLog.DELIMITER.

 Examples:
 KLog.info("Program started");
 KLog.debug("Any debugging message);
 
 Output:
 2024-06-23T09:11:02.628 D main[1]:ch.k43.util.KLog:open:466                            ===== Application started 2024-06-23T09:11:02.612 =====
 2024-06-23T09:11:02.629 D main[1]:ch.k43.util.KLog:open:468                            Java Utility Package (Freeware) ch.k43.util Version 2024.06.22
 2024-06-23T09:11:02.652 D main[1]:ch.k43.util.KLog:open:473                            Host ab-macbook-pro (10.0.0.105)
 2024-06-23T09:11:02.653 D main[1]:ch.k43.util.KLog:open:474                            OS platform Mac OS X (14.5)
 2024-06-23T09:11:02.653 D main[1]:ch.k43.util.KLog:open:475                            Java version 17 (OpenJDK 64-Bit Server VM - Eclipse Adoptium)
 2024-06-23T09:11:02.655 D main[1]:ch.k43.util.KLog:open:479                            Java heap maximum 16.00 GB, current 1.00 GB, used 4.83 MB, free 1019.17 MB
 2024-06-23T09:11:02.655 D main[1]:ch.k43.util.KLog:open:483                            Java locale de/CH, time UTC +02:00
 2024-06-23T09:11:02.655 D main[1]:ch.k43.util.KLog:open:486                            Java classpath ../bin/:../lib/k43.util.jar
 2024-06-23T09:11:02.656 I main[1]:Test:main:21                                         Program started
 2024-06-23T09:11:02.656 D main[1]:Test:main:22                                         Any debugging message
 
  • Feldübersicht

    Felder
    Modifizierer und Typ
    Feld
    Beschreibung
    static final String
    KLog properties file name
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    static void
    abort(boolean argExpression, String argMessage)
    Log error message if expression is true and throws an unchecked RuntimeException.
    static void
    abort(String argMessage)
    Log error message and throws an unchecked RuntimeException.
    static void
    argException(boolean argExpression, String argMessage)
    Log error message if expression evaluates true and throw an unchecked exception IllegalArgumentException.
    static void
    Close the logging.
    static void
    debug(String argMessage)
    Write log message of level FINEST.
    static void
    error(boolean argExpression, String argMessage)
    Log error message if expression is true.
    static void
    error(Exception argException)
    Log formatted exception with stack trace.
    static void
    error(String argMessage)
    Log error message.
    static void
    error(String argMessage, Exception argException)
    Log message and exception with stack trace.
    static Level
    Get logger level.
    static void
    info(String argMessage)
    Write log message of level INFO.
    static boolean
    Check if logging is active.
    static boolean
    Check if logger is at level FINEST.
    static boolean
    Check if logger is at level SEVERE
    static boolean
    Check if logger is at level INFO.
    static boolean
    Check if logger is at level OFF.
    static void
    Reset logger level to the configured level in KLog.properties
    static void
    setLevel(Level argLevel)
    Set logger level
    static void
    Set logger to debug level (FINEST)
    static void
    Set logger to error level (SEVERE)
    static void
    Set logger to info level (INFO)
    static void
    Set logger off (OFF)
    String representation of object.

    Von Klasse geerbte Methoden java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Felddetails

  • Methodendetails

    • abort

      public static void abort(boolean argExpression, String argMessage)
      Log error message if expression is true and throws an unchecked RuntimeException.
      Parameter:
      argExpression - Any expression
      argMessage - Message to be logged
    • abort

      public static void abort(String argMessage)
      Log error message and throws an unchecked RuntimeException.
      Parameter:
      argMessage - Message to be logged
    • argException

      public static void argException(boolean argExpression, String argMessage)
      Log error message if expression evaluates true and throw an unchecked exception IllegalArgumentException.
      Parameter:
      argExpression - Any expression
      argMessage - Message to be logged and used as exception
      Löst aus:
      IllegalArgumentException - Explicit exception
      Seit:
      2024.05.17
    • close

      public static void close()
      Close the logging.
    • debug

      public static void debug(String argMessage)
      Write log message of level FINEST.
      Parameter:
      argMessage - Message to be written
    • error

      public static void error(boolean argExpression, String argMessage)
      Log error message if expression is true.
      Parameter:
      argExpression - True/False Any expression
      argMessage - Message to be logged
    • error

      public static void error(Exception argException)
      Log formatted exception with stack trace.
      Parameter:
      argException - Exception to be formatted
    • error

      public static void error(String argMessage)
      Log error message.
      Parameter:
      argMessage - Message to be written
    • error

      public static void error(String argMessage, Exception argException)
      Log message and exception with stack trace.
      Parameter:
      argMessage - Message to be written
      argException - Optional exception to be formatted
    • getLevel

      public static Level getLevel()
      Get logger level.
      Gibt zurück:
      Logging level
      Seit:
      2024.06.16
    • info

      public static void info(String argMessage)
      Write log message of level INFO.
      Parameter:
      argMessage - Message to be written
    • isActive

      public static boolean isActive()
      Check if logging is active.
      Gibt zurück:
      True if logging is initialized and active, false otherwise
    • isLevelDebug

      public static boolean isLevelDebug()
      Check if logger is at level FINEST.
      Gibt zurück:
      True if level matches, false otherwise
    • isLevelError

      public static boolean isLevelError()
      Check if logger is at level SEVERE
      Gibt zurück:
      True if level matches, false otherwise
    • isLevelInfo

      public static boolean isLevelInfo()
      Check if logger is at level INFO.
      Gibt zurück:
      True if level matches, false otherwise
    • isLevelOff

      public static boolean isLevelOff()
      Check if logger is at level OFF.
      Gibt zurück:
      True if level matches, false otherwise
    • resetLevel

      public static void resetLevel()
      Reset logger level to the configured level in KLog.properties
      Seit:
      2024.05.25
    • setLevel

      public static void setLevel(Level argLevel)
      Set logger level
      Parameter:
      argLevel - Logging level to set
      Seit:
      2024.06.16
    • setLevelDebug

      public static void setLevelDebug()
      Set logger to debug level (FINEST)
      Seit:
      2024.05.25
    • setLevelError

      public static void setLevelError()
      Set logger to error level (SEVERE)
      Seit:
      2024.05.25
    • setLevelInfo

      public static void setLevelInfo()
      Set logger to info level (INFO)
      Seit:
      2024.05.25
    • setLevelOff

      public static void setLevelOff()
      Set logger off (OFF)
      Seit:
      2024.05.25
    • toString

      public String toString()
      String representation of object.
      Setzt außer Kraft:
      toString in Klasse Object
      Seit:
      2024.08.23