cake_log.php

Go to the documentation of this file.
00001 <?php
00002 /* SVN FILE: $Id: cake_log.php 7805 2008-10-30 17:30:26Z AD7six $ */
00003 /**
00004  * Logging.
00005  *
00006  * Log messages to text files.
00007  *
00008  * PHP versions 4 and 5
00009  *
00010  * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
00011  * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
00012  *
00013  * Licensed under The MIT License
00014  * Redistributions of files must retain the above copyright notice.
00015  *
00016  * @filesource
00017  * @copyright     Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
00018  * @link          http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
00019  * @package       cake
00020  * @subpackage    cake.cake.libs
00021  * @since         CakePHP(tm) v 0.2.9
00022  * @version       $Revision: 7805 $
00023  * @modifiedby    $LastChangedBy: AD7six $
00024  * @lastmodified  $Date: 2008-10-30 13:30:26 -0400 (Thu, 30 Oct 2008) $
00025  * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
00026  */
00027 /**
00028  * Included libraries.
00029  *
00030  */
00031     if (!class_exists('File')) {
00032         require LIBS . 'file.php';
00033     }
00034 /**
00035  * Set up error level constants to be used within the framework if they are not defined within the
00036  * system.
00037  *
00038  */
00039     if (!defined('LOG_WARNING')) {
00040         define('LOG_WARNING', 3);
00041     }
00042     if (!defined('LOG_NOTICE')) {
00043         define('LOG_NOTICE', 4);
00044     }
00045     if (!defined('LOG_DEBUG')) {
00046         define('LOG_DEBUG', 5);
00047     }
00048     if (!defined('LOG_INFO')) {
00049         define('LOG_INFO', 6);
00050     }
00051 /**
00052  * Logs messages to text files
00053  *
00054  * @package       cake
00055  * @subpackage    cake.cake.libs
00056  */
00057 class CakeLog {
00058 /**
00059  * Writes given message to a log file in the logs directory.
00060  *
00061  * @param string $type Type of log, becomes part of the log's filename
00062  * @param string $msg  Message to log
00063  * @return boolean Success
00064  * @access public
00065  * @static
00066  */
00067     function write($type, $msg) {
00068         if (!defined('LOG_ERROR')) {
00069             define('LOG_ERROR', 2);
00070         }
00071         if (!defined('LOG_ERR')) {
00072             define('LOG_ERR', LOG_ERROR);
00073         }
00074         $levels = array(
00075             LOG_WARNING => 'warning',
00076             LOG_NOTICE => 'notice',
00077             LOG_INFO => 'info',
00078             LOG_DEBUG => 'debug',
00079             LOG_ERR => 'error',
00080             LOG_ERROR => 'error'
00081         );
00082 
00083         if (is_int($type) && isset($levels[$type])) {
00084             $type = $levels[$type];
00085         }
00086 
00087         if ($type == 'error' || $type == 'warning') {
00088             $filename = LOGS . 'error.log';
00089         } elseif (in_array($type, $levels)) {
00090             $filename = LOGS . 'debug.log';
00091         } else {
00092             $filename = LOGS . $type . '.log';
00093         }
00094         $output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $msg . "\n";
00095         $log = new File($filename, true);
00096         if ($log->writable()) {
00097             return $log->append($output);
00098         }
00099     }
00100 }
00101 ?>

Generated on Sun Nov 22 00:30:52 2009 for CakePHP 1.2.x.x (v1.2.4.8284) by doxygen 1.4.7