Home arrow PHP arrow Page 6 - Error and Exception Handling in PHP

Sending a Message to the Logging Destination - PHP

Mistakes are inevitable, in life, programming, and application submissions. You can prepare for errors by making sure your application is designed to respond to them. This two-part article explains how PHP handles errors. It is excerpted from chapter 8 of the book Beginning PHP and Oracle: From Novice to Professional, written by W. Jason Gilmore and Bob Bryla (Apress; ISBN: 1590597702).

TABLE OF CONTENTS:
  1. Error and Exception Handling in PHP
  2. Configuration Directives
  3. Displaying Errors to the Browser
  4. Error Logging
  5. Initializing PHP’s Logging Facility
  6. Sending a Message to the Logging Destination
By: Apress Publishing
Rating: starstarstarstarstar / 2
December 31, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Thesyslog()function is responsible for sending a custom message to the syslog. Its prototype follows:

int syslog(int priority, string message)

The first parameter,priority, specifies the syslog priority level, presented in order of severity here:

LOG_EMERG: A serious system problem, likely signaling a crash

LOG_ALERT: A condition that must be immediately resolved to avert jeopardizing system integrity

LOG_CRIT: A critical error, which could render a service unusable but does not necessarily place the system in danger

LOG_ERR: A general error

LOG_WARNING: A general warning

LOG_NOTICE: A normal but notable condition

LOG_INFO: A general informational message

LOG_DEBUG: Information that is typically only relevant when debugging an application

The second parameter,message, specifies the text of the message that you’d like to log. If you’d like to log the error message as provided by the PHP engine, you can include the string%min the message. This string will be replaced by the error message string (strerror) as offered by the engine at execution time.

Now that you’ve been acquainted with the relevant functions, here’s an example:

<?php
    define_syslog_variables();
    openlog("CHP8", LOG_PID, LOG_USER);
    syslog(LOG_WARNING,"Chapter 8 example warning.");
    closelog();
?>

This snippet would produce a log entry in themessagessyslog file similar to the following:

--------------------------------------------

Dec 5 20:09:29 CHP8[30326]: Chapter 8 example warning.

--------------------------------------------

 

 

Please check back Monday for the conclusion to this article.



 
 
>>> More PHP Articles          >>> More By Apress Publishing
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: