From 36e4071b7f15003b912e673f2fb345d38ae14645 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sun, 24 Mar 2024 17:29:57 +0100 Subject: [PATCH] FlatSVGIcon: use log level `CONFIG` instead of `SEVERE` and allow disabling logging (issue #823) --- CHANGELOG.md | 2 ++ .../formdev/flatlaf/extras/FlatSVGIcon.java | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8117ac9e8..4533b3b38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ FlatLaf Change Log (issue 809) - Extras: - `FlatSVGIcon` color filters now support linear gradients. (PR #817) + - `FlatSVGIcon`: Use log level `CONFIG` instead of `SEVERE` and allow + disabling logging. (issue #823) - Added support for `JSplitPane.expandableSide` client property to `FlatSplitPane`. - Native libraries: Added API version check to test whether native library diff --git a/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatSVGIcon.java b/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatSVGIcon.java index 8b32455ad..35248d624 100644 --- a/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatSVGIcon.java +++ b/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatSVGIcon.java @@ -63,6 +63,7 @@ public class FlatSVGIcon extends ImageIcon implements DisabledIconProvider { + private static boolean loggingEnabled = true; private static boolean svgCacheEnabled = true; // cache that uses soft references for values, which allows freeing SVG documents if no longer used private static final SoftCache svgCache = new SoftCache<>(); @@ -273,7 +274,8 @@ public FlatSVGIcon( InputStream in ) throws IOException { if( document == null ) { loadFailed = true; - LoggingFacade.INSTANCE.logSevere( "FlatSVGIcon: failed to load SVG icon from input stream", null ); + if( loggingEnabled ) + LoggingFacade.INSTANCE.logConfig( "FlatSVGIcon: failed to load SVG icon from input stream", null ); } } } @@ -477,7 +479,8 @@ private void update() { if( url == null ) { loadFailed = true; - LoggingFacade.INSTANCE.logConfig( "FlatSVGIcon: resource '" + name + "' not found (if using Java modules, check whether icon package is opened in module-info.java)", null ); + if( loggingEnabled ) + LoggingFacade.INSTANCE.logConfig( "FlatSVGIcon: resource '" + name + "' not found (if using Java modules, check whether icon package is opened in module-info.java)", null ); return; } } @@ -508,7 +511,8 @@ private static SVGDocument loadSVGUncached( URL url ) { SVGDocument document = svgLoader.load( url ); if( document == null ) { - LoggingFacade.INSTANCE.logSevere( "FlatSVGIcon: failed to load '" + url + "'", null ); + if( loggingEnabled ) + LoggingFacade.INSTANCE.logConfig( "FlatSVGIcon: failed to load '" + url + "'", null ); return null; } @@ -707,6 +711,16 @@ private static void lafChanged() { darkLaf = FlatLaf.isLafDark(); } + /** @since 3.4.1 */ + public static boolean isLoggingEnabled() { + return loggingEnabled; + } + + /** @since 3.4.1 */ + public static void setLoggingEnabled( boolean loggingEnabled ) { + FlatSVGIcon.loggingEnabled = loggingEnabled; + } + /** @since 3.4.1 */ public static boolean isSVGDocumentEnabled() { return svgCacheEnabled;