PHP
  Home arrow PHP arrow Page 4 - Logging in PHP Applications
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Logging in PHP Applications
By: Shikhar Kumar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 12
    2008-12-08


    Table of Contents:
  • Logging in PHP Applications
  • Basic Design
  • Trace Logs
  • Code Explained
  • The writelog() function

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Logging in PHP Applications - Code Explained
    ( Page 4 of 5 )

     

    Here, we used a custom class MyLog which uses Pear::Log package (http://pear.php.net/package/Log/) through aggregation.

    We used MyLog because we might want to further customize the class according to our logging needs; in fact, we did.

    We used a global variable to configure several parameters; this global variable could be your application's global variable. The variables are:

    $myGlobal['log']['logfile'] : specifies the log file location like "f:trace.log"

    $myGlobal['log']['level'] : specifies the log level above which the logging should be done. The levels are :

    0 System is unusable

    1 Immediate action required

    2 Critical conditions

    3 Error conditions

    4 Warning conditions

    5 Normal but significant

    6 Informational

    7 Debug-level messages

    These levels are from Pear::Log library.


    $myGlobal['log']['size']: specifies the total log size. For example if you specify 32, it means 32 Mb can be the total size of the log files. Our class works by making two files of 16 MB each; once the second file nears completion, it deletes the first one. In this way, continuity is maintained in the logs.


    $ myGlobal ['log']['email_address'] = 'info@example.com' : critical log messages will be sent to this mail id.


    $ myGlobal ['log']['email_level'] = 1: log level above which (inclusive) the messages will be mailed to the email_address specified above.


    In the application, you will have to invoke the MyLog instance before using it:


    // logging object

    $objMyLog = new MyLog() ;


    Now, with this object you can log information in the application anywhere. Do make sure that the scope of this instance is global.


    // logging in a script

    $GLOBALS['objMyLog']->writelog("Could not create instance with dsn $dsn", 2, __FILE__, __LINE__) ;


    In this statement the first argument is the log message; the second argument is the priority, which is 2 here; and the third and fourth arguments are filename and line number respectively.



     
     
    >>> More PHP Articles          >>> More By Shikhar Kumar
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT