Login   Register  
PHP Classes
elePHPant
Icontem

File: LoggerDemo.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Claudius Tiberiu Iacob  >  Logger_ciacob  >  LoggerDemo.php  >  Download  
File: LoggerDemo.php
Role: Example script
Content type: text/plain
Description: See "HowToInstall.txt" for info
Class: Logger_ciacob
Log variable values to files
Author: By
Last change:
Date: 4 years ago
Size: 3,170 bytes
 

Contents

Class file image Download
<?php

    
require_once ('domit/xml_domit_include.php');
    require_once (
'ParamsProxy.php');
    require_once (
'Logger.php');

    
/**
    * Showcases the functionality of the Logger class.
    * Logger is an on-disk var_dump()ing tool for PHP developpers. You use it to log values from your
    * PHP program, at runtime.
    *
    * @author Claudius Tiberiu Iacob <claudius.iacob@gmail.com>.
    * @license Creative Commons Attribution Share Alike - Claudius Tiberiu Iacob 2009
    */
    
class LoggerDemo {

        
/**
        * @constructor
        * Logging pretty much of anything one would need: strings, integers, arrays, objects...
        */
        
public function __construct () {
            
// Log a string:
            
Logger::getInstance()->log ('This is my string');
            
// Log a number:
            
Logger::getInstance()->log (1908734619);
            
// Log an array:
            
$myArray = array ('red' => 0xff0000'green' => 0x00ff00'blue' => 0x0000ff);
            
Logger::getInstance()->log ($myArray);
            
// Log an object:
            
$myObject = new Foo();
            
Logger::getInstance()->log ($myObject);
            
// Log a resource:
            
$myResource fopen (__FILE__'r');
            
Logger::getInstance()->log ($myResource);
            
fclose ($myResource);
            
// Log the special value NULL:
            
Logger::getInstance()->log (null);
            
// Log boolean false:
            
Logger::getInstance()->log (false);
            
// Log boolean true:
            
Logger::getInstance()->log (true);
            
// Done with logging.
            //
            // Remember that you have no restrictions as to when is logging permitted; since output
            // goes to a file on disk rather than user's browser, you're not interfering with HTTP
            // headers, nor HTML layout.
            
$this->makePageContent ();
        }

        
// Less relevant class methods...
        
private function makePageContent () {
            echo 
'<?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
                "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
              <head>
                <title>LoggerDemo</title>
              </head>
                  <body>
                      <h2>Logger Demo</h2>
                      <p>This class executes a series of calls to
                      <code>Logger::getInstance()->log(...)</code> in its constructor method. Examine
                      the source code of <code>LoggerDemo.php</code> and the resulting <code>' 
.
                      
$this->getLogFileLocation() . '</code> file.
                </body>
            </html>'
;
        }

        private function 
getLogFileLocation () {
            
$configData = new DOMIT_Document();
            
$configData->loadXML ('ParamsProxy_config.xml');
            
$configFolderPath $configData->documentElement->getElementsByPath('//value'1)->getText();
            
$commonParentFolder dirname ($configFolderPath);
            if (
strpos ($commonParentFolderDIRECTORY_SEPARATOR) !==
                
strlen ($commonParentFolder) - 1) {
                
$commonParentFolder .= DIRECTORY_SEPARATOR;
            }
            
$logsFolderPath $commonParentFolder 'logs';
            
$logFilePath $logsFolderPath DIRECTORY_SEPARATOR LoggerDemo DIRECTORY_SEPARATOR .
                
'log.txt';
            return 
$logFilePath;
        }

    }
    
$loggerDemo = new LoggerDemo();

    
// Sample class to demonstrate logging of objects:
    
class Foo {
        public 
$bar 'bar';
    }
?>