PHP
  Home arrow PHP arrow Page 2 - 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 - Basic Design
    ( Page 2 of 5 )


    Before we move on to how we can implement logs, let's take a look at what should be the basic design consideration for logs.

    1. File system or database: To store logs, a database as well as a file can be used. The disadvantage with using a database is that the write time is longer, causing an undue load on the database server. The disadvantage with a file system is that the read and searching time is longer than the database server.

      The advantage of using a database server is better organization of the logs and better sorting, searching and display capability. So, the rule of thumb is that if the logging is being done excessively, then use a file system to log it; otherwise, you can use a database. Generally, trace logs are more frequently logged, so it would be a good idea to log them to a file system. Audit logs and user logs can be logged to a database.


    1. Priority: There should be an option for logging according to the priority, and this priority should be configurable. Sometimes logging slows the application. In that case, there should be an option of restricting the logs to higher priority issues or stop the application from logging altogether.


    1. Size limit: There should be an option to restrict the total size of the logs, otherwise they may flood the disk (in the worst case). I have seen one application which only had an option to restrict the logs by the number of days -- i.e., you could have logs for 1 day , 2 days ... n days. This application always had this problem in which it would flood the disk with logs and slow the application, because sometimes even when using a one-day window, gigabytes of logs would get created. So there has to be a configurable upper size limit if you're using a file system and a maximum number of rows if you're using a database to contain the total size of logs.


    1. Log file location: The log file location should be configurable, because in some cases you want the log to be in other drives or some location which is other than the install location.


    1. Timestamp: Log messages must contain a timestamp even though they contain the server date time. In some cases you will need to compare the logs of two application instances whose server time could be different from each other.



     
     
    >>> 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 2 Hosted by Hostway
    Stay green...Green IT