1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Core
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Log Adapter
29: *
30: * @category Mage
31: * @package Mage_Core
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Core_Model_Log_Adapter
35: {
36:
37: /**
38: * Store log file name
39: *
40: * @var string
41: */
42: protected $_logFileName = '';
43:
44: /**
45: * Data to log
46: *
47: * @var array
48: */
49: protected $_data = array();
50:
51: /**
52: * Fields that should be replaced in debug data with '***'
53: *
54: * @var array
55: */
56: protected $_debugReplacePrivateDataKeys = array();
57:
58: /**
59: * Set log file name
60: *
61: * @param string $fileName
62: */
63: public function __construct($fileName)
64: {
65: $this->_logFileName = $fileName;
66: }
67:
68: /**
69: * Perform forced log data to file
70: *
71: * @param mixed $data
72: * @return Mage_Core_Model_Log_Adapter
73: */
74: public function log($data = null)
75: {
76: if ($data === null) {
77: $data = $this->_data;
78: }
79: else {
80: if (!is_array($data)) {
81: $data = array($data);
82: }
83: }
84: $data = $this->_filterDebugData($data);
85: $data['__pid'] = getmypid();
86: Mage::log($data, null, $this->_logFileName, true);
87: return $this;
88: }
89:
90: /**
91: * Log data setter
92: *
93: * @param string|array $key
94: * @param mixed $value
95: * @return Mage_Core_Model_Log_Adapter
96: * @todo replace whole data
97: */
98: public function setData($key, $value = null)
99: {
100: if(is_array($key)) {
101: $this->_data = $key;
102: }
103: else {
104: $this->_data[$key] = $value;
105: }
106: return $this;
107: }
108:
109: /**
110: * Setter for private data keys, that should be replaced in debug data with '***'
111: *
112: * @param array $keys
113: * @return Mage_Core_Model_Log_Adapter
114: */
115: public function setFilterDataKeys($keys)
116: {
117: if (!is_array($keys)) {
118: $keys = array($keys);
119: }
120: $this->_debugReplacePrivateDataKeys = $keys;
121: return $this;
122: }
123:
124: /**
125: * Recursive filter data by private conventions
126: *
127: * @param mixed $debugData
128: * @return mixed
129: */
130: protected function _filterDebugData($debugData)
131: {
132: if (is_array($debugData) && is_array($this->_debugReplacePrivateDataKeys)) {
133: foreach ($debugData as $key => $value) {
134: if (in_array($key, $this->_debugReplacePrivateDataKeys)) {
135: $debugData[$key] = '****';
136: }
137: else {
138: if (is_array($debugData[$key])) {
139: $debugData[$key] = $this->_filterDebugData($debugData[$key]);
140: }
141: }
142: }
143: }
144: return $debugData;
145: }
146: }
147: