Mercurial > hg > Members > shoshi > webvirt
comparison cake/libs/log/file_log.php @ 0:261e66bd5a0c
hg init
author | Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 24 Jul 2011 21:08:31 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:261e66bd5a0c |
---|---|
1 <?php | |
2 /** | |
3 * File Storage stream for Logging | |
4 * | |
5 * PHP versions 4 and 5 | |
6 * | |
7 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | |
8 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
9 * | |
10 * Licensed under The MIT License | |
11 * Redistributions of files must retain the above copyright notice. | |
12 * | |
13 * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
14 * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project | |
15 * @package cake | |
16 * @subpackage cake.cake.libs.log | |
17 * @since CakePHP(tm) v 1.3 | |
18 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) | |
19 */ | |
20 if (!class_exists('File')) { | |
21 require LIBS . 'file.php'; | |
22 } | |
23 /** | |
24 * File Storage stream for Logging. Writes logs to different files | |
25 * based on the type of log it is. | |
26 * | |
27 * @package cake | |
28 * @subpackage cake.cake.libs.log | |
29 */ | |
30 class FileLog { | |
31 | |
32 /** | |
33 * Path to save log files on. | |
34 * | |
35 * @var string | |
36 */ | |
37 var $_path = null; | |
38 | |
39 /** | |
40 * Constructs a new File Logger. | |
41 * | |
42 * Options | |
43 * | |
44 * - `path` the path to save logs on. | |
45 * | |
46 * @param array $options Options for the FileLog, see above. | |
47 * @return void | |
48 */ | |
49 function FileLog($options = array()) { | |
50 $options += array('path' => LOGS); | |
51 $this->_path = $options['path']; | |
52 } | |
53 | |
54 /** | |
55 * Implements writing to log files. | |
56 * | |
57 * @param string $type The type of log you are making. | |
58 * @param string $message The message you want to log. | |
59 * @return boolean success of write. | |
60 */ | |
61 function write($type, $message) { | |
62 $debugTypes = array('notice', 'info', 'debug'); | |
63 | |
64 if ($type == 'error' || $type == 'warning') { | |
65 $filename = $this->_path . 'error.log'; | |
66 } elseif (in_array($type, $debugTypes)) { | |
67 $filename = $this->_path . 'debug.log'; | |
68 } else { | |
69 $filename = $this->_path . $type . '.log'; | |
70 } | |
71 $output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $message . "\n"; | |
72 $log = new File($filename, true); | |
73 if ($log->writable()) { | |
74 return $log->append($output); | |
75 } | |
76 } | |
77 } |