mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user