LoggingFacade: moved to com.formdev.flatlaf.util, added license header, fixed NPEs in logging calls and removed overloads of logSevere

This commit is contained in:
Ingo Kegel
2021-03-10 17:06:12 +01:00
parent 343451de65
commit eedfcf86aa
10 changed files with 76 additions and 55 deletions

View File

@@ -60,6 +60,7 @@ import javax.swing.text.html.HTMLEditorKit;
import com.formdev.flatlaf.ui.FlatPopupFactory; import com.formdev.flatlaf.ui.FlatPopupFactory;
import com.formdev.flatlaf.ui.JBRCustomDecorations; import com.formdev.flatlaf.ui.JBRCustomDecorations;
import com.formdev.flatlaf.util.GrayFilter; import com.formdev.flatlaf.util.GrayFilter;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.MultiResolutionImageSupport; import com.formdev.flatlaf.util.MultiResolutionImageSupport;
import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.SystemInfo;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;

View File

@@ -34,6 +34,7 @@ import javax.swing.UIDefaults;
import javax.swing.plaf.ColorUIResource; import javax.swing.plaf.ColorUIResource;
import com.formdev.flatlaf.json.Json; import com.formdev.flatlaf.json.Json;
import com.formdev.flatlaf.json.ParseException; import com.formdev.flatlaf.json.ParseException;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.StringUtils; import com.formdev.flatlaf.util.StringUtils;
/** /**

View File

@@ -28,6 +28,8 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.StringUtils; import com.formdev.flatlaf.util.StringUtils;
import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.SystemInfo;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;

View File

@@ -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();
}
}
}
}

View File

@@ -47,6 +47,7 @@ import com.formdev.flatlaf.util.ColorFunctions.ColorFunction;
import com.formdev.flatlaf.util.DerivedColor; import com.formdev.flatlaf.util.DerivedColor;
import com.formdev.flatlaf.util.GrayFilter; import com.formdev.flatlaf.util.GrayFilter;
import com.formdev.flatlaf.util.HSLColor; import com.formdev.flatlaf.util.HSLColor;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.StringUtils; import com.formdev.flatlaf.util.StringUtils;
import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.SystemInfo;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
@@ -932,7 +933,7 @@ class UIDefaultsLoader
Object value = UIManager.get( uiKey ); Object value = UIManager.get( uiKey );
if( value == null && !optional ) 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; return value;
} }
} }

View File

@@ -38,7 +38,7 @@ import javax.swing.UIManager;
import javax.swing.plaf.BorderUIResource; import javax.swing.plaf.BorderUIResource;
import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.FlatSystemProperties; 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.HiDPIUtils;
import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.SystemInfo;

View File

@@ -22,7 +22,6 @@ import java.awt.Graphics2D;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import javax.swing.JComponent; import javax.swing.JComponent;
import com.formdev.flatlaf.LoggingFacade;
/** /**
* Provides Java version compatibility methods. * 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, Graphics2D.class, String.class, int.class, float.class, float.class }
: new Class[] { JComponent.class, Graphics.class, String.class, int.class, int.class, int.class } ); : new Class[] { JComponent.class, Graphics.class, String.class, int.class, int.class, int.class } );
} catch( Exception ex ) { } catch( Exception ex ) {
LoggingFacade.logSevere( ex ); LoggingFacade.logSevere( null, ex );
throw new RuntimeException( ex ); throw new RuntimeException( ex );
} }
} }
@@ -68,7 +67,7 @@ public class JavaCompatibility
else else
drawStringUnderlineCharAtMethod.invoke( null, c, g, text, underlinedIndex, x, y ); drawStringUnderlineCharAtMethod.invoke( null, c, g, text, underlinedIndex, x, y );
} catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) { } catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) {
LoggingFacade.logSevere( ex ); LoggingFacade.logSevere( null, ex );
throw new RuntimeException( ex ); throw new RuntimeException( ex );
} }
} }
@@ -92,7 +91,7 @@ public class JavaCompatibility
: "clipStringIfNecessary", : "clipStringIfNecessary",
new Class[] { JComponent.class, FontMetrics.class, String.class, int.class } ); new Class[] { JComponent.class, FontMetrics.class, String.class, int.class } );
} catch( Exception ex ) { } catch( Exception ex ) {
LoggingFacade.logSevere( ex ); LoggingFacade.logSevere( null, ex );
throw new RuntimeException( ex ); throw new RuntimeException( ex );
} }
} }
@@ -101,7 +100,7 @@ public class JavaCompatibility
try { try {
return (String) getClippedStringMethod.invoke( null, c, fm, string, availTextWidth ); return (String) getClippedStringMethod.invoke( null, c, fm, string, availTextWidth );
} catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) { } catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) {
LoggingFacade.logSevere( ex ); LoggingFacade.logSevere( null, ex );
throw new RuntimeException( ex ); throw new RuntimeException( ex );
} }
} }

View File

@@ -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();
}
}
}
}
}

View File

@@ -18,7 +18,7 @@ package com.formdev.flatlaf.intellijthemes;
import java.io.IOException; import java.io.IOException;
import com.formdev.flatlaf.IntelliJTheme; import com.formdev.flatlaf.IntelliJTheme;
import com.formdev.flatlaf.LoggingFacade; import com.formdev.flatlaf.util.LoggingFacade;
/** /**
* @author Karl Tauber * @author Karl Tauber

View File

@@ -18,7 +18,7 @@ package com.formdev.flatlaf.intellijthemes.materialthemeuilite;
import java.io.IOException; import java.io.IOException;
import com.formdev.flatlaf.IntelliJTheme; import com.formdev.flatlaf.IntelliJTheme;
import com.formdev.flatlaf.LoggingFacade; import com.formdev.flatlaf.util.LoggingFacade;
/** /**
* @author Karl Tauber * @author Karl Tauber