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

    I recently took over a product stream whose code was approximately two years old. I was shocked to see that it didn’t have any logging mechanism in place, which scared the hell out of me. In this article, I'll explain why it scared me, and the best ways to implement logging in PHP applications.

    If there is no logging mechanism, then if there's a goof-up in a production environment, you have absolutely no idea what went wrong. The only thing which a support developer can do in this case is to reproduce the issue at the developer end, which sometimes work and sometimes don't.

    In a Lamp stack (PHP environment), logs are being generated at many places. Apache creates its logs, PHP creates its logs and MySQL also creates its logs. You can get a lot of information from these logs, especially when there are errors. The problem with these logs is that they are server-specific rather than application-specific, so they would not log anything specific to the application.

    Application logs are very important, and they must be implemented in even trivial applications. Some of the very basic reasons for which an application log is important are debugging during development, troubleshooting in a production environment, gathering statistics, fixing security loopholes, and so forth.

    Basically, application logs can be divided into the following categories.


    1. Trace logs: Trace logs are for troubleshooting. They contain the traces of what was executed when from which page and line. So trace logs are meant for developers and can be technical in nature. An example would look like this:


    02:49:06 05/07/08 [critical] 1210108746 Could not create instance with dsn mysql://:@/ C:xampphtdocsicore4includeISms.class.php 43 superadmin


    In this log the values are in the following order: server time, date, priority, timestamp, log message, filename, line number and the user who issued this.


    1. Audit logs: Audit logs keep track of logins and logouts of the users. This helps in security breaches.


    1. User logs / History: User logs are meant for end user consumption. These logs are not for troubleshooting and generally don't have priority attached to them. They serve as a history for the application. These logs should not be technical in nature. A typical example for this would be:


    02:49:06 05/07/08 A new user foo was created by superadmin



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