1: <?php
2: /**
3: * File Storage stream for Logging
4: *
5: * PHP 5
6: *
7: * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
8: * Copyright 2005-2012, 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-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
14: * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
15: * @package Cake.Log.Engine
16: * @since CakePHP(tm) v 1.3
17: * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
18: */
19:
20: App::uses('CakeLogInterface', 'Log');
21:
22: /**
23: * File Storage stream for Logging. Writes logs to different files
24: * based on the type of log it is.
25: *
26: * @package Cake.Log.Engine
27: */
28: class FileLog implements CakeLogInterface {
29:
30: /**
31: * Path to save log files on.
32: *
33: * @var string
34: */
35: protected $_path = null;
36:
37: /**
38: * Constructs a new File Logger.
39: *
40: * Options
41: *
42: * - `path` the path to save logs on.
43: *
44: * @param array $options Options for the FileLog, see above.
45: */
46: public function __construct($options = array()) {
47: $options += array('path' => LOGS);
48: $this->_path = $options['path'];
49: }
50:
51: /**
52: * Implements writing to log files.
53: *
54: * @param string $type The type of log you are making.
55: * @param string $message The message you want to log.
56: * @return boolean success of write.
57: */
58: public function write($type, $message) {
59: $debugTypes = array('notice', 'info', 'debug');
60:
61: if ($type == 'error' || $type == 'warning') {
62: $filename = $this->_path . 'error.log';
63: } elseif (in_array($type, $debugTypes)) {
64: $filename = $this->_path . 'debug.log';
65: } else {
66: $filename = $this->_path . $type . '.log';
67: }
68: $output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $message . "\n";
69: return file_put_contents($filename, $output, FILE_APPEND);
70: }
71:
72: }
73: