cvs: pear /Log/docs/examples composite.php console.php display.php error_log.php file.php mail.php pear_error_handler.php php_error_handler.php
sql.php syslog.php win.php
| From: | Jon Parise | Date: | Sat, 15 Nov 2003 08:16:49 +0000 |
| Subject: | cvs: pear /Log/docs/examples composite.php console.php display.php error_log.php file.php mail.php pear_error_handler.php php_error_handler.php sql.php syslog.php win.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-14281@lists.php.net to get a copy of this message | ||
jon Sat Nov 15 03:16:49 2003 EDT
Added files:
/pear/Log/docs/examples composite.php console.php display.php
error_log.php file.php mail.php
pear_error_handler.php
php_error_handler.php sql.php syslog.php
win.php
Log:
Adding a collection of examples.
Index: pear/Log/docs/examples/composite.php
+++ pear/Log/docs/examples/composite.php
<?php
require_once 'Log.php';
$console = &Log::singleton('console', '', 'TEST');
$file = &Log::singleton('file', 'out.log', 'TEST');
$composite = &Log::singleton('composite');
$composite->addChild($console);
$composite->addChild($file);
$composite->log('This event will be logged to both handlers.');
Index: pear/Log/docs/examples/console.php
+++ pear/Log/docs/examples/console.php
<?php
require_once 'Log.php';
$logger = &Log::singleton('console', '', 'ident');
for ($i = 0; $i < 10; $i++) {
$logger->log("Log entry $i");
}
Index: pear/Log/docs/examples/display.php
+++ pear/Log/docs/examples/display.php
<?php
require_once 'Log.php';
$conf = array('error_prepend' => '<font
color="#ff0000"><tt>',
'error_append' => '</tt></font>');
$logger = &Log::singleton('display', '', '', $conf,
PEAR_LOG_DEBUG);
for ($i = 0; $i < 10; $i++) {
$logger->log("Log entry $i");
}
Index: pear/Log/docs/examples/error_log.php
+++ pear/Log/docs/examples/error_log.php
<?php
require_once 'Log.php';
$logger = &Log::singleton('error_log', PEAR_LOG_TYPE_SYSTEM, 'ident');
for ($i = 0; $i < 10; $i++) {
$logger->log("Log entry $i");
}
Index: pear/Log/docs/examples/file.php
+++ pear/Log/docs/examples/file.php
<?php
require_once 'Log.php';
$conf = array('mode' => 0600, 'timeFormat' => '%X %x');
$logger = &Log::singleton('file', 'out.log', 'ident', $conf);
for ($i = 0; $i < 10; $i++) {
$logger->log("Log entry $i");
}
Index: pear/Log/docs/examples/mail.php
+++ pear/Log/docs/examples/mail.php
<?php
require_once 'Log.php';
$conf = array('subject' => 'Important Log Events');
$logger = &Log::singleton('mail', 'webmaster@example.com',
'ident', $conf);
for ($i = 0; $i < 10; $i++) {
$logger->log("Log entry $i");
}
Index: pear/Log/docs/examples/pear_error_handler.php
+++ pear/Log/docs/examples/pear_error_handler.php
<?php
require_once 'Log.php';
function errorHandler($error)
{
global $logger;
$message = $error->getMessage();
if (!empty($error->backtrace[1]['file'])) {
$message .= ' (' . $error->backtrace[1]['file'];
if (!empty($error->backtrace[1]['line'])) {
$message .= ' at line ' . $error->backtrace[1]['line'];
}
$message .= ')';
}
$logger->log($message, $error->code);
}
$logger = &Log::singleton('console', '', 'ident');
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'errorHandler');
PEAR::raiseError('This is an information log message.', PEAR_LOG_INFO);
Index: pear/Log/docs/examples/php_error_handler.php
+++ pear/Log/docs/examples/php_error_handler.php
<?php
require_once 'Log.php';
function errorHandler($code, $message, $file, $line)
{
global $logger;
/* Map the PHP error to a Log priority. */
switch ($code) {
case E_WARNING:
case E_USER_WARNING:
$priority = PEAR_LOG_WARNING;
break;
case E_NOTICE:
case E_USER_NOTICE:
$priority = PEAR_LOG_NOTICE;
break;
case E_ERROR:
case E_USER_ERROR:
$priority = PEAR_LOG_ERR;
break;
default:
$priotity = PEAR_LOG_INFO;
}
$logger->log($message . ' in ' . $file . ' at line ' . $line,
$priority);
}
$logger = &Log::singleton('console', '', 'ident');
set_error_handler('errorHandler');
trigger_error('This is an information log message.', E_USER_NOTICE);
Index: pear/Log/docs/examples/sql.php
+++ pear/Log/docs/examples/sql.php
<?php
require_once 'Log.php';
$conf = array('dsn' => 'pgsql://jon@localhost+unix/logs');
$logger = &Log::singleton('sql', 'log_table', 'ident', $conf);
for ($i = 0; $i < 10; $i++) {
$logger->log("Log entry $i");
}
Index: pear/Log/docs/examples/syslog.php
+++ pear/Log/docs/examples/syslog.php
<?php
require_once 'Log.php';
$logger = &Log::singleton('syslog', LOG_LOCAL0, 'ident');
for ($i = 0; $i < 10; $i++) {
$logger->log("Log entry $i");
}
Index: pear/Log/docs/examples/win.php
+++ pear/Log/docs/examples/win.php
<?php
require_once 'Log.php';
$conf = array('title' => 'Sample Log Output');
$logger = &Log::singleton('win', 'LogWindow', 'ident', $conf);
for ($i = 0; $i < 10; $i++) {
$logger->log("Log entry $i");
}