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 void
Log error message if expression is true and throws an unchecked RuntimeException.static void
Log error message and throws an unchecked RuntimeException.static void
argException
(boolean argExpression, String argMessage, Object... argObjects) Log error message if expression evaluates true and throw an unchecked exception IllegalArgumentException.static void
close()
Close the logging.static void
Write log message of level FINEST.static void
Log error message if expression is true.static void
Log formatted exception with stack trace.static void
Log message and exception with stack trace.static void
Log error message.static Level
getLevel()
Get logger level.static void
Write log message of level INFO.static boolean
isActive()
Check if logging is active.static boolean
Check if logger is at level FINEST.static boolean
Check if logger is at level SEVEREstatic 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.propertiesstatic void
Set logger levelstatic 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)toString()
String representation of object.
-
Method Details
-
abort
-
abort
-
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
-
close
public static void close()Close the logging. -
debug
-
error
-
error
Log formatted exception with stack trace.- Parameters:
argException
- Exception to be formatted
-
error
-
error
-
getLevel
-
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 at level FINEST.- Returns:
- True if level matches, false otherwise
-
isLevelError
public static boolean isLevelError()Check if logger is at level SEVERE- Returns:
- True if level matches, false otherwise
-
isLevelInfo
public static boolean isLevelInfo()Check if logger is at level INFO.- Returns:
- True if level matches, false otherwise
-
isLevelOff
public static boolean isLevelOff()Check if logger is at 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
-