PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Ante Damjanovic   ADLog   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example
Class: ADLog
Log messages of different levels to files
Author: By
Last change: replaced paths
Date: 12 years ago
Size: 2,500 bytes
 

Contents

Class file image Download
<?php
include_once("class.ADLog.php");

//simple
$log = ADLog::getInstance();
$log->Info("some logging informations");
//output file: All-default.log and Info-default.log
//output: 2012-02-16 21:25:43.000000 INFO some logging informations

//same as
ADLog::getInstance()->Info("some logging informations");
//output file: All-default.log and Info-default.log
//output: 2012-02-16 21:25:43.000000 INFO some logging informations

//Full logging Informations without Method
$someVar = Array("SomeValue", "SomeOtherValue");
$log = ADLog::getInstance();
$log->Debug("VarDump someVar:\r\n".$log->VarDump($someVar), __FILE__, null, __LINE__);
//output file: All-default.log and Debug-default.log
//output: 2012-02-16 21:54:38.000000 DEBUG E:\xampp\project\lib\adlog.php 322: VarDump someVar:
//output: array(2) {
//output: [0]=>
//output: string(9) "SomeValue"
//output: [1]=>
//output: string(14) "SomeOtherValue"
//output: }

function LogTest()
{
   
//if logging is used in a function or method
   
ADLog::getInstance("CustomFile.log")->Warn("some logging informations", null, __METHOD__);
   
//output file: All-CustomFile.log and Warn-CustomFile.log
    //output: 2012-02-16 21:25:43.000000 WARN LogTest() some logging informations

    //Full logging Informations with custom Logfile and without All-.log
   
$log = ADLog::getInstance("CustomFile.log");
   
$log->enableAll = false;
   
$log->Fatal("some logging informations", __FILE__, __METHOD__, __LINE__);
   
//output file: Fatal-CustomFile.log
    //output line: 2012-02-16 21:25:43.000000 FATAL E:\xampp\project\lib\adlog.php LogTest() 343: some logging informations

    //Full logging Informations with custom Logfile and logdir
   
$someVar = Array("SomeValue", "SomeOtherValue");
   
$log = ADLog::getInstance("CustomFile.log");
   
$log->logDir = "../LOG/";
   
$log->saveLevels = Array("Info", "Fatal");
   
$log->Fatal("VarPrint someVar:\r\n".$log->VarPrint($someVar), __FILE__, __METHOD__, __LINE__);
   
$log->Debug("VarPrint someVar:\r\n".$log->VarPrint($someVar), __FILE__, __METHOD__, __LINE__); // no ouput, Debug is not in saveLevels
    //output file: ../LOG/Fatal-CustomFile.log
    //output line: 2012-02-16 21:54:38.000000 FATAL E:\xampp\project\lib\adlog.php LogTest() 351: VarPrint someVar:
    //output line: Array
    //output line: (
    //output line: [0] => SomeValue
    //output line: [1] => SomeOtherValue
    //output line: )


}
LogTest();