Skip to content

Commit

Permalink
Merge pull request #851 from ebocher/logger_pb
Browse files Browse the repository at this point in the history
Fix logger info
  • Loading branch information
ebocher authored Oct 5, 2023
2 parents 85f04b8 + d890e81 commit b858e91
Show file tree
Hide file tree
Showing 23 changed files with 51 additions and 86 deletions.
5 changes: 1 addition & 4 deletions bdtopo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions common-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<logback-version>1.4.11</logback-version>
</properties>

<dependencies>
Expand All @@ -23,9 +24,14 @@
<artifactId>groovy</artifactId>
<version>${groovy-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback-version}</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {


/**
Expand All @@ -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)
}
}
6 changes: 3 additions & 3 deletions geoclimate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@
<groupId>org.orbisgis.geoclimate</groupId>
<artifactId>osmtools</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.9</version>
</dependency>

<!-- Test dependencies -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
12 changes: 4 additions & 8 deletions geoindicators/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@
<artifactId>xstream</artifactId>
<version>1.4.19</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-json</artifactId>
Expand All @@ -76,6 +68,10 @@
<groupId>org.orbisgis.geoclimate</groupId>
<artifactId>common-utils</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = [
Expand Down
13 changes: 5 additions & 8 deletions osm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,15 @@
<artifactId>geoindicators</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>org.orbisgis.geoclimate</groupId>
<artifactId>common-utils</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
1 change: 0 additions & 1 deletion osm/src/main/groovy/org/orbisgis/geoclimate/osm/OSM.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions osmtools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
*/
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
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

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
*/
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
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.*

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.*

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
Loading

0 comments on commit b858e91

Please sign in to comment.