From 978d5710eb34a6b6f9e7c4406f6fe5ae38424c83 Mon Sep 17 00:00:00 2001 From: Sean Arms <67096+lesserwhirls@users.noreply.github.com> Date: Thu, 3 Jul 2025 11:38:38 -0600 Subject: [PATCH] Improve netcdf4 logging Do not log to serverStartup log directly (that's a TDS detail) Do not log stacktract from JNA at info level (move that to a debug message) Do not doublelog setting the log level for the c library --- .../ucar/nc2/ffi/netcdf/NetcdfClibrary.java | 18 ++++++++---------- .../main/java/ucar/nc2/jni/netcdf/Nc4Iosp.java | 1 - 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/netcdf4/src/main/java/ucar/nc2/ffi/netcdf/NetcdfClibrary.java b/netcdf4/src/main/java/ucar/nc2/ffi/netcdf/NetcdfClibrary.java index 68b9456677..44ec719a97 100644 --- a/netcdf4/src/main/java/ucar/nc2/ffi/netcdf/NetcdfClibrary.java +++ b/netcdf4/src/main/java/ucar/nc2/ffi/netcdf/NetcdfClibrary.java @@ -14,7 +14,6 @@ /** Static methods to load the netcdf C library. */ public class NetcdfClibrary { private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(NetcdfClibrary.class); - private static org.slf4j.Logger startupLog = org.slf4j.LoggerFactory.getLogger("serverStartup"); private static final String JNA_PATH = "jna.library.path"; private static final String JNA_PATH_ENV = "JNA_PATH"; // environment var @@ -107,7 +106,7 @@ public static synchronized int setLogLevel(int level) { if (nc4 != null) { try { oldlevel = nc4.nc_set_log_level(log_level); - startupLog.info(String.format("NetcdfLoader: set log level: old=%d new=%d", oldlevel, log_level)); + log.info(String.format("NetcdfLoader: set log level: old=%d new=%d", oldlevel, log_level)); } catch (UnsatisfiedLinkError e) { // ignore } @@ -127,13 +126,14 @@ private static Nc4prototypes load() { // Make the library synchronized // nc4 = (Nc4prototypes) Native.synchronizedLibrary(nc4); nc4 = new Nc4wrapper(nc4); - startupLog.info("Nc4Iosp: NetCDF-4 C library loaded (jna_path='{}', libname='{}' version='{}').", jnaPath, - libName, getVersion()); - startupLog.debug("Netcdf nc_inq_libvers='{}' isProtected={}", nc4.nc_inq_libvers(), Native.isProtected()); + log.info("Nc4Iosp: NetCDF-4 C library loaded (jna_path='{}', libname='{}' version='{}').", jnaPath, libName, + getVersion()); + log.debug("Netcdf nc_inq_libvers='{}' isProtected={}", nc4.nc_inq_libvers(), Native.isProtected()); } catch (Throwable t) { String message = String.format("Nc4Iosp: NetCDF-4 C library not present (jna_path='%s', libname='%s').", jnaPath, libName); - startupLog.warn(message, t); + log.warn(message); + log.debug("details: ", t); } String slevel = Strings.emptyToNull(System.getProperty(JNA_LOG_LEVEL)); if (slevel != null) { @@ -144,13 +144,11 @@ private static Nc4prototypes load() { } } try { - int oldlevel = setLogLevel(log_level); - startupLog.info(String.format("Nc4Iosp: set log level: old=%d new=%d", oldlevel, log_level)); + setLogLevel(log_level); } catch (Throwable t) { String message = String.format("Nc4Iosp: could not set log level (level=%d jna_path='%s', libname='%s').", log_level, jnaPath, libName); - startupLog.warn("Nc4Iosp: " + t.getMessage()); - startupLog.warn(message); + log.debug("Nc4Iosp: " + t.getMessage()); } } return nc4; diff --git a/netcdf4/src/main/java/ucar/nc2/jni/netcdf/Nc4Iosp.java b/netcdf4/src/main/java/ucar/nc2/jni/netcdf/Nc4Iosp.java index 1994ae9875..6c1893586d 100755 --- a/netcdf4/src/main/java/ucar/nc2/jni/netcdf/Nc4Iosp.java +++ b/netcdf4/src/main/java/ucar/nc2/jni/netcdf/Nc4Iosp.java @@ -49,7 +49,6 @@ @Deprecated public class Nc4Iosp extends AbstractIOServiceProvider implements IOServiceProviderWriter { private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(Nc4Iosp.class); - private static org.slf4j.Logger startupLog = org.slf4j.LoggerFactory.getLogger("serverStartup"); public static final boolean DEBUG = false;