From d890e81149da5e8558bec041cce11d190d646388 Mon Sep 17 00:00:00 2001 From: ebocher Date: Thu, 5 Oct 2023 10:33:46 +0200 Subject: [PATCH] Fix logger info --- bdtopo/pom.xml | 5 +---- .../geoclimate/bdtopo/BDTopoUtils.groovy | 1 - common-utils/pom.xml | 6 ++++++ .../geoclimate/utils/AbstractScript.groovy | 11 +++++----- .../geoclimate/utils/LoggerUtils.groovy | 20 +++---------------- geoclimate/pom.xml | 6 +++--- .../orbisgis/geoclimate/GeoclimateTest.groovy | 2 +- geoindicators/pom.xml | 12 ++++------- .../geoindicators/WorkflowUtilities.groovy | 2 -- .../WorkflowGeoIndicatorsTest.groovy | 6 +++--- osm/pom.xml | 13 +++++------- .../org/orbisgis/geoclimate/osm/OSM.groovy | 1 - .../geoclimate/osm/WorflowOSMTest.groovy | 4 ++-- .../osm/WorkflowAbstractTest.groovy | 6 +++--- osmtools/pom.xml | 4 ---- .../geoclimate/osmtools/OSMTools.groovy | 1 - .../geoclimate/osmtools/LoaderTest.groovy | 6 +++--- .../geoclimate/osmtools/TransformTest.groovy | 6 +++--- .../osmtools/utils/TransformUtilsTest.groovy | 6 +++--- .../osmtools/utils/UtilitiesTest.groovy | 6 +++--- pom.xml | 6 ------ .../worldpoptools/WorldPopTools.groovy | 1 - .../worldpoptools/WorldPopExtractTest.groovy | 6 +++--- 23 files changed, 51 insertions(+), 86 deletions(-) diff --git a/bdtopo/pom.xml b/bdtopo/pom.xml index bb4aaaea3a..7eba1a68a3 100644 --- a/bdtopo/pom.xml +++ b/bdtopo/pom.xml @@ -59,10 +59,7 @@ org.slf4j slf4j-api - - ch.qos.logback - logback-classic - + org.junit.jupiter diff --git a/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/BDTopoUtils.groovy b/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/BDTopoUtils.groovy index d01b6d6302..50fbcfc78c 100644 --- a/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/BDTopoUtils.groovy +++ b/bdtopo/src/main/groovy/org/orbisgis/geoclimate/bdtopo/BDTopoUtils.groovy @@ -23,7 +23,6 @@ package org.orbisgis.geoclimate.bdtopo import org.locationtech.jts.geom.Envelope import org.locationtech.jts.geom.Geometry import org.orbisgis.geoclimate.utils.AbstractScript -import org.orbisgis.geoclimate.utils.LoggerUtils /** * BDTopo utils diff --git a/common-utils/pom.xml b/common-utils/pom.xml index 14af81a924..a120f832f2 100644 --- a/common-utils/pom.xml +++ b/common-utils/pom.xml @@ -15,6 +15,7 @@ UTF-8 + 1.4.11 @@ -23,9 +24,14 @@ groovy ${groovy-version} + + org.slf4j + slf4j-api + ch.qos.logback logback-classic + ${logback-version} diff --git a/common-utils/src/main/groovy/org/orbisgis/geoclimate/utils/AbstractScript.groovy b/common-utils/src/main/groovy/org/orbisgis/geoclimate/utils/AbstractScript.groovy index 209003332a..28c8ce1e2f 100644 --- a/common-utils/src/main/groovy/org/orbisgis/geoclimate/utils/AbstractScript.groovy +++ b/common-utils/src/main/groovy/org/orbisgis/geoclimate/utils/AbstractScript.groovy @@ -1,22 +1,21 @@ package org.orbisgis.geoclimate.utils -import ch.qos.logback.classic.Logger -import ch.qos.logback.classic.LoggerContext +import org.slf4j.Logger abstract class AbstractScript extends Script { public Logger logger + AbstractScript(Class aClass) { - LoggerContext context = new LoggerContext() - this.logger = context.getLogger(aClass) - LoggerUtils.setLoggerLevel("INFO") + this.logger = org.slf4j.LoggerFactory.getLogger(aClass.toString()) } + static String uuid() { UUID.randomUUID().toString().replaceAll("-", "_") } void info(def message) { - logger.info(message.toString()) + logger.info( message.toString()) } void warn(def message) { diff --git a/common-utils/src/main/groovy/org/orbisgis/geoclimate/utils/LoggerUtils.groovy b/common-utils/src/main/groovy/org/orbisgis/geoclimate/utils/LoggerUtils.groovy index cc0a4721d0..f4a9d8bd50 100644 --- a/common-utils/src/main/groovy/org/orbisgis/geoclimate/utils/LoggerUtils.groovy +++ b/common-utils/src/main/groovy/org/orbisgis/geoclimate/utils/LoggerUtils.groovy @@ -1,12 +1,11 @@ package org.orbisgis.geoclimate.utils import ch.qos.logback.classic.Level -import ch.qos.logback.classic.Logger import ch.qos.logback.classic.LoggerContext import org.slf4j.LoggerFactory -class LoggerUtils { +class LoggerUtils { /** @@ -27,22 +26,9 @@ class LoggerUtils { } else { throw new RuntimeException("Invalid log level. Allowed values are : INFO, DEBUG, TRACE, OFF") } - var logFac = LoggerFactory.getILoggerFactory() - if(logFac instanceof LoggerContext){ - var context = (LoggerContext) LoggerFactory.getILoggerFactory() - context.getLoggerList().each { it -> it.setLevel(level) } - } + var context = (LoggerContext) LoggerFactory.getILoggerFactory() + context.getLoggerList().each { it -> it.setLevel(level) } } } - - /** - * Create a logback logger - * @param aClass - * @return - */ - static Logger createLogger(Class aClass){ - LoggerContext context = new LoggerContext() - return context.getLogger(aClass) - } } diff --git a/geoclimate/pom.xml b/geoclimate/pom.xml index 4ecdf7746e..b08b4d35e0 100644 --- a/geoclimate/pom.xml +++ b/geoclimate/pom.xml @@ -85,14 +85,14 @@ org.orbisgis.geoclimate osmtools - org.slf4j slf4j-api - ch.qos.logback - logback-classic + org.slf4j + slf4j-simple + 2.0.9 diff --git a/geoclimate/src/test/groovy/org/orbisgis/geoclimate/GeoclimateTest.groovy b/geoclimate/src/test/groovy/org/orbisgis/geoclimate/GeoclimateTest.groovy index 4bc4e4293e..c681a81697 100644 --- a/geoclimate/src/test/groovy/org/orbisgis/geoclimate/GeoclimateTest.groovy +++ b/geoclimate/src/test/groovy/org/orbisgis/geoclimate/GeoclimateTest.groovy @@ -98,7 +98,7 @@ class GeoclimateTest { def cmd = new CommandLine(app) def sw = new StringWriter() cmd.setOut(new PrintWriter(sw)) - def exitCode = cmd.execute("-w osm", "-f $configFile", "-l info") + def exitCode = cmd.execute("-w osm", "-f $configFile", "-l OFF") assert 0 == exitCode } diff --git a/geoindicators/pom.xml b/geoindicators/pom.xml index 25afaaff05..377ad648c6 100644 --- a/geoindicators/pom.xml +++ b/geoindicators/pom.xml @@ -54,14 +54,6 @@ xstream 1.4.19 - - org.slf4j - slf4j-api - - - ch.qos.logback - logback-classic - org.codehaus.groovy groovy-json @@ -76,6 +68,10 @@ org.orbisgis.geoclimate common-utils + + org.slf4j + slf4j-api + diff --git a/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowUtilities.groovy b/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowUtilities.groovy index 7c0c8481f0..7db81a817a 100644 --- a/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowUtilities.groovy +++ b/geoindicators/src/main/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowUtilities.groovy @@ -19,8 +19,6 @@ */ package org.orbisgis.geoclimate.geoindicators -import ch.qos.logback.classic.Level -import ch.qos.logback.classic.LoggerContext import groovy.json.JsonSlurper import groovy.transform.BaseScript import org.h2gis.functions.io.utility.PRJUtil diff --git a/geoindicators/src/test/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowGeoIndicatorsTest.groovy b/geoindicators/src/test/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowGeoIndicatorsTest.groovy index 6d607008cb..7943131526 100644 --- a/geoindicators/src/test/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowGeoIndicatorsTest.groovy +++ b/geoindicators/src/test/groovy/org/orbisgis/geoclimate/geoindicators/WorkflowGeoIndicatorsTest.groovy @@ -19,14 +19,14 @@ */ package org.orbisgis.geoclimate.geoindicators -import ch.qos.logback.classic.Logger import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.Test import org.junit.jupiter.api.io.TempDir import org.orbisgis.data.H2GIS import org.orbisgis.data.dataframe.DataFrame import org.orbisgis.geoclimate.Geoindicators -import org.orbisgis.geoclimate.utils.LoggerUtils +import org.slf4j.Logger +import org.slf4j.LoggerFactory import static org.junit.jupiter.api.Assertions.* import static org.orbisgis.data.H2GIS.open @@ -36,7 +36,7 @@ class WorkflowGeoIndicatorsTest { @TempDir static File folder - public static Logger logger = LoggerUtils.createLogger(WorkflowGeoIndicatorsTest.class) + public static Logger logger = LoggerFactory.getLogger(WorkflowGeoIndicatorsTest.class) // Indicator list (at RSU scale) for each type of use public static listNames = [ diff --git a/osm/pom.xml b/osm/pom.xml index 600de6639d..c8494a8382 100644 --- a/osm/pom.xml +++ b/osm/pom.xml @@ -55,18 +55,15 @@ geoindicators ${project.parent.version} - - org.slf4j - slf4j-api - - - ch.qos.logback - logback-classic - org.orbisgis.geoclimate common-utils + + org.slf4j + slf4j-api + + org.junit.jupiter diff --git a/osm/src/main/groovy/org/orbisgis/geoclimate/osm/OSM.groovy b/osm/src/main/groovy/org/orbisgis/geoclimate/osm/OSM.groovy index 2651dcb2aa..87cfcc6d3a 100644 --- a/osm/src/main/groovy/org/orbisgis/geoclimate/osm/OSM.groovy +++ b/osm/src/main/groovy/org/orbisgis/geoclimate/osm/OSM.groovy @@ -23,7 +23,6 @@ import org.locationtech.jts.geom.Envelope import org.locationtech.jts.geom.Geometry import org.orbisgis.geoclimate.osmtools.utils.Utilities import org.orbisgis.geoclimate.utils.AbstractScript -import org.orbisgis.geoclimate.utils.LoggerUtils /** * Main class to access to the OSM processes diff --git a/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorflowOSMTest.groovy b/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorflowOSMTest.groovy index 8fc9467776..36a62227b4 100644 --- a/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorflowOSMTest.groovy +++ b/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorflowOSMTest.groovy @@ -29,8 +29,7 @@ import org.junit.jupiter.api.io.TempDir import org.orbisgis.data.H2GIS import org.orbisgis.data.POSTGIS import org.orbisgis.geoclimate.Geoindicators -import org.orbisgis.geoclimate.osmtools.OSMTools -import org.orbisgis.geoclimate.osmtools.utils.Utilities +import org.orbisgis.geoclimate.utils.LoggerUtils import static org.junit.jupiter.api.Assertions.* @@ -647,6 +646,7 @@ class WorflowOSMTest extends WorkflowAbstractTest { //Use it for debug @Test void testIntegration() { + String directory = "/tmp/geoclimate" File dirFile = new File(directory) dirFile.delete() diff --git a/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorkflowAbstractTest.groovy b/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorkflowAbstractTest.groovy index 372142984c..a965a6b913 100644 --- a/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorkflowAbstractTest.groovy +++ b/osm/src/test/groovy/org/orbisgis/geoclimate/osm/WorkflowAbstractTest.groovy @@ -19,15 +19,15 @@ */ package org.orbisgis.geoclimate.osm -import ch.qos.logback.classic.Logger import org.orbisgis.geoclimate.Geoindicators -import org.orbisgis.geoclimate.utils.LoggerUtils +import org.slf4j.Logger +import org.slf4j.LoggerFactory import static org.junit.jupiter.api.Assertions.* class WorkflowAbstractTest { - public static Logger logger = LoggerUtils.createLogger(WorkflowAbstractTest.class) + public static Logger logger = LoggerFactory.getLogger(WorkflowAbstractTest.class) /** * A method to compute geomorphological indicators diff --git a/osmtools/pom.xml b/osmtools/pom.xml index 801e718b6e..ae48b0bc67 100644 --- a/osmtools/pom.xml +++ b/osmtools/pom.xml @@ -48,10 +48,6 @@ org.slf4j slf4j-api - - ch.qos.logback - logback-classic - diff --git a/osmtools/src/main/groovy/org/orbisgis/geoclimate/osmtools/OSMTools.groovy b/osmtools/src/main/groovy/org/orbisgis/geoclimate/osmtools/OSMTools.groovy index 1fe86943ad..7c6d77472b 100644 --- a/osmtools/src/main/groovy/org/orbisgis/geoclimate/osmtools/OSMTools.groovy +++ b/osmtools/src/main/groovy/org/orbisgis/geoclimate/osmtools/OSMTools.groovy @@ -24,7 +24,6 @@ import org.orbisgis.geoclimate.osmtools.Transform as TRANSFORM import org.orbisgis.geoclimate.osmtools.utils.TransformUtils as TRANSFORM_UTILS import org.orbisgis.geoclimate.osmtools.utils.Utilities as UTILITIES import org.orbisgis.geoclimate.utils.AbstractScript -import org.orbisgis.geoclimate.utils.LoggerUtils /** * Main script to access to all processes used to extract, transform and save OSM data as GIS layers. diff --git a/osmtools/src/test/groovy/org/orbisgis/geoclimate/osmtools/LoaderTest.groovy b/osmtools/src/test/groovy/org/orbisgis/geoclimate/osmtools/LoaderTest.groovy index 70bf52ccc8..2bdd405e61 100644 --- a/osmtools/src/test/groovy/org/orbisgis/geoclimate/osmtools/LoaderTest.groovy +++ b/osmtools/src/test/groovy/org/orbisgis/geoclimate/osmtools/LoaderTest.groovy @@ -19,7 +19,6 @@ */ package org.orbisgis.geoclimate.osmtools -import ch.qos.logback.classic.Logger import org.junit.jupiter.api.* import org.junit.jupiter.api.io.TempDir import org.locationtech.jts.geom.Coordinate @@ -27,7 +26,8 @@ import org.locationtech.jts.geom.GeometryFactory import org.orbisgis.data.H2GIS import org.orbisgis.geoclimate.osmtools.utils.OSMElement import org.orbisgis.geoclimate.osmtools.utils.Utilities -import org.orbisgis.geoclimate.utils.LoggerUtils +import org.slf4j.Logger +import org.slf4j.LoggerFactory import java.util.regex.Pattern @@ -44,7 +44,7 @@ class LoaderTest extends AbstractOSMToolsTest { @TempDir static File folder - private static final Logger LOGGER = LoggerUtils.createLogger(LoaderTest) + private static final Logger LOGGER = LoggerFactory.getLogger(LoaderTest) static H2GIS ds diff --git a/osmtools/src/test/groovy/org/orbisgis/geoclimate/osmtools/TransformTest.groovy b/osmtools/src/test/groovy/org/orbisgis/geoclimate/osmtools/TransformTest.groovy index cc9286eb35..6b36ce5463 100644 --- a/osmtools/src/test/groovy/org/orbisgis/geoclimate/osmtools/TransformTest.groovy +++ b/osmtools/src/test/groovy/org/orbisgis/geoclimate/osmtools/TransformTest.groovy @@ -19,7 +19,6 @@ */ package org.orbisgis.geoclimate.osmtools -import ch.qos.logback.classic.Logger import org.h2gis.utilities.GeographyUtilities import org.junit.jupiter.api.* import org.junit.jupiter.api.io.TempDir @@ -27,7 +26,8 @@ import org.locationtech.jts.geom.* import org.orbisgis.data.H2GIS import org.orbisgis.geoclimate.osmtools.utils.OSMElement import org.orbisgis.geoclimate.osmtools.utils.Utilities -import org.orbisgis.geoclimate.utils.LoggerUtils +import org.slf4j.Logger +import org.slf4j.LoggerFactory import static org.junit.jupiter.api.Assertions.* @@ -42,7 +42,7 @@ class TransformTest extends AbstractOSMToolsTest { @TempDir static File folder - private static final Logger LOGGER = LoggerUtils.createLogger(TransformTest) + private static final Logger LOGGER = LoggerFactory.getLogger(TransformTest) static H2GIS ds diff --git a/osmtools/src/test/groovy/org/orbisgis/geoclimate/osmtools/utils/TransformUtilsTest.groovy b/osmtools/src/test/groovy/org/orbisgis/geoclimate/osmtools/utils/TransformUtilsTest.groovy index 6d428af073..bc08c7b3d5 100644 --- a/osmtools/src/test/groovy/org/orbisgis/geoclimate/osmtools/utils/TransformUtilsTest.groovy +++ b/osmtools/src/test/groovy/org/orbisgis/geoclimate/osmtools/utils/TransformUtilsTest.groovy @@ -19,7 +19,6 @@ */ package org.orbisgis.geoclimate.osmtools.utils -import ch.qos.logback.classic.Logger import org.junit.jupiter.api.* import org.junit.jupiter.api.io.CleanupMode import org.junit.jupiter.api.io.TempDir @@ -28,7 +27,8 @@ import org.locationtech.jts.geom.MultiLineString import org.orbisgis.data.H2GIS import org.orbisgis.geoclimate.osmtools.AbstractOSMToolsTest import org.orbisgis.geoclimate.osmtools.OSMTools -import org.orbisgis.geoclimate.utils.LoggerUtils +import org.slf4j.Logger +import org.slf4j.LoggerFactory import static org.junit.jupiter.api.Assertions.* @@ -43,7 +43,7 @@ class TransformUtilsTest extends AbstractOSMToolsTest { @TempDir(cleanup = CleanupMode.ON_SUCCESS) static File folder - private static final Logger LOGGER = LoggerUtils.createLogger(TransformUtilsTest) + private static final Logger LOGGER = LoggerFactory.getLogger(TransformUtilsTest) static H2GIS h2gis diff --git a/osmtools/src/test/groovy/org/orbisgis/geoclimate/osmtools/utils/UtilitiesTest.groovy b/osmtools/src/test/groovy/org/orbisgis/geoclimate/osmtools/utils/UtilitiesTest.groovy index 66c0643050..74c557521a 100644 --- a/osmtools/src/test/groovy/org/orbisgis/geoclimate/osmtools/utils/UtilitiesTest.groovy +++ b/osmtools/src/test/groovy/org/orbisgis/geoclimate/osmtools/utils/UtilitiesTest.groovy @@ -19,7 +19,6 @@ */ package org.orbisgis.geoclimate.osmtools.utils -import ch.qos.logback.classic.Logger import org.junit.jupiter.api.* import org.junit.jupiter.api.io.CleanupMode import org.junit.jupiter.api.io.TempDir @@ -30,7 +29,8 @@ import org.locationtech.jts.geom.Polygon import org.orbisgis.data.H2GIS import org.orbisgis.geoclimate.osmtools.AbstractOSMToolsTest import org.orbisgis.geoclimate.osmtools.OSMTools -import org.orbisgis.geoclimate.utils.LoggerUtils +import org.slf4j.Logger +import org.slf4j.LoggerFactory import java.util.regex.Pattern @@ -47,7 +47,7 @@ class UtilitiesTest extends AbstractOSMToolsTest { @TempDir(cleanup = CleanupMode.ON_SUCCESS) static File folder - private static final Logger LOGGER = LoggerUtils.createLogger(UtilitiesTest) + private static final Logger LOGGER = LoggerFactory.getLogger(UtilitiesTest) /** Used to store method pointer in order to replace it for the tests to avoid call to Overpass servers. */ private static def executeOverPassQuery diff --git a/pom.xml b/pom.xml index 62c5916722..ea081d8152 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,6 @@ 1.7.1-SNAPSHOT 2.1.0-SNAPSHOT 2.0.9 - 1.4.11 3.0.19 4.6.3 2.11.0 @@ -213,11 +212,6 @@ slf4j-api ${slf4j-version} - - ch.qos.logback - logback-classic - ${logback-version} - org.codehaus.groovy groovy diff --git a/worldpoptools/src/main/groovy/org/orbisgis/geoclimate/worldpoptools/WorldPopTools.groovy b/worldpoptools/src/main/groovy/org/orbisgis/geoclimate/worldpoptools/WorldPopTools.groovy index ed0568abe4..39daf9f7be 100644 --- a/worldpoptools/src/main/groovy/org/orbisgis/geoclimate/worldpoptools/WorldPopTools.groovy +++ b/worldpoptools/src/main/groovy/org/orbisgis/geoclimate/worldpoptools/WorldPopTools.groovy @@ -31,7 +31,6 @@ package org.orbisgis.geoclimate.worldpoptools import org.orbisgis.geoclimate.utils.AbstractScript -import org.orbisgis.geoclimate.utils.LoggerUtils /** * Main script to access to all WorldPop utilities diff --git a/worldpoptools/src/test/groovy/org/orbisgis/geoclimate/worldpoptools/WorldPopExtractTest.groovy b/worldpoptools/src/test/groovy/org/orbisgis/geoclimate/worldpoptools/WorldPopExtractTest.groovy index 2f6ae87683..ce2567403e 100644 --- a/worldpoptools/src/test/groovy/org/orbisgis/geoclimate/worldpoptools/WorldPopExtractTest.groovy +++ b/worldpoptools/src/test/groovy/org/orbisgis/geoclimate/worldpoptools/WorldPopExtractTest.groovy @@ -19,13 +19,13 @@ */ package org.orbisgis.geoclimate.worldpoptools -import ch.qos.logback.classic.Logger import org.h2gis.api.EmptyProgressVisitor import org.h2gis.functions.io.asc.AscReaderDriver import org.junit.jupiter.api.* import org.junit.jupiter.api.io.TempDir import org.orbisgis.data.H2GIS -import org.orbisgis.geoclimate.utils.LoggerUtils +import org.slf4j.Logger +import org.slf4j.LoggerFactory import static org.junit.jupiter.api.Assertions.* @@ -34,7 +34,7 @@ class WorldPopExtractTest { @TempDir static File folder - private static final Logger LOGGER = LoggerUtils.createLogger(WorldPopExtractTest) + private static final Logger LOGGER = LoggerFactory.getLogger(WorldPopExtractTest) private static H2GIS h2GIS @BeforeAll