Class KLog
java.lang.Object
ch.k43.util.KLog
Static class for simple logging.
Notes:
- To enable logging, the file KLog.properties must be in the current directory or set thru -DKLogPropertyFile.
- 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().
Example:
KLog.info("Program started at {}", new Date());
KLog.debug("Any debugging message");
Output:
2025-02-18T08:18:18.477 D main[1]:ch.k43.util.KLog:clinit:121 ===== Application started 2025-02-18T08:18:18.456 =====
2025-02-18T08:18:18.477 D main[1]:ch.k43.util.KLog:clinit:122 Java Utility Package (Freeware) Version 2025.02.17
2025-02-18T08:18:18.477 D main[1]:ch.k43.util.KLog:clinit:123 Homepage java-util.k43.ch - Please send any feedback to andy.brunner@k43.ch
2025-02-18T08:18:18.477 D main[1]:ch.k43.util.KLog:clinit:126 KLog properties read from file KLog.properties
2025-02-18T08:18:18.518 D main[1]:ch.k43.util.KLog:clinit:134 Network host ab-macbook-pro (10.0.0.100)
2025-02-18T08:18:18.518 D main[1]:ch.k43.util.KLog:clinit:138 OS platform Mac OS X Version 15.3.1/aarch64
2025-02-18T08:18:18.519 D main[1]:ch.k43.util.KLog:clinit:143 OS disk space total 3.63 TiB, free 2.25 TiB, usable 2.25 TiB
2025-02-18T08:18:18.519 D main[1]:ch.k43.util.KLog:clinit:149 Java version 23 (Java HotSpot(TM) 64-Bit Server VM - Oracle Corporation)
2025-02-18T08:18:18.519 D main[1]:ch.k43.util.KLog:clinit:154 Java directory /Library/Java/JavaVirtualMachines/graalvm-jdk-23.0.1+11.1/Contents/Home
2025-02-18T08:18:18.519 D main[1]:ch.k43.util.KLog:clinit:159 Java CPUs 10, de/CH, UTF-8, UTC +01:00 (Europe/Zurich)
2025-02-18T08:18:18.520 D main[1]:ch.k43.util.KLog:clinit:169 Java heap maximum 16.00 GiB, current 1.01 GiB, used 8.98 MiB, free 1023.02 MiB
2025-02-18T08:18:18.520 D main[1]:ch.k43.util.KLog:clinit:176 Java classpath ../bin/:../lib/angus-mail-2.0.3.jar:../lib/jakarta.mail-api-2.1.3.jar:../lib/org.json.20230618.jar:../lib/h2-2.2.224.jar:../lib/jakarta.activation-api-2.1.3.jar:../lib/angus-activation-2.0.2.jar
2025-02-18T08:18:18.520 D main[1]:ch.k43.util.KLog:clinit:180 User andybrunner, language de, directory /Users/andybrunner/
2025-02-18T08:18:18.520 D main[1]:ch.k43.util.KLog:clinit:186 Current directory /Users/andybrunner/Documents/Eclipse-Workspace/ch.k43.util/src/
2025-02-18T08:18:18.521 D main[1]:ch.k43.util.KLog:clinit:190 Temporary directory /var/folders/9s/tbyqn_vn7bs9rf3f1rc2jpxw0000gn/T/
2025-02-18T08:18:18.521 D main[1]:ch.k43.util.KLog:clinit:194 KLog initialization completed (86 ms)
2025-02-18T08:18:18.527 I main[1]:Test:main:10 Program started at Tue Feb 18 08:18:18 CET 2025
2025-02-18T08:18:18.527 D main[1]:Test:main:11 Any debugging message
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidLog error message if expression is true and throws an unchecked RuntimeException.static voidLog error message and throws an unchecked RuntimeException.static voidLog error message and throws an unchecked RuntimeException.static voidargException(boolean argExpression, String argMessage, Object... argObjects) Log error message if expression evaluates true and throw an unchecked exception IllegalArgumentException.static voidargException(String argMessage, Object... argObjects) Log error message and throw an unchecked exception IllegalArgumentException.static voidclose()Close the logging.static voidLog debug message if expression is true.static voidWrite log message of level FINEST.static voidLog error message if expression is true.static voidLog formatted exception with stack trace.static voidLog message and exception with stack trace.static voidLog error message.static LevelgetLevel()Get logger level.static voidLog message if expression is true.static voidWrite log message of level INFO.static booleanisActive()Check if logging is active.static booleanCheck if logger is in debug mode (level FINEST).static booleanCheck if logger is in debug mode (level SEVERE).static booleanCheck if logger is in debug mode (level INFO).static booleanCheck if logger is in debug mode (level OFF).static voidReset logger level to the configured level in KLog.propertiesstatic voidSet logger levelstatic voidSet logger to debug level (FINEST)static voidSet logger to error level (SEVERE)static voidSet logger to info level (INFO)static voidSet logger off (OFF)toString()String representation of object.
-
Method Details
-
abort
Log error message if expression is true and throws an unchecked RuntimeException.- Parameters:
argExpression- Any expressionargMessage- Message to be loggedargObjects- Optional arguments for {} parameters- Throws:
RuntimeException- Explicit exception
-
abort
Log error message and throws an unchecked RuntimeException.- Parameters:
argException- Exception to be logged- Throws:
RuntimeException- Explicit exception- Since:
- 2025.05.19
-
abort
Log error message and throws an unchecked RuntimeException.- Parameters:
argMessage- Message to be loggedargObjects- Optional arguments for {} parameters- Throws:
RuntimeException- Explicit exception
-
argException
Log error message if expression evaluates true and throw an unchecked exception IllegalArgumentException.- Parameters:
argExpression- Any expressionargMessage- Message to be logged and used as exceptionargObjects- Optional arguments for {} parameters- Throws:
IllegalArgumentException- Explicit exception- Since:
- 2024.05.17
-
argException
Log error message and throw an unchecked exception IllegalArgumentException.- Parameters:
argMessage- Message to be logged and used as exceptionargObjects- Optional arguments for {} parameters- Throws:
IllegalArgumentException- Explicit exception- Since:
- 2025.03.16
-
close
public static void close()Close the logging. -
debug
-
debug
-
error
-
error
Log formatted exception with stack trace.- Parameters:
argException- Exception to be formatted
-
error
-
error
-
getLevel
-
info
-
info
-
isActive
public static boolean isActive()Check if logging is active.- Returns:
- True if logging is active, false otherwise
-
isLevelDebug
public static boolean isLevelDebug()Check if logger is in debug mode (level FINEST).- Returns:
- True if level matches, false otherwise
-
isLevelError
public static boolean isLevelError()Check if logger is in debug mode (level SEVERE).- Returns:
- True if level matches, false otherwise
-
isLevelInfo
public static boolean isLevelInfo()Check if logger is in debug mode (level INFO).- Returns:
- True if level matches, false otherwise
-
isLevelOff
public static boolean isLevelOff()Check if logger is in debug mode (level OFF).- Returns:
- True if level matches, false otherwise
-
resetLevel
public static void resetLevel()Reset logger level to the configured level in KLog.properties- Since:
- 2024.05.25
-
setLevel
Set logger level- Parameters:
argLevel- Logging level to set- Since:
- 2024.06.16
-
setLevelDebug
public static void setLevelDebug()Set logger to debug level (FINEST)- Since:
- 2024.05.25
-
setLevelError
public static void setLevelError()Set logger to error level (SEVERE)- Since:
- 2024.05.25
-
setLevelInfo
public static void setLevelInfo()Set logger to info level (INFO)- Since:
- 2024.05.25
-
setLevelOff
public static void setLevelOff()Set logger off (OFF)- Since:
- 2024.05.25
-
toString
-