Skip to content

Commit

Permalink
Merge pull request #727 from girder/suppress-some-warnings
Browse files Browse the repository at this point in the history
Suppress some warnings
  • Loading branch information
manthey authored Dec 13, 2021
2 parents 8e8deaa + d854b7a commit a5b3e1d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
6 changes: 6 additions & 0 deletions girder/girder_large_image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import datetime
import json
import warnings

from girder_jobs.constants import JobStatus
from girder_jobs.models.job import Job
Expand Down Expand Up @@ -49,6 +50,11 @@
pass


# Girder 3 is pinned to use pymongo < 4; its warnings aren't relevant until
# that changes.
warnings.filterwarnings('ignore', category=UserWarning, module='pymongo')


def _postUpload(event):
"""
Called when a file is uploaded. We check the parent item to see if it is
Expand Down
29 changes: 23 additions & 6 deletions sources/bioformats/large_image_source_bioformats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import types

import bioformats
import bioformats.log4j
import javabridge
import numpy
from pkg_resources import DistributionNotFound, get_distribution
Expand Down Expand Up @@ -75,6 +74,28 @@ def _monitor_thread():
_stopJavabridge()


def _reduceLogging():
# As of bioformat 4.0.0, org.apache.log4j isn't in the bundled
# jar file, so setting log levels just produces needless warnings.
# bioformats.log4j.basic_config()
# javabridge.JClassWrapper('loci.common.Log4jTools').setRootLevel(
# logging.getLevelName(logger.level))
#
# This is taken from
# https://github.com/pskeshu/microscoper/blob/master/microscoper/io.py
try:
rootLoggerName = javabridge.get_static_field(
'org/slf4j/Logger', 'ROOT_LOGGER_NAME', 'Ljava/lang/String;')
rootLogger = javabridge.static_call(
'org/slf4j/LoggerFactory', 'getLogger',
'(Ljava/lang/String;)Lorg/slf4j/Logger;', rootLoggerName)
logLevel = javabridge.get_static_field(
'ch/qos/logback/classic/Level', 'WARN', 'Lch/qos/logback/classic/Level;')
javabridge.call(rootLogger, 'setLevel', '(Lch/qos/logback/classic/Level;)V', logLevel)
except Exception:
pass


def _startJavabridge(logger):
global _javabridgeStarted

Expand All @@ -85,11 +106,7 @@ def _startJavabridge(logger):
monitor.start()
try:
javabridge.start_vm(class_path=bioformats.JARS, run_headless=True)
# As of bioformat 4.0.0, org.apache.log4j isn't in the bundled
# jar file, so setting log levels just produces needless warnings.
# bioformats.log4j.basic_config()
# javabridge.JClassWrapper('loci.common.Log4jTools').setRootLevel(
# logging.getLevelName(logger.level))
_reduceLogging()
atexit.register(_stopJavabridge)
logger.info('Started JVM for Bioformats tile source.')
_javabridgeStarted = True
Expand Down

0 comments on commit a5b3e1d

Please sign in to comment.