Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3616

Show
Ignore:
Timestamp:
06/13/08 16:31:06 (6 months ago)
Author:
kris
Message:

removed support for lazy delegates, since their usage is just too awkward

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/example/logging/context.d

    r3029 r3616  
    233233    Log.getRootLogger.addAppender(appender); 
    234234 
    235     char[128] tmp = 0; 
    236235    auto log = Log.getLogger("context");     
    237236    log.setLevel(log.Level.Info); 
     
    240239    //calls should count in the test. 
    241240    for (int i=0;i < 10; i++) { 
    242         log.info(log.format(tmp, "test1 {}", i)); 
    243         log.trace(log.format(tmp, "test1 {}", i)); 
     241        log.info("test1 {}", i); 
     242        log.trace("test1 {}", i); 
    244243    } 
    245244    if (appender.events !is 10) { 
    246         log.error(log.format(tmp, "events:{}", appender.events)); 
     245        log.error("events:{}", appender.events); 
    247246        throw new Exception("Incorrect Number of events in normal mode");    
    248247    } 
     
    255254    Log.getHierarchy.context(context); 
    256255    for (int i=0;i < 10; i++) { 
    257         log.info(log.format(tmp, "test2 {}", i)); 
    258         log.trace(log.format(tmp, "test2 {}", i)); 
     256        log.info(tmp, "test2 {}", i); 
     257        log.trace("test2 {}", i); 
    259258    } 
    260259    if (appender.events !is 10) { 
    261         log.error(log.format(tmp, "events:{}", appender.events)); 
     260        log.error("events:{}", appender.events); 
    262261        throw new Exception("Incorrect Number of events in TLS single thread mode");     
    263262    } 
     
    270269    context.setLevel(log.Level.Trace); 
    271270    for (int i=0;i < 10; i++) { 
    272         log.info(log.format(tmp, "test3 {}", i)); 
    273         log.trace(log.format(tmp, "test3 {}", i)); 
     271        log.info("test3 {}", i); 
     272        log.trace("test3 {}", i); 
    274273    } 
    275274    if (appender.events !is 20) { 
    276         log.error(log.format(tmp, "events:{}", appender.events)); 
     275        log.error("events:{}", appender.events); 
    277276        throw new Exception("Incorrect Number of events in TLS single thread mode with level set");  
    278277    } 
     
    283282    context.setLevel(log.Level.None); 
    284283    for (int i=0;i < 10; i++) { 
    285         log.info(log.format(tmp, "test4 {}", i)); 
    286         log.trace(log.format(tmp, "test4 {}", i)); 
     284        log.info("test4 {}", i); 
     285        log.trace("test4 {}", i); 
    287286    } 
    288287    if (appender.events !is 10) { 
    289         log.error(log.format(tmp, "events:{}", appender.events)); 
     288        log.error("events:{}", appender.events); 
    290289        throw new Exception("Incorrect Number of events in TLS single thread mode after level reset");   
    291290    } 
     
    296295    ThreadGroup tg = new ThreadGroup(); 
    297296    tg.create({ 
    298         char[128] tmp = 0; 
    299297        context.setLevel(log.Level.Trace);         
    300298        context.push("specialthread"); 
    301299        context.push("2ndlevel"); 
    302300        for (int i=0;i < 10; i++) { 
    303              log.info(log.format(tmp, "test5 {}", i)); 
    304              log.trace(log.format(tmp, "test5 {}", i)); 
     301             log.info("test5 {}", i); 
     302             log.trace("test5 {}", i); 
    305303        } 
    306304    }); 
    307305    tg.create({ 
    308         char[128] tmp = 0;       
    309306        context.setLevel(log.Level.None); 
    310307        for (int i=0;i < 10; i++) { 
    311              log.info(log.format(tmp, "test6 {}", i)); 
    312              log.trace(log.format(tmp, "test6 {}", i)); 
     308             log.info("test6 {}", i); 
     309             log.trace("test6 {}", i); 
    313310        } 
    314311    }); 
     
    316313     
    317314    if (appender.events !is 30) { 
    318         log.error(log.format(tmp, "events:{}", appender.events)); 
     315        log.error("events:{}", appender.events); 
    319316        throw new Exception("Incorrect Number of events in TLS multi thread mode");  
    320317    }    
  • trunk/example/logging/logging.d

    r3485 r3616  
    3434                } 
    3535 
    36                 // get a log formatting instance 
    37                 auto format = Log.format; 
    38  
    3936                // information level 
    40                 log.info (format ("Searching prime numbers up to {}", max)); 
     37                log.info ("Searching prime numbers up to {}", max); 
    4138 
    4239                feld = (new byte[max / 16 + 1]).ptr; 
     
    4744                           if  ((++hits & 0x0f) == 0)  
    4845                                // more information level 
    49                                 log.info (format ("found {}", hits));  
     46                                log.info ("found {}", hits);  
    5047 
    5148                           for (mom=3*teste; mom < max; mom += teste<<1)  
     
    5552                if (hits) 
    5653                    // more information 
    57                     log.info (format ("{} prime numbers found", hits)); 
     54                    log.info ("{} prime numbers found", hits); 
    5855                else 
    5956                   // a warning level 
     
    7269                           // log trace information 
    7370                           if (! test (feld, count))  
    74                                  log.trace (format ("prime found: {}", count)); 
     71                                 log.trace ("prime found: {}", count); 
    7572                   } 
    7673} 
  • trunk/tango/util/log/Log.d

    r3572 r3616  
    55        license:        BSD style: $(LICENSE) 
    66       
    7         version:        Initial release: May 2004 
    8         version:        Hierarchy moved due to circular dependencies; Oct 2004 
    9          
     7        version:        May 2004 : Initial release 
     8        version:        Oct 2004: Hierarchy moved due to circular dependencies 
     9        version:        Apr 2008: Lazy delegates removed due to awkward usage 
    1010        author:         Kris 
    1111 
     
    1616        For example, a typical name might be something like "mail.send.writer" 
    1717        --- 
    18         import tango.util.log.Log; 
     18        import tango.util.log.Log;format 
    1919         
    2020        auto log = Log.lookup ("mail.send.writer"); 
    2121 
    2222        log.info  ("an informational message"); 
    23         log.error ("an exception message: " ~ exception.toString); 
     23        log.error ("an exception message: {}", exception.toString); 
    2424 
    2525        etc ... 
     
    3939        --- 
    4040 
    41         Messages passed to a Logger are assumed to be pre-formatted. You  
    42         may find that the format() methos is handy for collating various  
    43         components of the message:  
    44         --- 
    45         auto format = Log.format; 
    46         ... 
    47         log.warn (format ("temperature is {} degrees!", 101)); 
    48         --- 
    49  
    50         Note that a provided workspace is used to format the message, which  
    51         should generally be located on the stack so as to support multiple 
    52         threads of execution. In the example above we indicate assignment as  
    53         "tmp = void", although this is an optional attribute (see the language  
    54         manual for more information). 
    55  
    56         To avoid overhead when constructing formatted messages, the logging 
    57         system employs lazy expressions such that the message is not constructed 
    58         unless the logger is actually active. You can also explicitly check to 
    59         see whether a logger is active or not: 
    60         --- 
    61         if (log.isEnabled (log.Level.Warn)) 
    62             log.warn (format ("temperature is {} degrees!", 101)); 
    63         --- 
    64  
    65         You might optionally configure various layout & appender implementations 
    66         to support specific rendering needs. 
    67          
     41        Messages passed to a Logger are assumed to be either self-contained 
     42        or configured with "{}" notation a la Layout & Stdout: 
     43        --- 
     44        log.warn ("temperature is {} degrees!", 101); 
     45        --- 
     46 
     47        Note that an internal workspace is used to format the message, which 
     48        is limited to 2000 bytes. Use "{.256}" truncation notation to limit 
     49        the size of individual message components, or use explicit formatting: 
     50        --- 
     51        char[4096] buf = void; 
     52 
     53        log.warn (log.format (buf, "a very long warning: {}", someLongWarning); 
     54        --- 
     55 
     56        To avoid overhead when constructing argument passed to formatted  
     57        messages, you should check to see whether a logger is active or not: 
     58        --- 
     59        if (log.enabled (log.Level.Warn)) 
     60            log.warn ("temperature is {} degrees!", complexFunction()); 
     61        --- 
     62         
     63        The above will be handled implicitly by the logging system when  
     64        macros are added to the language (used to be handled implicitly  
     65        via lazy delegates, but usage of those turned out to be awkward). 
     66 
    6867        tango.log closely follows both the API and the behaviour as documented  
    6968        at the official Log4J site, where you'll find a good tutorial. Those  
     
    328327        /*********************************************************************** 
    329328         
    330                 Format support for use with existing log instances. We have 
    331                 to do it this way because log instances are shared, and the 
    332                 formatting buffer must be on the stack instead (in order to 
    333                 avoid potential thread contention). Typical usage is: 
    334                 --- 
    335                 auto format = Log.format; 
    336                 ... 
    337                 log.trace (format ("{} trace {}", 'a', "message")); 
    338                 ... 
    339                 log.info (format ("{} {} {}", "an", "info", "message")); 
    340                 ... 
    341                 --- 
    342  
    343                 Setting a larger buffer size than the default (of 512): 
    344                 --- 
    345                 char[2048] buf = void; 
    346                 auto format = Log.format (buf); 
    347  
    348                 log.trace (format ("{} formatted {}", 'a', "string")); 
    349                 ... 
    350                 --- 
    351  
    352                 Note that this is a struct, and is thus allocated on the  
    353                 stack. Note also that the format() call is *not* invoked 
    354                 unless the log instance is actually enabled - meaning we 
    355                 pay only for what will be emitted. 
    356  
    357         ***********************************************************************/ 
    358  
    359         static Sprint format (char[] buffer = null) 
    360         { 
    361                 Sprint sprint = void; 
    362          
    363                 if (buffer.length is 0) 
    364                     buffer = sprint.tmp; 
    365          
    366                 sprint.buffer = buffer; 
    367                 return sprint; 
    368         } 
    369  
    370         /*********************************************************************** 
    371          
    372329                Initialize a snapshot for a specific logging level, and  
    373330                with an optional buffer. Default buffer size is 1024 
     
    375332        ***********************************************************************/ 
    376333 
    377         static Snapshot snapshot (Logger owner, Level level, char[] buffer = null) 
     334        static private Snapshot snapshot (Logger owner, Level level, char[] buffer = null) 
    378335        { 
    379336                assert (owner); 
     
    388345                snap.next = 0; 
    389346                return snap; 
    390         } 
    391  
    392         /*********************************************************************** 
    393          
    394         ***********************************************************************/ 
    395  
    396         private struct Sprint 
    397         { 
    398                 private char[]    buffer; 
    399                 private char[512] tmp = void; 
    400          
    401                 char[] opCall (char[] formatStr, ...) 
    402                 { 
    403                         return Format.vprint (buffer, formatStr, _arguments, _argptr);                 
    404                 } 
    405347        } 
    406348} 
     
    435377*******************************************************************************/ 
    436378 
    437 public struct Snapshot 
     379private struct Snapshot 
    438380{ 
    439381        private Logger          owner; 
     
    494436        For example, a typical name might be something like "mail.send.writer" 
    495437        --- 
    496         import tango.util.log.Log; 
     438        import tango.util.log.Log;format 
    497439         
    498440        auto log = Log.lookup ("mail.send.writer"); 
    499441 
    500442        log.info  ("an informational message"); 
    501         log.error ("an exception message: " ~ exception.toString); 
     443        log.error ("an exception message: {}", exception.toString); 
    502444 
    503445        etc ... 
     
    517459        --- 
    518460 
    519         Messages passed to a Logger are assumed to be pre-formatted. You  
    520         may find that the format() methos is handy for collating various  
    521         components of the message:  
    522         --- 
    523         auto format = Log.format; 
    524         ... 
    525         log.warn (format ("temperature is {} degrees!", 101)); 
    526         --- 
    527  
    528         Note that a provided workspace is used to format the message, which  
    529         should generally be located on the stack so as to support multiple 
    530         threads of execution. In the example above we indicate assignment as  
    531         "tmp = void", although this is an optional attribute (see the language  
    532         manual for more information). 
    533  
    534         To avoid overhead when constructing formatted messages, the logging 
    535         system employs lazy expressions such that the message is not constructed 
    536         unless the logger is actually active. You can also explicitly check to 
    537         see whether a logger is active or not: 
    538         --- 
    539         if (log.isEnabled (log.Level.Warn)) 
    540             log.warn (format ("temperature is {} degrees!", 101)); 
    541         --- 
    542  
    543         You might optionally configure various layout & appender implementations 
    544         to support specific rendering needs. 
    545          
     461        Messages passed to a Logger are assumed to be either self-contained 
     462        or configured with "{}" notation a la Layout & Stdout: 
     463        --- 
     464        log.warn ("temperature is {} degrees!", 101); 
     465        --- 
     466 
     467        Note that an internal workspace is used to format the message, which 
     468        is limited to 2000 bytes. Use "{.256}" truncation notation to limit 
     469        the size of individual message components, or use explicit formatting: 
     470        --- 
     471        char[4096] buf = void; 
     472 
     473        log.warn (log.format (buf, "a very long warning: {}", someLongWarning); 
     474        --- 
     475 
     476        To avoid overhead when constructing argument passed to formatted  
     477        messages, you should check to see whether a logger is active or not: 
     478        --- 
     479        if (log.enabled (log.Level.Warn)) 
     480            log.warn ("temperature is {} degrees!", complexFunction()); 
     481        --- 
     482         
     483        The above will be handled implicitly by the logging system when  
     484        macros are added to the language (used to be handled implicitly  
     485        via lazy delegates, but usage of those turned out to be awkward). 
     486 
    546487        tango.log closely follows both the API and the behaviour as documented  
    547488        at the official Log4J site, where you'll find a good tutorial. Those  
     
    626567        ***********************************************************************/ 
    627568 
    628         final Logger trace (lazy char[] msg
    629         { 
    630                 return append (Level.Trace, msg); 
     569        final Logger trace (char[] fmt, ...
     570        { 
     571                return format (Level.Trace, fmt, _arguments, _argptr); 
    631572        } 
    632573 
     
    637578        ***********************************************************************/ 
    638579 
    639         final void trace (lazy void dg) 
     580        private void trace (lazy void dg) 
    640581        { 
    641582                if (enabled (Level.Trace)) 
     
    649590        ***********************************************************************/ 
    650591 
    651         final Logger info (lazy char[] msg
    652         { 
    653                 return append (Level.Info, msg); 
     592        final Logger info (char[] fmt, ...
     593        { 
     594                return format (Level.Info, fmt, _arguments, _argptr); 
    654595        } 
    655596 
     
    660601        ***********************************************************************/ 
    661602 
    662         final void info (lazy void dg) 
     603        private void info (lazy void dg) 
    663604        { 
    664605                if (enabled (Level.Info)) 
     
    672613        ***********************************************************************/ 
    673614 
    674         final Logger warn (lazy char[] msg
    675         { 
    676                 return append (Level.Warn, msg); 
     615        final Logger warn (char[] fmt, ...
     616        { 
     617                return format (Level.Warn, fmt, _arguments, _argptr); 
    677618        } 
    678619 
     
    683624        ***********************************************************************/ 
    684625 
    685         final void warn (lazy void dg) 
     626        private void warn (lazy void dg) 
    686627        { 
    687628                if (enabled (Level.Warn)) 
     
    695636        ***********************************************************************/ 
    696637 
    697         final Logger error (lazy char[] msg
    698         { 
    699                 return append (Level.Error, msg); 
     638        final Logger error (char[] fmt, ...
     639        { 
     640                return format (Level.Error, fmt, _arguments, _argptr); 
    700641        } 
    701642 
     
    706647        ***********************************************************************/ 
    707648 
    708         final void error (lazy void dg) 
     649        private void error (lazy void dg) 
    709650        { 
    710651                if (enabled (Level.Error)) 
     
    718659        ***********************************************************************/ 
    719660 
    720         final Logger fatal (lazy char[] msg
    721         { 
    722                 return append (Level.Fatal, msg); 
     661        final Logger fatal (char[] fmt, ...
     662        { 
     663                return format (Level.Fatal, fmt, _arguments, _argptr); 
    723664        } 
    724665 
     
    729670        ***********************************************************************/ 
    730671 
    731         final void fatal (lazy void dg) 
     672        private void fatal (lazy void dg) 
    732673        { 
    733674                if (enabled (Level.Fatal)) 
     
    912853        final char[] format (char[] buffer, char[] formatStr, ...) 
    913854        { 
    914                 return format (_arguments, _argptr, formatStr, buffer);      
     855                return Format.vprint (buffer, formatStr, _arguments, _argptr); 
    915856        } 
    916857 
     
    922863        ***********************************************************************/ 
    923864 
    924         final char[] format (TypeInfo[] arguments, ArgList argptr, char[] formatStr, char[] scratchpad
     865        final Logger format (Level level, char[] fmt, TypeInfo[] types, ArgList args
    925866        {     
    926                 return Format.vprint (scratchpad, formatStr, arguments, argptr);                 
     867                char[2048] tmp = void; 
     868  
     869                if (types.length) 
     870                    append (level, Format.vprint (tmp, fmt, types, args)); 
     871                else 
     872                   append (level, fmt);                 
     873                return this; 
    927874        } 
    928875 
     
    17391686                Log.config (Cerr.stream); 
    17401687                auto log = Log.lookup ("fu.bar"); 
    1741                 log.level = log.level.Info
     1688                log.level = log.level.Trace
    17421689                // traditional usage 
    1743                 log.trace ("hello"); 
     1690                log.trace ("hello {}", "world"); 
    17441691 
    17451692                // formatted output 
     1693/*                / 
    17461694                auto format = Log.format; 
    17471695                log.info (format ("blah{}", 1)); 
     
    17511699                snap.format ("arg{}; ", 1); 
    17521700                snap.format ("arg{}; ", 2); 
    1753                 log.trace (snap.format ("error! arg{}", 3)); 
     1701                //log.trace (snap.format ("error! arg{}", 3)); 
    17541702                snap.flush; 
     1703*/ 
    17551704        } 
    17561705} 
  • trunk/tango/util/log/model/ILogger.d

    r3485 r3616  
    3535        ***********************************************************************/ 
    3636 
    37         ILogger trace (lazy char[] msg); 
     37        ILogger trace (char[] fmt, ...); 
    3838 
    3939        /*********************************************************************** 
     
    4343        ***********************************************************************/ 
    4444 
    45         void trace (lazy void dg); 
     45        //void trace (lazy void dg); 
    4646 
    4747        /*********************************************************************** 
     
    5151        ***********************************************************************/ 
    5252 
    53         ILogger info (lazy char[] msg); 
     53        ILogger info (char[] fmt, ...); 
    5454         
    5555        /*********************************************************************** 
     
    5959        ***********************************************************************/ 
    6060 
    61         void info (lazy void dg); 
     61        //void info (lazy void dg); 
    6262 
    6363        /*********************************************************************** 
     
    6767        ***********************************************************************/ 
    6868 
    69         ILogger warn (lazy char[] msg); 
     69        ILogger warn (char[] fmt, ...); 
    7070 
    7171        /*********************************************************************** 
     
    7575        ***********************************************************************/ 
    7676 
    77         void warn (lazy void dg); 
     77        //void warn (lazy void dg); 
    7878         
    7979        /*********************************************************************** 
     
    8383        ***********************************************************************/ 
    8484 
    85         ILogger error (lazy char[] msg); 
     85        ILogger error (char[] fmt, ...); 
    8686 
    8787        /*********************************************************************** 
     
    9191        ***********************************************************************/ 
    9292 
    93         void error (lazy void dg); 
     93        //void error (lazy void dg); 
    9494 
    9595        /*********************************************************************** 
     
    9999        ***********************************************************************/ 
    100100 
    101         ILogger fatal (lazy char[] msg); 
     101        ILogger fatal (char[] fmt, ...); 
    102102 
    103103        /*********************************************************************** 
     
    107107        ***********************************************************************/ 
    108108 
    109         void fatal (lazy void dg); 
     109        //void fatal (lazy void dg); 
    110110 
    111111        /***********************************************************************