While doing experiment over tinylog the issue i am facing is am not able to print the run time exception logs.
For ex. int a =0 ;int b = 10;int c = b/a;
As this will give arithmetic exception but this is not getting recorder in logs.
You just need to catch the runtime exception and pass it to the logger:
import org.tinylog.Logger; public class Application { public static void main(String[] args) { try { int a = 0, b = 10; System.out.println(b / a); } catch (RuntimeException ex) { Logger.error(ex); } } }
Edit: Alternatively, you can also use an UncaughtExceptionHandler for logging uncaught exceptions:
import java.lang.Thread.UncaughtHandler; import org.tinylog.Logger; public class Application { public static void main(String[] args) { Thread.setDefaultUncaughtExceptionHandler(new TinylogHandler()); int a = 0, b = 0; System.out.println(a / b); } private static class TinylogHandler implements UncaughtExceptionHandler { @Override public void uncaughtException(Thread thread, Throwable ex) { Logger.error(ex); } } }
Copyright © 2021 Jogjafile Inc.
You just need to catch the runtime exception and pass it to the logger:
Edit: Alternatively, you can also use an UncaughtExceptionHandler for logging uncaught exceptions: