From 56dfa124cafd79e15aca29ab1fca3a10a550ab79 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Fri, 18 Aug 2023 18:29:50 +0200 Subject: [PATCH] classlib: add more methods to Logger --- .../classlib/java/util/logging/TLogger.java | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/logging/TLogger.java b/classlib/src/main/java/org/teavm/classlib/java/util/logging/TLogger.java index cffa2e0d9..a42bd835d 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/logging/TLogger.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/logging/TLogger.java @@ -15,6 +15,7 @@ */ package org.teavm.classlib.java.util.logging; +import java.util.function.Supplier; import org.teavm.classlib.PlatformDetector; import org.teavm.classlib.java.lang.TInteger; import org.teavm.classlib.java.lang.TObject; @@ -143,34 +144,128 @@ public class TLogger { log(record); } + public void log(TLevel level, Supplier msgSupplier) { + var record = new TLogRecord(level, msgSupplier.get()); + log(record); + } + + public void log(TLevel level, TThrowable thrown, Supplier msgSupplier) { + var record = new TLogRecord(level, msgSupplier.get()); + record.setThrown(thrown); + log(record); + } + + public void logp(TLevel level, String sourceClass, String sourceMethod, String msg) { + var record = new TLogRecord(level, msg); + record.setSourceClassName(sourceClass); + record.setSourceMethodName(sourceMethod); + log(record); + } + + public void logp(TLevel level, String sourceClass, String sourceMethod, String msg, Object[] params) { + var record = new TLogRecord(level, msg); + record.setSourceClassName(sourceClass); + record.setSourceMethodName(sourceMethod); + record.setParameters(params); + log(record); + } + + public void logp(TLevel level, String sourceClass, String sourceMethod, Supplier msgSupplier) { + var record = new TLogRecord(level, msgSupplier.get()); + record.setSourceClassName(sourceClass); + record.setSourceMethodName(sourceMethod); + log(record); + } + + public void logp(TLevel level, String sourceClass, String sourceMethod, String msg, Object param1) { + var record = new TLogRecord(level, msg); + record.setSourceClassName(sourceClass); + record.setSourceMethodName(sourceMethod); + record.setParameters(new Object[] { param1 }); + log(record); + } + + public void logp(TLevel level, String sourceClass, String sourceMethod, String msg, TThrowable thrown) { + var record = new TLogRecord(level, msg); + record.setSourceClassName(sourceClass); + record.setSourceMethodName(sourceMethod); + record.setThrown(thrown); + log(record); + } + + public void logp(TLevel level, String sourceClass, String sourceMethod, TThrowable thrown, + Supplier msgSupplier) { + var record = new TLogRecord(level, msgSupplier.get()); + record.setSourceClassName(sourceClass); + record.setSourceMethodName(sourceMethod); + record.setThrown(thrown); + log(record); + } + public void severe(String msg) { log(TLevel.SEVERE, msg); } + public void severe(Supplier msgSupplier) { + severe(msgSupplier.get()); + } + public void warning(String msg) { log(TLevel.WARNING, msg); } + public void warning(Supplier msgSupplier) { + warning(msgSupplier.get()); + } + public void info(String msg) { log(TLevel.INFO, msg); } + public void info(Supplier msgSupplier) { + info(msgSupplier.get()); + } + public void config(String msg) { log(TLevel.CONFIG, msg); } + public void config(Supplier msgSupplier) { + config(msgSupplier.get()); + } + public void fine(String msg) { log(TLevel.FINE, msg); } + public void fine(Supplier msgSupplier) { + fine(msgSupplier.get()); + } + public void finer(String msg) { log(TLevel.FINER, msg); } + public void finer(Supplier msgSupplier) { + finer(msgSupplier.get()); + } + public void finest(String msg) { log(TLevel.FINEST, msg); } + public void finest(Supplier msgSupplier) { + finest(msgSupplier.get()); + } + + public void throwing(String sourceClass, String sourceMethod, TThrowable thrown) { + var record = new TLogRecord(TLevel.FINEST, "THROW"); + record.setThrown(thrown); + record.setSourceClassName(sourceClass); + record.setSourceMethodName(sourceMethod); + log(record); + } + public boolean isLoggable(@SuppressWarnings("unused") TLevel level) { return true; }