Skip to content

Commit

Permalink
swap from log4j to logback
Browse files Browse the repository at this point in the history
  • Loading branch information
bethac07 committed Dec 17, 2021
1 parent 9e0732a commit e049cf6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions bioformats/log4j.py → bioformats/logback.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

def basic_config():
'''Configure logging for "WARN" level'''
log4j = javabridge.JClassWrapper("loci.common.Log4jTools")
log4j.enableLogging()
log4j.setRootLevel("WARN")
logback = javabridge.JClassWrapper("loci.common.LogbackTools")
logback.enableLogging()
logback.setRootLevel("WARN")
18 changes: 9 additions & 9 deletions bioformats/noseplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@
log = logging.getLogger(__name__)


class Log4JPlugin(Plugin):
class LogbackPlugin(Plugin):
'''
Plugin that initializes Log4J in order to avoid Bioformats error
Plugin that initializes Logback in order to avoid Bioformats error
messages.
'''
enabled = False
name = "log4j"
name = "logback"
score = 90 # Less than the score of javabridge.nosetests.JavaBridgePlugin

def begin(self):
javabridge.static_call("org/apache/log4j/BasicConfigurator",
javabridge.static_call("org/apache/logback/BasicConfigurator",
"configure", "()V")
log4j_logger = javabridge.static_call("org/apache/log4j/Logger",
logback_logger = javabridge.static_call("org/apache/logback/Logger",
"getRootLogger",
"()Lorg/apache/log4j/Logger;")
warn_level = javabridge.get_static_field("org/apache/log4j/Level","WARN",
"Lorg/apache/log4j/Level;")
javabridge.call(log4j_logger, "setLevel", "(Lorg/apache/log4j/Level;)V",
"()Lorg/apache/logback/Logger;")
warn_level = javabridge.get_static_field("org/apache/logback/Level","WARN",
"Lorg/apache/logback/Level;")
javabridge.call(logback_logger, "setLevel", "(Lorg/apache/logback/Level;)V",
warn_level)
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

@pytest.fixture(autouse=True, scope="session")
def setup_and_teardown():
log_config = os.path.join(os.path.split(__file__)[0], "resources", "log4j.properties")
log_config = os.path.join(os.path.split(__file__)[0], "resources", "logback.properties")

javabridge.start_vm(
args=[
"-Dlog4j.configuration=file:{}".format(log_config),
"-Dlogback.configuration=file:{}".format(log_config),
],
class_path=bioformats.JARS,
run_headless=True
Expand Down
9 changes: 0 additions & 9 deletions tests/resources/log4j.properties

This file was deleted.

9 changes: 9 additions & 0 deletions tests/resources/logback.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Set root logger level to DEBUG and its only appender to A1.
logback.rootLogger=WARN, A1

# A1 is set to be a ConsoleAppender.
logback.appender.A1=org.apache.logback.ConsoleAppender

# A1 uses PatternLayout.
logback.appender.A1.layout=org.apache.logback.PatternLayout
logback.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

0 comments on commit e049cf6

Please sign in to comment.