mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 22:10:54 +03:00
Use System.Logger for logging with Java 9+
This commit is contained in:
@@ -27,6 +27,10 @@ if( JavaVersion.current() >= JavaVersion.VERSION_1_9 ) {
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
add("java9Compile", sourceSets.main.get().output)
|
||||
}
|
||||
|
||||
tasks {
|
||||
named<JavaCompile>( "compileJava9Java" ) {
|
||||
sourceCompatibility = "9"
|
||||
|
||||
@@ -101,7 +101,7 @@ public abstract class FlatLaf
|
||||
UIManager.setLookAndFeel( newLookAndFeel );
|
||||
return true;
|
||||
} catch( Exception ex ) {
|
||||
LoggingFacade.logSevere( "FlatLaf: Failed to initialize look and feel '" + newLookAndFeel.getClass().getName() + "'.", ex );
|
||||
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to initialize look and feel '" + newLookAndFeel.getClass().getName() + "'.", ex );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -339,7 +339,7 @@ public abstract class FlatLaf
|
||||
} else
|
||||
aquaLaf = (BasicLookAndFeel) Class.forName( aquaLafClassName ).newInstance();
|
||||
} catch( Exception ex ) {
|
||||
LoggingFacade.logSevere( "FlatLaf: Failed to initialize Aqua look and feel '" + aquaLafClassName + "'.", ex );
|
||||
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to initialize Aqua look and feel '" + aquaLafClassName + "'.", ex );
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@@ -575,7 +575,7 @@ public abstract class FlatLaf
|
||||
.invoke( null, true );
|
||||
defaults.put( key, value );
|
||||
} catch( Exception ex ) {
|
||||
LoggingFacade.logSevere( null, ex );
|
||||
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||
throw new RuntimeException( ex );
|
||||
}
|
||||
}
|
||||
@@ -682,7 +682,7 @@ public abstract class FlatLaf
|
||||
// update UI
|
||||
updateUI();
|
||||
} catch( UnsupportedLookAndFeelException ex ) {
|
||||
LoggingFacade.logSevere( "FlatLaf: Failed to reinitialize look and feel '" + lookAndFeel.getClass().getName() + "'.", ex );
|
||||
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to reinitialize look and feel '" + lookAndFeel.getClass().getName() + "'.", ex );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class IntelliJTheme
|
||||
try {
|
||||
return FlatLaf.install( createLaf( in ) );
|
||||
} catch( Exception ex ) {
|
||||
LoggingFacade.logSevere( "FlatLaf: Failed to load IntelliJ theme", ex );
|
||||
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to load IntelliJ theme", ex );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ class LinuxFontPolicy
|
||||
if( "1".equals( strs.get( 5 ) ) )
|
||||
style |= Font.ITALIC;
|
||||
} catch( RuntimeException ex ) {
|
||||
LoggingFacade.logConfig( "FlatLaf: Failed to parse 'font=" + generalFont + "'.", ex );
|
||||
LoggingFacade.INSTANCE.logConfig( "FlatLaf: Failed to parse 'font=" + generalFont + "'.", ex );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ class LinuxFontPolicy
|
||||
if( dpi < 50 )
|
||||
dpi = 50;
|
||||
} catch( NumberFormatException ex ) {
|
||||
LoggingFacade.logConfig( "FlatLaf: Failed to parse 'forceFontDPI=" + forceFontDPI + "'.", ex );
|
||||
LoggingFacade.INSTANCE.logConfig( "FlatLaf: Failed to parse 'forceFontDPI=" + forceFontDPI + "'.", ex );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ class LinuxFontPolicy
|
||||
while( (line = reader.readLine()) != null )
|
||||
lines.add( line );
|
||||
} catch( IOException ex ) {
|
||||
LoggingFacade.logConfig( "FlatLaf: Failed to read '" + filename + "'.", ex );
|
||||
LoggingFacade.INSTANCE.logConfig( "FlatLaf: Failed to read '" + filename + "'.", ex );
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
@@ -247,16 +247,16 @@ class UIDefaultsLoader
|
||||
}
|
||||
}
|
||||
} catch( IOException ex ) {
|
||||
LoggingFacade.logSevere( "FlatLaf: Failed to load properties files.", ex );
|
||||
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to load properties files.", ex );
|
||||
}
|
||||
}
|
||||
|
||||
static void logParseError( String key, String value, RuntimeException ex, boolean severe ) {
|
||||
String message = "FlatLaf: Failed to parse: '" + key + '=' + value + '\'';
|
||||
if (severe) {
|
||||
LoggingFacade.logSevere( message, ex );
|
||||
LoggingFacade.INSTANCE.logSevere( message, ex );
|
||||
} else {
|
||||
LoggingFacade.logConfig( message, ex );
|
||||
LoggingFacade.INSTANCE.logConfig( message, ex );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,7 +445,7 @@ class UIDefaultsLoader
|
||||
try {
|
||||
return findClass( value, addonClassLoaders ).newInstance();
|
||||
} catch( InstantiationException | IllegalAccessException | ClassNotFoundException ex ) {
|
||||
LoggingFacade.logSevere( "FlatLaf: Failed to instantiate '" + value + "'.", ex );
|
||||
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to instantiate '" + value + "'.", ex );
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -456,7 +456,7 @@ class UIDefaultsLoader
|
||||
try {
|
||||
return findClass( value, addonClassLoaders );
|
||||
} catch( ClassNotFoundException ex ) {
|
||||
LoggingFacade.logSevere( "FlatLaf: Failed to find class '" + value + "'.", ex );
|
||||
LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to find class '" + value + "'.", ex );
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -933,7 +933,7 @@ class UIDefaultsLoader
|
||||
|
||||
Object value = UIManager.get( uiKey );
|
||||
if( value == null && !optional )
|
||||
LoggingFacade.logSevere( "FlatLaf: '" + uiKey + "' not found in UI defaults.", null );
|
||||
LoggingFacade.INSTANCE.logSevere( "FlatLaf: '" + uiKey + "' not found in UI defaults.", null );
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ public class JBRCustomDecorations
|
||||
try {
|
||||
return (Boolean) Window_hasCustomDecoration.invoke( window );
|
||||
} catch( Exception ex ) {
|
||||
LoggingFacade.logSevere( null, ex );
|
||||
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -166,7 +166,7 @@ public class JBRCustomDecorations
|
||||
try {
|
||||
Window_setHasCustomDecoration.invoke( window );
|
||||
} catch( Exception ex ) {
|
||||
LoggingFacade.logSevere( null, ex );
|
||||
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ public class JBRCustomDecorations
|
||||
WWindowPeer_setCustomDecorationHitTestSpots.invoke( peer, hitTestSpots );
|
||||
WWindowPeer_setCustomDecorationTitleBarHeight.invoke( peer, titleBarHeight );
|
||||
} catch( Exception ex ) {
|
||||
LoggingFacade.logSevere( null, ex );
|
||||
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,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( null, ex );
|
||||
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||
throw new RuntimeException( ex );
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class JavaCompatibility
|
||||
else
|
||||
drawStringUnderlineCharAtMethod.invoke( null, c, g, text, underlinedIndex, x, y );
|
||||
} catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) {
|
||||
LoggingFacade.logSevere( null, ex );
|
||||
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||
throw new RuntimeException( ex );
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,7 @@ public class JavaCompatibility
|
||||
: "clipStringIfNecessary",
|
||||
new Class[] { JComponent.class, FontMetrics.class, String.class, int.class } );
|
||||
} catch( Exception ex ) {
|
||||
LoggingFacade.logSevere( null, ex );
|
||||
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||
throw new RuntimeException( ex );
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class JavaCompatibility
|
||||
try {
|
||||
return (String) getClippedStringMethod.invoke( null, c, fm, string, availTextWidth );
|
||||
} catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) {
|
||||
LoggingFacade.logSevere( null, ex );
|
||||
LoggingFacade.INSTANCE.logSevere( null, ex );
|
||||
throw new RuntimeException( ex );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,48 +16,11 @@
|
||||
|
||||
package com.formdev.flatlaf.util;
|
||||
|
||||
import com.formdev.flatlaf.FlatLaf;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class LoggingFacade
|
||||
public interface LoggingFacade
|
||||
{
|
||||
private static final Logger LOG = createLogger();
|
||||
LoggingFacade INSTANCE = new LoggingFacadeImpl();
|
||||
|
||||
private static Logger createLogger() {
|
||||
try {
|
||||
return Logger.getLogger( FlatLaf.class.getName() );
|
||||
} catch( Throwable e ) {
|
||||
// Module java.logging is not present
|
||||
return null;
|
||||
}
|
||||
}
|
||||
void logSevere( String message, Throwable t );
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void logConfig( String message, Throwable t );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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 LoggingFacadeImpl implements LoggingFacade
|
||||
{
|
||||
private static final Logger LOG = Logger.getLogger( FlatLaf.class.getName() );
|
||||
|
||||
public void logSevere( String message, Throwable t ) {
|
||||
LOG.log( Level.SEVERE, message, t );
|
||||
}
|
||||
|
||||
public void logConfig( String message, Throwable t ) {
|
||||
LOG.log( Level.CONFIG, message, t );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class LoggingFacadeImpl implements LoggingFacade
|
||||
{
|
||||
private static final System.Logger LOG = System.getLogger( FlatLaf.class.getName() );
|
||||
|
||||
public void logSevere( String message, Throwable t ) {
|
||||
LOG.log( System.Logger.Level.ERROR, message, t );
|
||||
}
|
||||
|
||||
public void logConfig( String message, Throwable t ) {
|
||||
LOG.log( System.Logger.Level.DEBUG, message, t );
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ class Utils
|
||||
"/com/formdev/flatlaf/intellijthemes/themes/" + name ) );
|
||||
} catch( IOException ex ) {
|
||||
String msg = "FlatLaf: Failed to load IntelliJ theme '" + name + "'";
|
||||
LoggingFacade.logSevere( msg, ex );
|
||||
LoggingFacade.INSTANCE.logSevere( msg, ex );
|
||||
throw new RuntimeException( msg, ex );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class Utils
|
||||
"/com/formdev/flatlaf/intellijthemes/themes/material-theme-ui-lite/" + name ) );
|
||||
} catch( IOException ex ) {
|
||||
String msg = "FlatLaf: Failed to load IntelliJ theme '" + name + "'";
|
||||
LoggingFacade.logSevere( msg, ex );
|
||||
LoggingFacade.INSTANCE.logSevere( msg, ex );
|
||||
throw new RuntimeException( msg, ex );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user