diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java index 2e27d600..d703ea3e 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java @@ -60,6 +60,7 @@ import javax.swing.text.html.HTMLEditorKit; import com.formdev.flatlaf.ui.FlatPopupFactory; import com.formdev.flatlaf.ui.JBRCustomDecorations; import com.formdev.flatlaf.util.GrayFilter; +import com.formdev.flatlaf.util.LoggingFacade; import com.formdev.flatlaf.util.MultiResolutionImageSupport; import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.UIScale; diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java index 5c66f938..e3154907 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java @@ -34,6 +34,7 @@ import javax.swing.UIDefaults; import javax.swing.plaf.ColorUIResource; import com.formdev.flatlaf.json.Json; import com.formdev.flatlaf.json.ParseException; +import com.formdev.flatlaf.util.LoggingFacade; import com.formdev.flatlaf.util.StringUtils; /** diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java index e4008b1b..71c8d9a6 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java @@ -28,6 +28,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.StringTokenizer; + +import com.formdev.flatlaf.util.LoggingFacade; import com.formdev.flatlaf.util.StringUtils; import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.UIScale; diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/LoggingFacade.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/LoggingFacade.java deleted file mode 100644 index 254d8cba..00000000 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/LoggingFacade.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.formdev.flatlaf; - -import java.util.logging.Level; -import java.util.logging.Logger; - -public class LoggingFacade -{ - private static final Logger LOG = createLogger(); - - private static Logger createLogger() { - try { - return Logger.getLogger( FlatLaf.class.getName() ); - } catch( Throwable e ) { - // Module java.logging is not present - return null; - } - } - - public static void logSevere( Throwable t ) { - logSevere( null, t ); - } - - public static void logSevere( String message ) { - logSevere( message, null ); - } - - public static void logSevere( String message, Throwable t ) { - if( LOG != null ) { - LOG.log( Level.SEVERE, message, t ); - } else { - System.err.println( message ); - t.printStackTrace(); - } - } - - public static void logConfig( String message, Throwable t ) { - if( LOG != null ) { - LOG.log( Level.CONFIG, message, t ); - } else { - if (Boolean.getBoolean( "flatLaf.logConfig" )) { - System.err.println( message ); - t.printStackTrace(); - } - } - } -} diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java index 3a8f4118..d34b3b6a 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java @@ -47,6 +47,7 @@ import com.formdev.flatlaf.util.ColorFunctions.ColorFunction; import com.formdev.flatlaf.util.DerivedColor; import com.formdev.flatlaf.util.GrayFilter; import com.formdev.flatlaf.util.HSLColor; +import com.formdev.flatlaf.util.LoggingFacade; import com.formdev.flatlaf.util.StringUtils; import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.UIScale; @@ -932,7 +933,7 @@ class UIDefaultsLoader Object value = UIManager.get( uiKey ); if( value == null && !optional ) - LoggingFacade.logSevere( "FlatLaf: '" + uiKey + "' not found in UI defaults." ); + LoggingFacade.logSevere( "FlatLaf: '" + uiKey + "' not found in UI defaults.", null ); return value; } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java index 56623e35..97f21724 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java @@ -38,7 +38,7 @@ import javax.swing.UIManager; import javax.swing.plaf.BorderUIResource; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatSystemProperties; -import com.formdev.flatlaf.LoggingFacade; +import com.formdev.flatlaf.util.LoggingFacade; import com.formdev.flatlaf.util.HiDPIUtils; import com.formdev.flatlaf.util.SystemInfo; diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java index 547d74d2..bc177a66 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java @@ -22,7 +22,6 @@ import java.awt.Graphics2D; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import javax.swing.JComponent; -import com.formdev.flatlaf.LoggingFacade; /** * Provides Java version compatibility methods. @@ -56,7 +55,7 @@ public class JavaCompatibility ? new Class[] { JComponent.class, Graphics2D.class, String.class, int.class, float.class, float.class } : new Class[] { JComponent.class, Graphics.class, String.class, int.class, int.class, int.class } ); } catch( Exception ex ) { - LoggingFacade.logSevere( ex ); + LoggingFacade.logSevere( null, ex ); throw new RuntimeException( ex ); } } @@ -68,7 +67,7 @@ public class JavaCompatibility else drawStringUnderlineCharAtMethod.invoke( null, c, g, text, underlinedIndex, x, y ); } catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) { - LoggingFacade.logSevere( ex ); + LoggingFacade.logSevere( null, ex ); throw new RuntimeException( ex ); } } @@ -92,7 +91,7 @@ public class JavaCompatibility : "clipStringIfNecessary", new Class[] { JComponent.class, FontMetrics.class, String.class, int.class } ); } catch( Exception ex ) { - LoggingFacade.logSevere( ex ); + LoggingFacade.logSevere( null, ex ); throw new RuntimeException( ex ); } } @@ -101,7 +100,7 @@ public class JavaCompatibility try { return (String) getClippedStringMethod.invoke( null, c, fm, string, availTextWidth ); } catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) { - LoggingFacade.logSevere( ex ); + LoggingFacade.logSevere( null, ex ); throw new RuntimeException( ex ); } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java new file mode 100644 index 00000000..12172f7f --- /dev/null +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java @@ -0,0 +1,63 @@ +/* + * Copyright 2020 FormDev Software GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.formdev.flatlaf.util; + +import com.formdev.flatlaf.FlatLaf; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class LoggingFacade +{ + private static final Logger LOG = createLogger(); + + private static Logger createLogger() { + try { + return Logger.getLogger( FlatLaf.class.getName() ); + } catch( Throwable e ) { + // Module java.logging is not present + return null; + } + } + + public static void logSevere( String message, Throwable t ) { + if( LOG != null ) { + LOG.log( Level.SEVERE, message, t ); + } else { + if( message != null ) { + System.err.println( message ); + } + if( t != null ) { + t.printStackTrace(); + } + } + } + + public static void logConfig( String message, Throwable t ) { + if( LOG != null ) { + LOG.log( Level.CONFIG, message, t ); + } else { + if (Boolean.getBoolean( "flatLaf.logConfig" )) { + if( message != null ) { + System.err.println( message ); + } + if( t != null ) { + t.printStackTrace(); + } + } + } + } +} diff --git a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java index a2d87c2d..0e31e66b 100644 --- a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java +++ b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java @@ -18,7 +18,7 @@ package com.formdev.flatlaf.intellijthemes; import java.io.IOException; import com.formdev.flatlaf.IntelliJTheme; -import com.formdev.flatlaf.LoggingFacade; +import com.formdev.flatlaf.util.LoggingFacade; /** * @author Karl Tauber diff --git a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java index 9faba7d1..2a1558ce 100644 --- a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java +++ b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java @@ -18,7 +18,7 @@ package com.formdev.flatlaf.intellijthemes.materialthemeuilite; import java.io.IOException; import com.formdev.flatlaf.IntelliJTheme; -import com.formdev.flatlaf.LoggingFacade; +import com.formdev.flatlaf.util.LoggingFacade; /** * @author Karl Tauber