From 03b3b2946800ee00c6860ea7df911af51b0da530 Mon Sep 17 00:00:00 2001 From: Nathaniel Bauernfeind Date: Wed, 14 Feb 2024 17:16:50 -0700 Subject: [PATCH] Generators: use LoggerFactory and reduce CI log spam --- Generators/Generators.gradle | 1 + .../gen/AbstractBasicJavaGenerator.java | 30 +++++++------- .../main/java/io/deephaven/gen/GenUtils.java | 7 ++-- .../java/io/deephaven/gen/JavaFunction.java | 7 ++-- .../plot/util/GenerateAxesPlotMethods.java | 11 +++-- .../plot/util/GenerateFigureImmutable.java | 37 ++++++++--------- .../plot/util/GenerateMultiSeries.java | 13 +++--- .../util/GeneratePlottingConvenience.java | 40 ++++++++++--------- 8 files changed, 77 insertions(+), 69 deletions(-) diff --git a/Generators/Generators.gradle b/Generators/Generators.gradle index 7c6dc49da93..8295624ade8 100644 --- a/Generators/Generators.gradle +++ b/Generators/Generators.gradle @@ -13,6 +13,7 @@ configurations { dependencies { implementation project(':engine-table') + implementation project(':log-factory') implementation project(':Plot') implementation project(':extensions-csv') implementation project(':extensions-kafka') diff --git a/Generators/src/main/java/io/deephaven/gen/AbstractBasicJavaGenerator.java b/Generators/src/main/java/io/deephaven/gen/AbstractBasicJavaGenerator.java index bc599770847..a79a51cc086 100644 --- a/Generators/src/main/java/io/deephaven/gen/AbstractBasicJavaGenerator.java +++ b/Generators/src/main/java/io/deephaven/gen/AbstractBasicJavaGenerator.java @@ -3,6 +3,9 @@ */ package io.deephaven.gen; +import io.deephaven.internal.log.LoggerFactory; +import io.deephaven.io.logger.Logger; + import java.io.IOException; import java.io.PrintWriter; import java.lang.reflect.Method; @@ -13,8 +16,6 @@ import java.util.Set; import java.util.TreeMap; import java.util.function.Predicate; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Abstract class for generating Java code from methods of one or more classes. @@ -22,7 +23,7 @@ * {@link #generateCode()} must be called to generate the code. */ public abstract class AbstractBasicJavaGenerator { - private static final Logger log = Logger.getLogger(AbstractBasicJavaGenerator.class.toString()); + private static final Logger log = LoggerFactory.getLogger(AbstractBasicJavaGenerator.class); private final String gradleTask; private final String packageName; @@ -51,10 +52,11 @@ public AbstractBasicJavaGenerator(final String gradleTask, final String packageN for (String imp : imports) { Class c = Class.forName(imp, false, Thread.currentThread().getContextClassLoader()); - log.info("Processing class: " + c); + log.debug().append("Processing class: ").append(c.toString()).endl(); for (Method m : c.getMethods()) { - log.info("Processing method (" + c + "): " + m); + log.debug().append("Processing method (").append(c.toString()).append("): ").append(m.toString()) + .endl(); if (includeMethod.test(m)) { addMethod(m); } @@ -63,7 +65,7 @@ public AbstractBasicJavaGenerator(final String gradleTask, final String packageN } private void addMethod(Method m) { - log.info("Processing public static method: " + m); + log.debug().append("Processing public static method: ").append(m.toString()).endl(); JavaFunction f = new JavaFunction(m); // System.out.println(f); @@ -71,10 +73,10 @@ private void addMethod(Method m) { if (functions.containsKey(f)) { JavaFunction fAlready = functions.get(f); final String message = "Signature Already Present: " + fAlready + "\t" + f; - log.severe(message); + log.error().append(message).endl(); throw new RuntimeException(message); } else { - log.info("Added method: " + f); + log.debug().append("Added method: ").append(f.toString()).endl(); functions.put(f, f); } } @@ -122,7 +124,7 @@ public String generateCode() { } if (skip) { - log.warning("*** Skipping function: " + f); + log.warn().append("*** Skipping function: ").append(f.toString()).endl(); continue; } @@ -158,12 +160,12 @@ public static void runCommandLine(final AbstractBasicJavaGenerator gen, final St System.exit(-1); } - log.setLevel(Level.WARNING); - log.warning("Running " + gen.getClass().getSimpleName() + " assertNoChange=" + assertNoChange); + log.warn().append("Running ").append(gen.getClass().getSimpleName()).append(" assertNoChange=") + .append(assertNoChange).endl(); final String code = gen.generateCode(); - log.info("\n\n**************************************\n\n"); - log.info(code); + log.debug().nl().nl().append("**************************************").nl().nl().endl(); + log.debug().append(code).endl(); String file = devroot + relativeFilePath; @@ -176,7 +178,7 @@ public static void runCommandLine(final AbstractBasicJavaGenerator gen, final St out.print(code); out.close(); - log.warning("Class file written to: " + file); + log.warn().append("Class file written to: ").append(file).endl(); } } diff --git a/Generators/src/main/java/io/deephaven/gen/GenUtils.java b/Generators/src/main/java/io/deephaven/gen/GenUtils.java index b4ec61df602..a9d70e5ca1d 100644 --- a/Generators/src/main/java/io/deephaven/gen/GenUtils.java +++ b/Generators/src/main/java/io/deephaven/gen/GenUtils.java @@ -2,17 +2,18 @@ import gnu.trove.map.TIntObjectMap; import gnu.trove.map.hash.TIntObjectHashMap; +import io.deephaven.internal.log.LoggerFactory; +import io.deephaven.io.logger.Logger; import org.jetbrains.annotations.NotNull; import java.lang.reflect.*; import java.util.*; -import java.util.logging.Logger; @SuppressWarnings("StringConcatenationInLoop") public class GenUtils { private GenUtils() {} - private static final Logger log = Logger.getLogger(GenUtils.class.toString()); + private static final Logger log = LoggerFactory.getLogger(GenUtils.class); private static final TIntObjectMap cachedIndents = new TIntObjectHashMap<>(); @@ -205,7 +206,7 @@ public static String javaFunctionSignature(final JavaFunction f, final String si } TypeVariable t = f.getTypeParameters()[i]; - log.fine("BOUNDS: " + Arrays.toString(t.getBounds())); + log.debug().append("BOUNDS: ").append(Arrays.toString(t.getBounds())).endl(); s += t; Type[] bounds = t.getBounds(); diff --git a/Generators/src/main/java/io/deephaven/gen/JavaFunction.java b/Generators/src/main/java/io/deephaven/gen/JavaFunction.java index 54c29ac5227..f369d4f3e27 100644 --- a/Generators/src/main/java/io/deephaven/gen/JavaFunction.java +++ b/Generators/src/main/java/io/deephaven/gen/JavaFunction.java @@ -1,5 +1,7 @@ package io.deephaven.gen; +import io.deephaven.internal.log.LoggerFactory; +import io.deephaven.io.logger.Logger; import io.deephaven.util.type.TypeUtils; import org.jetbrains.annotations.NotNull; @@ -9,7 +11,6 @@ import java.lang.reflect.TypeVariable; import java.util.Arrays; import java.util.Objects; -import java.util.logging.Logger; /** * A Java function description for use in code generation. @@ -17,7 +18,7 @@ * JavaFunctions are equal if they have the same method names and parameter types. */ public class JavaFunction implements Comparable { - private static final Logger log = Logger.getLogger(JavaFunction.class.toString()); + private static final Logger log = LoggerFactory.getLogger(JavaFunction.class); private final String className; private final String classNameShort; @@ -146,7 +147,7 @@ public Class getReturnClass() { try { return TypeUtils.getErasedType(returnType); } catch (UnsupportedOperationException e) { - log.warning("Unable to determine Class from returnType=" + returnType.getTypeName()); + log.warn().append("Unable to determine Class from returnType=").append(returnType.getTypeName()).endl(); return null; } } diff --git a/Generators/src/main/java/io/deephaven/plot/util/GenerateAxesPlotMethods.java b/Generators/src/main/java/io/deephaven/plot/util/GenerateAxesPlotMethods.java index c2bbba7739f..41cdf989768 100644 --- a/Generators/src/main/java/io/deephaven/plot/util/GenerateAxesPlotMethods.java +++ b/Generators/src/main/java/io/deephaven/plot/util/GenerateAxesPlotMethods.java @@ -5,6 +5,8 @@ import io.deephaven.base.verify.Require; import io.deephaven.gen.GenUtils; +import io.deephaven.internal.log.LoggerFactory; +import io.deephaven.io.logger.Logger; import java.io.IOException; import java.io.PrintWriter; @@ -14,13 +16,11 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.stream.IntStream; public class GenerateAxesPlotMethods { - private static final Logger log = Logger.getLogger(GenerateAxesPlotMethods.class.toString()); + private static final Logger log = LoggerFactory.getLogger(GenerateAxesPlotMethods.class); private static final String GRADLE_TASK = ":Generators:generateAxesPlotMethods"; private static final String PLOT_INFO_ID = "new PlotInfo(this, seriesName)"; @@ -872,7 +872,7 @@ private static void generate(final boolean assertNoChange, final String file, fi out.print(newcode); out.close(); - log.info(file + " written"); + log.info().append(file).append(" written").endl(); } } @@ -890,8 +890,7 @@ public static void main(String[] args) throws IOException { System.exit(-1); } - log.setLevel(Level.WARNING); - log.info("Running GenerateAxesPlotMethods assertNoChange=" + assertNoChange); + log.info().append("Running GenerateAxesPlotMethods assertNoChange=").append(assertNoChange).endl(); final String fileIface = devroot + "/Plot/src/main/java/io/deephaven/plot/Axes.java"; final String fileImpl = devroot + "/Plot/src/main/java/io/deephaven/plot/AxesImpl.java"; diff --git a/Generators/src/main/java/io/deephaven/plot/util/GenerateFigureImmutable.java b/Generators/src/main/java/io/deephaven/plot/util/GenerateFigureImmutable.java index 89acf744da8..f0dd25a42be 100644 --- a/Generators/src/main/java/io/deephaven/plot/util/GenerateFigureImmutable.java +++ b/Generators/src/main/java/io/deephaven/plot/util/GenerateFigureImmutable.java @@ -4,6 +4,8 @@ package io.deephaven.plot.util; import io.deephaven.gen.GenUtils; +import io.deephaven.internal.log.LoggerFactory; +import io.deephaven.io.logger.Logger; import io.deephaven.plot.*; import io.deephaven.plot.datasets.DataSeries; import io.deephaven.plot.datasets.multiseries.MultiSeries; @@ -18,8 +20,6 @@ import java.util.*; import java.util.function.Function; import java.util.function.Predicate; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -33,7 +33,7 @@ public class GenerateFigureImmutable { // See also GroovyStaticImportGenerator - private static final Logger log = Logger.getLogger(GenerateFigureImmutable.class.toString()); + private static final Logger log = LoggerFactory.getLogger(GenerateFigureImmutable.class); private static final String GRADLE_TASK = ":Generators:generateFigureImmutable"; private static final String CLASS_NAME_INTERFACE = "io.deephaven.plot.Figure"; @@ -66,10 +66,11 @@ private GenerateFigureImmutable(final boolean isInterface, final String[] import for (final String imp : interfaces) { final Class c = Class.forName(imp, false, Thread.currentThread().getContextClassLoader()); - log.info("Processing class: " + c); + log.debug().append("Processing class: ").append(c.toString()).endl(); for (final Method m : c.getMethods()) { - log.info("Processing method (" + c + "): " + m); + log.debug().append("Processing method (").append(c.toString()).append("): ").append(m.toString()) + .endl(); boolean isStatic = Modifier.isStatic(m.getModifiers()); boolean isPublic = Modifier.isPublic(m.getModifiers()); boolean isObject = m.getDeclaringClass().equals(Object.class); @@ -104,7 +105,7 @@ public String getTypeName() { } private void addPublicNonStatic(Method m) { - log.info("Processing public non-static method: " + m); + log.debug().append("Processing public non-static method: ").append(m.toString()).endl(); final JavaFunction f = new JavaFunction(m); final JavaFunction signature = signature(f); @@ -112,17 +113,17 @@ private void addPublicNonStatic(Method m) { boolean skip = skip(f); if (skip) { - log.info("*** Skipping function: " + f); + log.debug().append("*** Skipping function: ").append(f.toString()).endl(); return; } if (nonstaticFunctions.containsKey(signature)) { JavaFunction fAlready = nonstaticFunctions.get(signature); final String message = "Signature Already Present: " + fAlready + "\t" + signature; - log.severe(message); + log.error().append(message).endl(); throw new RuntimeException(message); } else { - log.info("Added public method: " + f); + log.debug().append("Added public method: ").append(f.toString()).endl(); nonstaticFunctions.put(signature, f); } } @@ -201,7 +202,7 @@ private String generateCode() { final boolean skip = skip(f); if (skip) { - log.info("*** Skipping function: " + f); + log.debug().append("*** Skipping function: ").append(f.toString()).endl(); continue; } @@ -216,7 +217,7 @@ private String generateCode() { final boolean skip = skip(f); if (skip) { - log.info("*** Skipping function: " + f); + log.debug().append("*** Skipping function: ").append(f.toString()).endl(); continue; } @@ -797,10 +798,11 @@ private Map> commonSignatureGroups( final Set functionSet = new HashSet<>(); for (String iface : interfaces) { final Class c = Class.forName(iface, false, Thread.currentThread().getContextClassLoader()); - log.info("Processing class: " + c); + log.debug().append("Processing class: ").append(c.toString()).endl(); for (final java.lang.reflect.Method m : c.getMethods()) { - log.info("Processing method (" + c + "): " + m); + log.debug().append("Processing method (").append(c.toString()).append("): ").append(m.toString()) + .endl(); boolean isStatic = Modifier.isStatic(m.getModifiers()); boolean isPublic = Modifier.isPublic(m.getModifiers()); boolean isObject = m.getDeclaringClass().equals(Object.class); @@ -843,8 +845,7 @@ private static String createMultiSeriesArgs(JavaFunction f) { private static void generateFile(final String devroot, final boolean assertNoChange, final boolean isInterface) throws ClassNotFoundException, IOException { - log.setLevel(Level.WARNING); - log.info("Running GenerateFigureImmutable assertNoChange=" + assertNoChange); + log.info().append("Running GenerateFigureImmutable assertNoChange=").append(assertNoChange).endl(); final String[] imports = { "io.deephaven.plot.datasets.DataSeriesInternal", @@ -904,8 +905,8 @@ private static void generateFile(final String devroot, final boolean assertNoCha seriesInterfaces, skips, JavaFunction::getMethodName); final String code = gen.generateCode(); - log.info("\n\n**************************************\n\n"); - log.info(code); + log.debug().nl().nl().append("**************************************").nl().nl().endl(); + log.debug().append(code).endl(); String file = devroot + "/Plot/src/main/java/" + gen.outputClass.replace(".", "/") + ".java"; @@ -918,7 +919,7 @@ private static void generateFile(final String devroot, final boolean assertNoCha out.print(code); out.close(); - log.info(gen.outputClass + " written to: " + file); + log.info().append(gen.outputClass).append(" written to: ").append(file).endl(); } } diff --git a/Generators/src/main/java/io/deephaven/plot/util/GenerateMultiSeries.java b/Generators/src/main/java/io/deephaven/plot/util/GenerateMultiSeries.java index fb2d5fea436..c05522ee355 100644 --- a/Generators/src/main/java/io/deephaven/plot/util/GenerateMultiSeries.java +++ b/Generators/src/main/java/io/deephaven/plot/util/GenerateMultiSeries.java @@ -7,6 +7,8 @@ import io.deephaven.base.Pair; import io.deephaven.gen.GenUtils; import io.deephaven.gen.JavaFunction; +import io.deephaven.internal.log.LoggerFactory; +import io.deephaven.io.logger.Logger; import io.deephaven.plot.util.functions.ClosureFunction; import io.deephaven.engine.table.Table; import io.deephaven.util.type.TypeUtils; @@ -22,7 +24,6 @@ import java.nio.file.Paths; import java.util.*; import java.util.function.Function; -import java.util.logging.Logger; import static io.deephaven.gen.GenUtils.indent; @@ -31,7 +32,7 @@ * Generates methods for the MultiSeries datasets. */ public class GenerateMultiSeries { - private static final Logger log = Logger.getLogger(GenerateMultiSeries.class.toString()); + private static final Logger log = LoggerFactory.getLogger(GenerateMultiSeries.class); private static final String GRADLE_TASK = ":Generators:generateMultiSeries"; public static void main(String[] args) throws ClassNotFoundException, IOException, NoSuchMethodException { @@ -581,7 +582,7 @@ private String getFigureFunctionInput(final String returnClass, code.append("getX(), newColumn"); break; default: - log.warning(tableMethod.toString()); + log.warn().append(tableMethod.toString()).endl(); throw new IllegalStateException("Can not calculate function input for function " + tableMethodName + " in class " + function.getClassNameShort()); } @@ -602,9 +603,9 @@ private String getFigureFunctionInput(final String returnClass, } if (methods.length != 1) { - log.warning("More than 1 possible table method for function input for function " + tableMethodName - + " in class " + function.getClassNameShort()); - log.warning(Arrays.toString(methods)); + log.warn().append("More than 1 possible table method for function input for function ") + .append(tableMethodName).append(" in class ").append(function.getClassNameShort()).endl(); + log.warn().append(Arrays.toString(methods)).endl(); throw new IllegalStateException("Can not calculate function input for function " + tableMethodName + " in class " + function.getClassNameShort()); } diff --git a/Generators/src/main/java/io/deephaven/plot/util/GeneratePlottingConvenience.java b/Generators/src/main/java/io/deephaven/plot/util/GeneratePlottingConvenience.java index 4c6f5cea056..620322b1992 100644 --- a/Generators/src/main/java/io/deephaven/plot/util/GeneratePlottingConvenience.java +++ b/Generators/src/main/java/io/deephaven/plot/util/GeneratePlottingConvenience.java @@ -4,6 +4,8 @@ package io.deephaven.plot.util; import io.deephaven.gen.GenUtils; +import io.deephaven.internal.log.LoggerFactory; +import io.deephaven.io.logger.Logger; import io.deephaven.plot.BaseFigureImpl; import io.deephaven.plot.FigureImpl; import io.deephaven.gen.JavaFunction; @@ -16,8 +18,6 @@ import java.util.*; import java.util.function.Function; import java.util.function.Predicate; -import java.util.logging.Level; -import java.util.logging.Logger; import static io.deephaven.gen.GenUtils.indent; import static io.deephaven.gen.GenUtils.typesToImport; @@ -30,7 +30,7 @@ public class GeneratePlottingConvenience { // See also GroovyStaticImportGenerator - private static final Logger log = Logger.getLogger(GeneratePlottingConvenience.class.toString()); + private static final Logger log = LoggerFactory.getLogger(GeneratePlottingConvenience.class); private static final String GRADLE_TASK = ":Generators:generatePlottingConvenience"; private static final String OUTPUT_CLASS = "io.deephaven.plot.PlottingConvenience"; @@ -53,7 +53,7 @@ private GeneratePlottingConvenience(final String[] staticImports, final String[] final String classPath = staticImport.substring(0, lastDot); final String methodName = staticImport.substring(lastDot + 1); final Class c = Class.forName(classPath, false, Thread.currentThread().getContextClassLoader()); - log.info("Processing static class: " + c); + log.debug().append("Processing static class: ").append(c.toString()).endl(); final Method[] methods = Arrays.stream(c.getMethods()).filter( m -> m.getName().equals(methodName) && Modifier.isStatic(m.getModifiers()) @@ -61,17 +61,19 @@ private GeneratePlottingConvenience(final String[] staticImports, final String[] .toArray(Method[]::new); for (Method m : methods) { - log.info("Processing static method (" + c + "): " + m); + log.debug().append("Processing static method (").append(c.toString()).append("): ").append(m.toString()) + .endl(); addPublicMethod(m, staticFunctions, true); } } for (final String imp : imports) { final Class c = Class.forName(imp, false, Thread.currentThread().getContextClassLoader()); - log.info("Processing class: " + c); + log.debug().append("Processing class: ").append(c.toString()).endl(); for (final Method m : c.getMethods()) { - log.info("Processing method (" + c + "): " + m); + log.debug().append("Processing method (").append(c.toString()).append("): ").append(m.toString()) + .endl(); boolean isStatic = Modifier.isStatic(m.getModifiers()); boolean isPublic = Modifier.isPublic(m.getModifiers()); boolean isObject = m.getDeclaringClass().equals(Object.class); @@ -81,7 +83,8 @@ private GeneratePlottingConvenience(final String[] staticImports, final String[] if (!isStatic && isPublic && !isObject && (isFigureImmutable || isFigureImpl)) { addPublicMethod(m, nonstaticFunctions, false); } else { - log.info("Not adding method (" + c + "): " + m); + log.debug().append("Not adding method (").append(c.toString()).append("): ").append(m.toString()) + .endl(); } } } @@ -102,7 +105,7 @@ private boolean skip(final JavaFunction f, final boolean ignore) { } private void addPublicMethod(Method m, Map functions, boolean ignoreSkips) { - log.info("Processing public method: " + m); + log.debug().append("Processing public method: ").append(m.toString()).endl(); final JavaFunction f = new JavaFunction(m); final JavaFunction signature = f.transform(OUTPUT_CLASS, OUTPUT_CLASS_NAME_SHORT, functionNamer.apply(f), null); @@ -110,17 +113,17 @@ private void addPublicMethod(Method m, Map functions boolean skip = skip(f, ignoreSkips); if (skip) { - log.warning("*** Skipping function: " + f); + log.warn().append("*** Skipping function: ").append(f.toString()).endl(); return; } if (functions.containsKey(signature)) { JavaFunction fAlready = functions.get(signature); final String message = "Signature Already Present: " + fAlready + "\t" + signature; - log.severe(message); + log.error().append(message).endl(); throw new RuntimeException(message); } else { - log.info("Added public method: " + f); + log.debug().append("Added public method: ").append(f.toString()).endl(); functions.put(signature, f); } } @@ -167,7 +170,7 @@ private String generateCode() { final boolean skip = skip(f, true); if (skip) { - log.warning("*** Skipping static function: " + f); + log.warn().append("*** Skipping static function: ").append(f.toString()).endl(); continue; } @@ -183,7 +186,7 @@ private String generateCode() { final boolean skip = skip(f, false); if (skip) { - log.warning("*** Skipping function: " + f); + log.warn().append("*** Skipping function: ").append(f.toString()).endl(); continue; } @@ -228,8 +231,7 @@ public static void main(String[] args) throws ClassNotFoundException, IOExceptio System.exit(-1); } - log.setLevel(Level.WARNING); - log.warning("Running GeneratePlottingConvenience assertNoChange=" + assertNoChange); + log.warn().append("Running GeneratePlottingConvenience assertNoChange=").append(assertNoChange).endl(); final String[] staticImports = { "io.deephaven.gui.color.Color.color", @@ -294,8 +296,8 @@ public static void main(String[] args) throws ClassNotFoundException, IOExceptio final String code = gen.generateCode() .replace("io.deephaven.plot.FigureImpl", "io.deephaven.plot.Figure"); - log.info("\n\n**************************************\n\n"); - log.info(code); + log.debug().nl().nl().append("**************************************").nl().nl().endl(); + log.debug().append(code).endl(); String file = devroot + "/Plot/src/main/java/" + OUTPUT_CLASS.replace(".", "/") + ".java"; @@ -308,7 +310,7 @@ public static void main(String[] args) throws ClassNotFoundException, IOExceptio out.print(code); out.close(); - log.warning(OUTPUT_CLASS + " written to: " + file); + log.info().append(OUTPUT_CLASS).append(" written to: ").append(file).endl(); } }