Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate

Advertising

DWT2 logging patch
Tuesday, July 13th, 2010 at 8:11:31pm UTC 

  1. diff -r 490206ac8a6a base/src/java/lang/exceptions.d
  2. --- a/base/src/java/lang/exceptions.d   Tue Jul 13 17:10:14 2010 +0200
  3. +++ b/base/src/java/lang/exceptions.d   Tue Jul 13 22:03:48 2010 +0200
  4. @@ -170,23 +170,22 @@
  5.  }
  6.  
  7.  /// Extension to the D Exception
  8. -void ExceptionPrintStackTrace( Exception e ){
  9. -    ExceptionPrintStackTrace( e, & getDwtLogger().error );
  10. -}
  11. -
  12. -/// Extension to the D Exception
  13. -void ExceptionPrintStackTrace( Throwable e, void delegate ( String file, ulong line, String fmt, ... ) dg ){
  14. +void ExceptionPrintStackTrace( Throwable e, bool infoOnly=false ){
  15.  version (D_Version2){
  16.      // D 2 stacktrace info is different.
  17. -    //implMissing(__FILE__, __LINE__);
  18. -    dg( e.file, e.line, e.toString() );
  19. +    // Phobos currently has stack tracing only on Linux.
  20. +    // Revisit this when that changes.
  21. +    auto print = infoOnly ? &getDwtLogger().info!() : &getDwtLogger.error!();
  22. +    print( e.file, e.line, e.toString() );
  23.  }else{
  24. +    auto print = infoOnly ? &getDwtLogger().info!(String, long, String) :
  25. +                            &getDwtLogger().error!(String, long, String);
  26.      Throwable exception = e;
  27.      while( exception !is null ){
  28. -        dg( exception.file, exception.line, "Exception in {}({}): {}", exception.file, exception.line, exception.msg );
  29. +        print( exception.file, exception.line, "Exception in {}({}): {}", exception.file, exception.line, exception.msg );
  30.          if( exception.info !is null ){
  31.              foreach( frame; exception.info ){
  32. -                dg( exception.file, exception.line, "trc {} {}", frame.file, frame.line );
  33. +                print( exception.file, exception.line, "trc {} {}", frame.file, frame.line, "" );
  34.              }
  35.          }
  36.          exception = exception.next;
  37. diff -r 490206ac8a6a base/src/java/lang/util.d
  38. --- a/base/src/java/lang/util.d Tue Jul 13 17:10:14 2010 +0200
  39. +++ b/base/src/java/lang/util.d Tue Jul 13 22:03:48 2010 +0200
  40. @@ -28,77 +28,79 @@
  41.      String GSHARED(String s) { return s; }
  42.  }
  43.  
  44. -
  45. -interface IDwtLogger {
  46. -    void trace( String file, ulong line, String fmt, ... );
  47. -    void info( String file, ulong line, String fmt, ... );
  48. -    void warn( String file, ulong line, String fmt, ... );
  49. -    void error( String file, ulong line, String fmt, ... );
  50. -    void fatal( String file, ulong line, String fmt, ... );
  51. -}
  52. -
  53.  version(Tango){
  54. -    class DwtLogger : IDwtLogger {
  55. +    class DwtLogger {
  56.          tango.util.log.Log.Logger logger;
  57.          private this( char[] name ){
  58.              logger = tango.util.log.Log.Log.lookup( name );
  59.          }
  60. -        private char[] format( String file, ulong line, String fmt, TypeInfo[] types, void* argptr ){
  61. -            auto msg = Format.convert( types, argptr, fmt );
  62. +        char[] format( T... )( String file, ulong line, String fmt, T args ){
  63. +            auto msg = Format( fmt, args );
  64.              auto text = Format( "{} {}: {}", file, line, msg );
  65.              return text;
  66.          }
  67. -        void trace( String file, ulong line, String fmt, ... ){
  68. +        void trace(T...)(String file, ulong line, String fmt, T args){
  69.              if( logger.trace ){
  70. -                logger.trace( format( file, line, fmt, _arguments, _argptr ));
  71. +                logger.trace( format( file, line, fmt, args ));
  72.              }
  73.          }
  74. -        void info( String file, ulong line, String fmt, ... ){
  75. +        void info(T...)(String file, ulong line, String fmt, T args){
  76.              if( logger.info ){
  77. -                logger.info( format( file, line, fmt, _arguments, _argptr ));
  78. +                logger.info( format( file, line, fmt, args ));
  79.              }
  80.          }
  81. -        void warn( String file, ulong line, String fmt, ... ){
  82. +        void warn(T...)(String file, ulong line, String fmt, T args){
  83.              if( logger.warn ){
  84. -                logger.warn( format( file, line, fmt, _arguments, _argptr ));
  85. +                logger.warn( format( file, line, fmt, args ));
  86.              }
  87.          }
  88. -        void error( String file, ulong line, String fmt, ... ){
  89. +        void error(T...)(String file, ulong line, String fmt, T args){
  90.              if( logger.error ){
  91. -                logger.error( format( file, line, fmt, _arguments, _argptr ));
  92. +                logger.error( format( file, line, fmt, args ));
  93.              }
  94.          }
  95. -        void fatal( String file, ulong line, String fmt, ... ){
  96. +        void fatal(T...)(String file, ulong line, String fmt, T args){
  97.              if( logger.fatal ){
  98. -                logger.fatal( format( file, line, fmt, _arguments, _argptr ));
  99. +                logger.fatal( format( file, line, fmt, args));
  100.              }
  101.          }
  102.      }
  103.  } else { // Phobos
  104. -    class DwtLogger : IDwtLogger {
  105. +    class DwtLogger {
  106.          private this( String name ){
  107.          }
  108. -        void trace( String file, ulong line, String fmt, ... ){
  109. -            std.stdio.writefln( "TRC %s %d: %s", file, line, fmt );
  110. +        private void writeLine( T... )( String prefix, String file, ulong line, String fmt, T args )
  111. +        {
  112. +            std.stdio.write( prefix, " ", file, " ", line, ": " );
  113. +            fmt = std.string.replace( fmt, "{}", "%s" );
  114. +            std.stdio.writefln(fmt, args);
  115.          }
  116. -        void info( String file, ulong line, String fmt, ... ){
  117. -            std.stdio.writefln( "INF %s %d: %s", file, line, fmt );
  118. +        void trace( T... )( String file, ulong line, String fmt, T args )
  119. +        {
  120. +            writeLine( "TRC", file, line, fmt, args );
  121.          }
  122. -        void warn( String file, ulong line, String fmt, ... ){
  123. -            std.stdio.writefln( "WRN %s %d: %s", file, line, fmt );
  124. +        void info( T... )( String file, ulong line, String fmt, T args )
  125. +        {
  126. +            writeLine( "INF", file, line, fmt, args );
  127.          }
  128. -        void error( String file, ulong line, String fmt, ... ){
  129. -            std.stdio.writefln( "ERR %s %d: %s", file, line, fmt );
  130. +        void warn( T... )( String file, ulong line, String fmt, T args )
  131. +        {
  132. +            writeLine( "WRN", file, line, fmt, args );
  133.          }
  134. -        void fatal( String file, ulong line, String fmt, ... ){
  135. -            std.stdio.writefln( "FAT %s %d: %s", file, line, fmt );
  136. +        void error( T... )( String file, ulong line, String fmt, T args )
  137. +        {
  138. +            writeLine( "ERR", file, line, fmt, args );
  139. +        }
  140. +        void fatal( T... )( String file, ulong line, String fmt, T args )
  141. +        {
  142. +            writeLine( "FAT", file, line, fmt, args );
  143.          }
  144.      }
  145.  }
  146.  
  147.  private mixin(GSHARED(`DwtLogger dwtLoggerInstance;`));
  148.  
  149. -IDwtLogger getDwtLogger(){
  150. +DwtLogger getDwtLogger(){
  151.      if( dwtLoggerInstance is null ){
  152.          synchronized{
  153.              if( dwtLoggerInstance is null ){

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right