diff --git a/girder/girder_large_image/__init__.py b/girder/girder_large_image/__init__.py index d9faedbfa..13e831170 100644 --- a/girder/girder_large_image/__init__.py +++ b/girder/girder_large_image/__init__.py @@ -16,6 +16,7 @@ import datetime import json +import warnings from girder_jobs.constants import JobStatus from girder_jobs.models.job import Job @@ -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 diff --git a/sources/bioformats/large_image_source_bioformats/__init__.py b/sources/bioformats/large_image_source_bioformats/__init__.py index 717007a06..915a77356 100644 --- a/sources/bioformats/large_image_source_bioformats/__init__.py +++ b/sources/bioformats/large_image_source_bioformats/__init__.py @@ -29,7 +29,6 @@ import types import bioformats -import bioformats.log4j import javabridge import numpy from pkg_resources import DistributionNotFound, get_distribution @@ -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 @@ -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