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: 15 years ago
Size: 2,527 bytes


Class file image Download

 * 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 <>
 * @category org.zadara.marius.logger.exceptions
 * @copyright (C) 2008 Marius Zadara <>
 * @license GNU GPL
 * @package org.zadara.marius.logger

// add all the program's prerequisites
require '_interfaces/addInterfaces.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

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

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

// register all the handlers previously defined

// 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");