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

Changeset 2596

Show
Ignore:
Timestamp:
10/02/07 02:12:48 (1 year ago)
Author:
kris
Message:

updated to use log.format()

Files:

Legend:

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

    r2465 r2596  
    88               tango.util.log.Configurator; 
    99 
    10 private import tango.text.convert.Sprint; 
     10/******************************************************************************* 
    1111 
    12 /******************************************************************************* 
     12        Search for a set of prime numbers 
    1313 
    1414*******************************************************************************/ 
    1515 
    16 private class Sieve 
    17 
    18         private Logger logger; 
    19          
    20         /*********************************************************************** 
    21  
    22                 Initialize the Sieve class  
    23  
    24         ***********************************************************************/ 
    25  
    26         this() 
    27         { 
    28                 // get a logger for this object. Could make this static instead 
    29                 logger = Log.getLogger ("example.logging.Sieve"); 
    30         } 
    31  
    32         /*********************************************************************** 
    33  
    34                 Search for a set of prime numbers 
    35  
    36         ***********************************************************************/ 
    37  
    38         void compute (uint max) 
     16void compute (Logger log, uint max) 
    3917        { 
    4018                byte*   feld; 
     
    4523                        e = 1; 
    4624                int     count; 
    47                 auto    sprint = new Sprint!(char)
     25                char    tmp[128] = void
    4826 
    4927                void set (byte* f, uint x) 
     
    5836 
    5937                // information level 
    60                 logger.info (sprint ("Searching prime numbers to : {0}", max)); 
     38                log.info (log.format (tmp, "Searching prime numbers up to {}", max)); 
    6139 
    6240                feld = (new byte[max / 16 + 1]).ptr; 
    6341 
    6442                // get milliseconds since application began 
    65                 auto begin = logger.runtime()
     43                auto begin = log.runtime
    6644 
    6745                while ((teste += 2) < max) 
     
    7048                           if  ((++hits & 0x0f) == 0)  
    7149                                // more information level 
    72                                 logger.info (sprint ("found {0}", hits));  
     50                                log.info (log.format (tmp, "found {}", hits));  
    7351 
    7452                           for (mom=3*teste; mom < max; mom += teste<<1)  
     
    7755 
    7856                // get number of milliseconds we took to compute 
    79                 auto period = logger.runtime() - begin; 
     57                auto period = log.runtime - begin; 
    8058 
    8159                if (hits) 
    8260                    // more information 
    83                     logger.info (sprint ("{0} prime numbers found in {1} millsecs", hits, period)); 
     61                    log.info (log.format (tmp, "{} prime numbers found in {} millsecs", hits, period)); 
    8462                else 
    8563                   // a warning level 
    86                    logger.warn ("no prime numbers found"); 
     64                   log.warn ("no prime numbers found"); 
    8765         
    8866                // check to see if we're enabled for  
    8967                // tracing before we expend a lot of effort 
    90                 if (logger.isEnabled (logger.Level.Trace)) 
     68                if (log.isEnabled (log.Level.Trace)) 
    9169                   {         
    9270                   e = max; 
     
    9876                           // log trace information 
    9977                           if (! test (feld, count))  
    100                                logger.trace (sprint ("prime found: {0}", count)); 
     78                                 log.trace (log.format (tmp, "prime found: {}", count)); 
    10179                   } 
    102         } 
    10380} 
    10481 
     
    10683/******************************************************************************* 
    10784 
    108         Create a Sieve and have it compute a bunch of prime numbers. 
     85        Compute a bunch of prime numbers 
    10986 
    11087*******************************************************************************/ 
     
    11491        // get a logger to represent this module. We could just as 
    11592        // easily share a name with some other module(s) 
    116         auto logger = Log.getLogger ("example.logging"); 
    117          
     93        auto log = Log.getLogger ("example.logging"); 
    11894        try { 
    119             Sieve sieve = new Sieve; 
    120  
    121             sieve.compute (1000); 
     95            compute (log, 1000); 
    12296 
    12397            } catch (Exception x) 
    12498                    { 
    12599                    // log the exception as an error 
    126                     logger.error ("Exception: " ~ x.toUtf8); 
     100                    log.error ("Exception: " ~ x.toUtf8); 
    127101                    } 
    128102}