Changeset 626

Show
Ignore:
Timestamp:
04/25/07 08:58:48 (2 years ago)
Author:
schst
Message:

Display logs when executing the example, replaced tabs with spaces

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/examples/logging/index.php

    r625 r626  
    1111class Bootstrap 
    1212{ 
    13    public static function main() 
    14    
    15        // initialize logger from configuration 
    16        // in a default application using the 
    17        // net.stubbles.websites.stubFrontController this can be done via the 
    18        // net.stubbles.util.log.stubLogPreInterceptor 
    19        $loggerXJConfFactory = new stubLoggerXJConfFactory(); 
    20        $loggerXJConfFactory->init(); 
     13    public static function main() 
     14   
     15        // initialize logger from configuration 
     16        // in a default application using the 
     17        // net.stubbles.websites.stubFrontController this can be done via the 
     18        // net.stubbles.util.log.stubLogPreInterceptor 
     19        $loggerXJConfFactory = new stubLoggerXJConfFactory(); 
     20        $loggerXJConfFactory->init(); 
    2121 
    22        // both request and session normally are put into your application 
    23        // classes e.g. via stub(Pre|Post)Interceptor::(pre|post)process() 
    24        // or via stubPageElement::(isAvailable|process)() 
    25        $request = new stubWebRequest(); 
    26        $session = new stubPHPSession($request, 'SID'); 
     22        // both request and session normally are put into your application 
     23        // classes e.g. via stub(Pre|Post)Interceptor::(pre|post)process() 
     24        // or via stubPageElement::(isAvailable|process)() 
     25        $request = new stubWebRequest(); 
     26        $session = new stubPHPSession($request, 'SID'); 
    2727 
    28        // now the real work for logging 
    29        // first we create a new logdata object with target trail and level 
    30        // info 
    31        // the type of the logdata object can be configured in 
    32        // config/xml/config.xml with the property net.stubbles.util.log.class 
    33        // if property not set an instance of 
    34        // net.stubbles.util.log.stubBaseLogData will be created 
    35        $logData = stubLogDataFactory::create($session, 'trail', stubLogger::LEVEL_INFO); 
     28        // now the real work for logging 
     29        // first we create a new logdata object with target trail and level 
     30        // info 
     31        // the type of the logdata object can be configured in 
     32        // config/xml/config.xml with the property net.stubbles.util.log.class 
     33        // if property not set an instance of 
     34        // net.stubbles.util.log.stubBaseLogData will be created 
     35        $logData = stubLogDataFactory::create($session, 'trail', stubLogger::LEVEL_INFO); 
    3636 
    37        // we add some more data that we want to log 
    38        $logData->addData('logging/index.php'); 
    39        $logData->addData('foo'); 
     37        // we add some more data that we want to log 
     38        $logData->addData('logging/index.php'); 
     39        $logData->addData('foo'); 
    4040 
    41        // and finally we send the logdata to all log appenders that listen for 
    42        // the level of the logdata (in this case stubLogger::LEVEL_INFO) 
    43        stubLogger::logToAll($logData); 
     41        // and finally we send the logdata to all log appenders that listen for 
     42        // the level of the logdata (in this case stubLogger::LEVEL_INFO) 
     43        stubLogger::logToAll($logData); 
    4444 
    45         // now take a look into the log directory, there should be a logfile 
    46         // named trail-Y-m-d.log containing the logdata 
    47         // the contents are 
    48         // [timestamp]|[session-id]|logging/index.php|foo 
    49     } 
     45        // now take a look into the log directory, there should be a logfile 
     46        // named trail-Y-m-d.log containing the logdata 
     47        // the contents are 
     48        // [timestamp]|[session-id]|logging/index.php|foo 
     49 
     50        // Display logs 
     51        echo '<br /><br />The logfiles:<br />'; 
     52        foreach (new DirectoryIterator(stubConfig::getLogPath()) as $log) { 
     53            if ($log->isDot()) { 
     54                continue; 
     55            } 
     56            if ($log->isDir()) { 
     57                continue; 
     58            } 
     59            printf('<b>%s</b></br /><pre>%s</pre>', $log->getFilename(), file_get_contents($log->getPathname())); 
     60        } 
     61    } 
    5062} 
    5163Bootstrap::main();