Mercurial > projects > dwt2
diff java/src/java/lang/util.d @ 18:735224fcc45f
redirected all printings to DwtLogger
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 18 Mar 2009 09:57:53 +0100 |
parents | 950d84783eac |
children | 9b96950f2c3c |
line wrap: on
line diff
--- a/java/src/java/lang/util.d Wed Mar 18 09:09:23 2009 +0100 +++ b/java/src/java/lang/util.d Wed Mar 18 09:57:53 2009 +0100 @@ -25,8 +25,63 @@ import tango.util.log.Trace; import tango.util.log.Log; import tango.text.UnicodeData; -Logger getDwtLogger(){ - return Log.lookup( "org.eclipse.swt" ); + +interface IDwtLogger { + void trace( String file, ulong line, String fmt, ... ); + void info( String file, ulong line, String fmt, ... ); + void warn( String file, ulong line, String fmt, ... ); + void error( String file, ulong line, String fmt, ... ); + void fatal( String file, ulong line, String fmt, ... ); +} + +class DwtLogger : IDwtLogger { + Logger logger; + private this( char[] name ){ + logger = Log.lookup( name ); + } + private char[] format( String file, ulong line, String fmt, TypeInfo[] types, void* argptr ){ + auto msg = Format.convert( types, argptr, fmt ); + auto text = Format( "{} {}: {}", file, line, msg ); + return text; + } + void trace( String file, ulong line, String fmt, ... ){ + if( logger.trace ){ + logger.trace( format( file, line, fmt, _arguments, _argptr )); + } + } + void info( String file, ulong line, String fmt, ... ){ + if( logger.info ){ + logger.info( format( file, line, fmt, _arguments, _argptr )); + } + } + void warn( String file, ulong line, String fmt, ... ){ + if( logger.warn ){ + logger.warn( format( file, line, fmt, _arguments, _argptr )); + } + } + void error( String file, ulong line, String fmt, ... ){ + if( logger.error ){ + logger.error( format( file, line, fmt, _arguments, _argptr )); + } + } + void fatal( String file, ulong line, String fmt, ... ){ + if( logger.fatal ){ + logger.fatal( format( file, line, fmt, _arguments, _argptr )); + } + } +} + +private DwtLogger dwtLoggerInstance; + +IDwtLogger getDwtLogger(){ + if( dwtLoggerInstance is null ){ + synchronized{ + if( dwtLoggerInstance is null ){ + dwtLoggerInstance = new DwtLogger( "dwt" ); + } + } + } + return dwtLoggerInstance; } public alias tango.text.convert.Format.Format Format; @@ -732,17 +787,17 @@ /// Extension to the D Exception void ExceptionPrintStackTrace( Exception e ){ - ExceptionPrintStackTrace( e, Stderr ); + ExceptionPrintStackTrace( e, & getDwtLogger().error ); } /// Extension to the D Exception -void ExceptionPrintStackTrace( Exception e, FormatOutput!(char) print ){ +void ExceptionPrintStackTrace( Exception e, void delegate ( String file, ulong line, String fmt, ... ) dg ){ Exception exception = e; while( exception !is null ){ - print.formatln( "Exception in {}({}): {}", exception.file, exception.line, exception.msg ); + dg( exception.file, exception.line, "Exception in {}({}): {}", exception.file, exception.line, exception.msg ); if( exception.info !is null ){ foreach( msg; exception.info ){ - print.formatln( "trc {}", msg ); + dg( exception.file, exception.line, "trc {}", msg ); } } exception = exception.next;