Log histograms with -Dorg.enso.persist.Logger.level=debug (#8881)

Fixes #8644 by using `slf4j` instead of `java.util.logging`.
This commit is contained in:
Jaroslav Tulach 2024-01-29 11:26:58 +01:00 committed by GitHub
parent ad7fad42fa
commit 946f931d21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 12 deletions

View File

@ -1105,6 +1105,7 @@ lazy val `persistance` = (project in file("lib/java/persistance"))
frgaalJavaCompilerSetting,
Compile / javacOptions := ((Compile / javacOptions).value),
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.netbeans.api" % "org-openide-util-lookup" % netbeansApiVersion,
"junit" % "junit" % junitVersion % Test,
"com.github.sbt" % "junit-interface" % junitIfVersion % Test

View File

@ -9,8 +9,7 @@ import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.slf4j.Logger;
final class PerGenerator {
static final byte[] HEADER = new byte[] {0x0a, 0x0d, 0x03, 0x0f};
@ -31,7 +30,7 @@ final class PerGenerator {
}
static byte[] writeObject(Object obj, Function<Object, Object> writeReplace) throws IOException {
var histogram = PerUtils.LOG.isLoggable(Level.FINE) ? new Histogram() : null;
var histogram = PerUtils.LOG.isDebugEnabled() ? new Histogram() : null;
var out = new ByteArrayOutputStream();
var data = new DataOutputStream(out);
@ -140,16 +139,14 @@ final class PerGenerator {
return a.getValue()[0] - b.getValue()[0];
});
log.fine("==== Top Bytes & Counts of Classes =====");
log.debug("==== Top Bytes & Counts of Classes =====");
for (var i = 0; i < list.size(); i++) {
if (i == 30) {
break;
}
var elem = list.get(list.size() - 1 - i);
log.log(
Level.FINE,
" {0} {1} {2}",
new Object[] {elem.getValue()[0], elem.getValue()[1], elem.getKey().getName()});
log.debug(
" " + elem.getValue()[0] + " " + elem.getValue()[1] + " " + elem.getKey().getName());
}
}

View File

@ -9,7 +9,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.logging.Level;
import org.enso.persist.Persistance.Input;
import org.enso.persist.Persistance.Reference;
@ -213,7 +212,7 @@ final class PerInputImpl implements Input {
sb.append("\nare they equal: ").append(bothObjectsAreTheSame);
var ex = new IOException(sb.toString());
if (bothObjectsAreTheSame) {
PerUtils.LOG.log(Level.WARNING, sb.toString(), ex);
PerUtils.LOG.warn(sb.toString(), ex);
} else {
throw raise(RuntimeException.class, ex);
}

View File

@ -1,11 +1,12 @@
package org.enso.persist;
import java.util.logging.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final class PerUtils {
private PerUtils() {}
static final Logger LOG = Logger.getLogger(Persistance.class.getPackageName());
static final Logger LOG = LoggerFactory.getLogger(Persistance.class.getPackageName());
@SuppressWarnings("unchecked")
static <E extends Throwable> E raise(Class<E> clazz, Throwable t) throws E {