Login   Register  
PHP Classes
elePHPant
Icontem

File: Log.class.example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Alberto Miranda  >  Log  >  Log.class.example.php  >  Download  
File: Log.class.example.php
Role: Example script
Content type: text/plain
Description: Log class example
Class: Log
Generate log files with formatted text messages
Author: By
Last change: Creating two logs in the same dir with individual counters.
Using some other functions and one modifier.
Date: 2007-07-27 07:23
Size: 3,678 bytes
 

Contents

Class file image Download
<?php

/*
    [ Update July 7, 2007 ]
    Log.class.example.php v1.1
    
    Individual counter added
    Individual counters are used when logging to different files 
    in the same log directory.
    
    
    -------------------------------------------------------------
    

    [ Novenber 18, 2005 - Banfield, Buenos Aires, Argentina ]
    Log.class.example.php v1.0
    

    This is an example script to demonstrate de usage
    of Log.class.php.
    
    Note that both files, this one and Log.class.php were
    thought to be in the same path for you to tray this example.
    
    For the script to create the log dir and create log files
    it needs to have write permissions on the specified target.
    
    Just play around changing the example values and try
    using some log functions. It will be fun!
    
    
    
                            Happy coding!
                            
                            
                                          Alberto Miranda                                              
*/







    //--[ LOG ]--------------------------------------------------
    /*
        Generates a LOG
    */
    
        //include Log Class
        
include('Log.class.php');
        
        
//instantiate Log Class
        
$logDir="logDir";
        
$logFileName="test";
        
$headerTitle="TEST LOG";
        
$logMode="oneFile"//oneFile: each log instance goes to the same file ([logFileName].log) | oneFilePerLog: each log instance goes to a new file ([logFileName][logNumber].log
        
$counterFile="test.counter";
        
$log=new Log($logDir,$logFileName,$headerTitle$logMode$counterFile);
        
        
//log start
        
$log->logThis('f:logNumber'); //writes the log number to log file
        
$log->logThis('+ LOG START: ' $log->get_formatted_date()); //writes formatted date
        
$log->logThis('f:nl'); //writes a new line, "\n"
    //-----------------------------------------------------------
    
    
    
    //--------------------------
    //Clean log contents
    /*
        if you call this script passing "clean=yes" by get:
        http://...Log.class.example.php?cleanLog=true
        
        it will delete log folder and all of its content
    */
    
if($_GET['cleanLog']=='true'){
        
$log->clean();
        
        echo 
'LOG Contents Cleaned';
        exit;
    }
    
//--------------------------
    
    


    //now log some text, each in a new line
    
$log->logThis("Thank you for using this class!");
    
$log->logThis("I hope you find it as usefull as I do.");
    
$log->logThis("See you around on PHP Classes ok? Cheers!");
    
$log->logThis(""); //writes a new line
    
$log->logThis("f:line"); //writes a "line" separator
    
$log->logThis("f:nl"); //also writes a new line
    
$log->logThis("And don't forget about individual counters in this update!");
    
$log->logThis("f:2nl"); //writes two new lines
    
$log->logThis("CYA!");
    
        
        
        
        
        
        
        
        
    
//--[ LOG ]--------------------------------------------------
    /*
        Generates a new LOG to same dir, using a new log file
        and a new counter.
    */
    
        //include Log Class
        
include('Log.class.php');
        
        
//instantiate Log Class
        
$logDir="logDir";
        
$logFileName="test2";
        
$headerTitle="TEST2 LOG";
        
$logMode="oneFile"//oneFile: each log instance goes to the same file ([logFileName].log) | oneFilePerLog: each log instance goes to a new file ([logFileName][logNumber].log
        
$counterFile="test2.counter";
        
$log=new Log($logDir,$logFileName,$headerTitle$logMode$counterFile);
        
        
//log start
        
$log->logThis('f:logNumber'); //writes the log number to log file
        
$log->logThis('+ LOG START: ' $log->get_formatted_date()); //writes formatted date
        
$log->logThis('f:nl'); //writes a new line, "\n"
    //-----------------------------------------------------------
    
    //now log some text, each in a new line
    
$log->logThis("You've just created a new log file with individual counter!""nLine");
    
?>