BAEL-6033: Add tinylog 2 examples (#13232)

* BAEL-6033: Add tinylog 2 examples

* BAEL-6033: Rename test methods of tinylog 2 in when-then style
This commit is contained in:
Martin Winandy
2023-01-11 02:53:43 +01:00
committed by GitHub
parent a23ccae5ac
commit 5825cf4775
6 changed files with 166 additions and 0 deletions
@@ -0,0 +1,43 @@
package com.baeldung.tinylog;
import org.tinylog.Logger;
public class TinylogExamples {
public static void main(String[] args) {
/* Static text */
Logger.info("Hello World!");
/* Placeholders */
Logger.info("Hello {}!", "Alice");
Logger.info("π = {0.00}", Math.PI);
/* Lazy Logging */
Logger.debug("Expensive computation: {}", () -> compute()); // Visible in log files but not on the console
/* Exceptions */
int a = 42;
int b = 0;
try {
int i = a / b;
} catch (Exception ex) {
Logger.error(ex, "Cannot divide {} by {}", a, b);
}
try {
int i = a / b;
} catch (Exception ex) {
Logger.error(ex);
}
}
private static int compute() {
return 42; // In real applications, we would perform an expensive computation here
}
}