Subversion-Projekte lars-tiefland.cakephp

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/* SVN FILE: $Id: cake_log.php 7945 2008-12-19 02:16:01Z gwoo $ */
3
/**
4
 * Logging.
5
 *
6
 * Log messages to text files.
7
 *
8
 * PHP versions 4 and 5
9
 *
10
 * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
11
 * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
12
 *
13
 * Licensed under The MIT License
14
 * Redistributions of files must retain the above copyright notice.
15
 *
16
 * @filesource
17
 * @copyright     Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
18
 * @link          http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
19
 * @package       cake
20
 * @subpackage    cake.cake.libs
21
 * @since         CakePHP(tm) v 0.2.9
22
 * @version       $Revision: 7945 $
23
 * @modifiedby    $LastChangedBy: gwoo $
24
 * @lastmodified  $Date: 2008-12-18 18:16:01 -0800 (Thu, 18 Dec 2008) $
25
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
26
 */
27
/**
28
 * Included libraries.
29
 *
30
 */
31
	if (!class_exists('File')) {
32
		require LIBS . 'file.php';
33
	}
34
/**
35
 * Set up error level constants to be used within the framework if they are not defined within the
36
 * system.
37
 *
38
 */
39
	if (!defined('LOG_WARNING')) {
40
		define('LOG_WARNING', 3);
41
	}
42
	if (!defined('LOG_NOTICE')) {
43
		define('LOG_NOTICE', 4);
44
	}
45
	if (!defined('LOG_DEBUG')) {
46
		define('LOG_DEBUG', 5);
47
	}
48
	if (!defined('LOG_INFO')) {
49
		define('LOG_INFO', 6);
50
	}
51
/**
52
 * Logs messages to text files
53
 *
54
 * @package       cake
55
 * @subpackage    cake.cake.libs
56
 */
57
class CakeLog {
58
/**
59
 * Writes given message to a log file in the logs directory.
60
 *
61
 * @param string $type Type of log, becomes part of the log's filename
62
 * @param string $msg  Message to log
63
 * @return boolean Success
64
 * @access public
65
 * @static
66
 */
67
	function write($type, $msg) {
68
		if (!defined('LOG_ERROR')) {
69
			define('LOG_ERROR', 2);
70
		}
71
		if (!defined('LOG_ERR')) {
72
			define('LOG_ERR', LOG_ERROR);
73
		}
74
		$levels = array(
75
			LOG_WARNING => 'warning',
76
			LOG_NOTICE => 'notice',
77
			LOG_INFO => 'info',
78
			LOG_DEBUG => 'debug',
79
			LOG_ERR => 'error',
80
			LOG_ERROR => 'error'
81
		);
82
 
83
		if (is_int($type) && isset($levels[$type])) {
84
			$type = $levels[$type];
85
		}
86
 
87
		if ($type == 'error' || $type == 'warning') {
88
			$filename = LOGS . 'error.log';
89
		} elseif (in_array($type, $levels)) {
90
			$filename = LOGS . 'debug.log';
91
		} else {
92
			$filename = LOGS . $type . '.log';
93
		}
94
		$output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $msg . "\n";
95
		$log = new File($filename, true);
96
		if ($log->writable()) {
97
			return $log->append($output);
98
		}
99
	}
100
}
101
?>