PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Marius Zadara   Logger   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Logger example
Class: Logger
Filter and export data of application events
Author: By
Last change:
Date: 16 years ago
Size: 2,527 bytes
 

Contents

Class file image Download
<?php

/**
 * Demo script to put the Logger at work.
 * In this script, a handler (with it's exporter) will be added to the logger
 * and a event will be generated to see if it caught.
 *
 * @author Marius Zadara <marius@zadara.org>
 * @category org.zadara.marius.logger.exceptions
 * @copyright (C) 2008 Marius Zadara <marius@zadara.org>
 * @license GNU GPL
 * @package org.zadara.marius.logger
 */


// add all the program's prerequisites
require '_interfaces/addInterfaces.php';
require
'_exceptions/addExceptions.php';
require
'_constants/addConstants.php';
require
'_classes/addClasses.php';



// EVENT EXPORTERS DEFINITIONS ////////////////////////////////////////////////////////////////////

// event exporter to the console
// this exporter will be used in both of the handlers
$consoleExporter = new ConsoleExporter();



// EVENT HANDLERS DEFINITIONS /////////////////////////////////////////////////////////////////////

// first event handler - this one will accept all the events that will pass throught the logger
$allEventHandler = new AllEventsHandler();

// second event handler - this one will accept only high levels events
$highEventLevelHandler = new HighEventLevelHandler();



// EVENT EXPORTERS TO HANDLERS ASSOCIATIONS ///////////////////////////////////////////////////////

// associate the exporter to the first and second exporter
// this is done for this demo convenience, but is not mandatory - each handler can have its custom exporter
$allEventHandler->setExporter($consoleExporter);
$highEventLevelHandler->setExporter($consoleExporter);


// LOGGER DEFINITION //////////////////////////////////////////////////////////////////////////////

// instanciate the main logger class
$logger = new Logger();

// register all the handlers previously defined
$logger->registerHandler($allEventHandler);
$logger->registerHandler($highEventLevelHandler);


// simulate the info level event
// this event will be caught by the first handler ($allEventHandler) because
// this handler accepts all the events, no matter its definition
$logger->info("My first event", Sources::$HOME, Categories::$APPLICATION, "Info based event");

// simulate the sever level event
// this event will be accepted by both of the handlers:
// > the first because it accepts all the events
// > the second because the event levels matches the required
$logger->severe("My second event", Sources::$HOME, Categories::$APPLICATION, "Severe event");


?>