Changeset 623

Show
Ignore:
Timestamp:
04/25/07 00:38:44 (1 year ago)
Author:
mikey
Message:

moved logging example from docroot to examples/logging and reworked it to show usage of the logging api

Files:

Legend:

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

    r618 r623  
    99      <li><a href="json-rpc">Out-of-the-box AJAX with the JSON-RPC processor</a></li> 
    1010      <li><a href="foreignClassLoaders">Loading classes from foreign resources with the Stubbles class loader</a></li> 
     11      <li><a href="logging">Logging data</a></li> 
    1112    </ul> 
    1213  </body> 
  • trunk/examples/logging/index.php

    r219 r623  
    11<?php 
    2 require '../config/php/config.php'; 
    3 require '../lib/stubbles.php'; 
    4 stubClassLoader::load('net.stubbles.util.log.stubLoggerXJConfFactory'); 
     2echo 'The PHP code:<br />'; 
     3echo highlight_file(__FILE__); 
     4 
     5require '../../config/php/config.php'; 
     6require '../bootstrap-stubbles.php'; 
     7stubClassLoader::load('net.stubbles.ipo.request.stubWebRequest', 
     8                      'net.stubbles.ipo.session.stubPHPSession', 
     9                      'net.stubbles.util.log.log', 
     10                      'net.stubbles.util.log.stubLoggerXJConfFactory'); 
    511class Bootstrap 
    612{ 
    713    public static function main() 
    814    { 
    9         stubLoggerXJConfFactory::init('../config/xml/logging.xml'); 
    10         echo '<pre>'; 
    11         var_dump(stubLogger::getInstance()); 
     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(); 
     21         
     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'); 
     27         
     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); 
     36         
     37        // we add some more data that we want to log 
     38        $logData->addData('logging/index.php'); 
     39        $logData->addData('foo'); 
     40         
     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); 
     44         
     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 
    1249    } 
    1350}