Wf_Logmanager - Version 0.1.0.0

Version Notes

First release

Download this release

Release Info

Developer Jay El-Kaake
Extension Wf_Logmanager
Version 0.1.0.0
Comparing to
See all releases


Version 0.1.0.0

app/code/community/Wf/Logmanager/Block/Adminhtml/List.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * @category Log Manager
6
+ * @package Wf_Logmanager
7
+ * @author Magecredit Team <hi@magecredit.com>
8
+ */
9
+ class Wf_Logmanager_Block_Adminhtml_List extends Mage_Core_Block_Template
10
+ {
11
+ /**
12
+ * Local store of the list of modules
13
+ * @var array
14
+ */
15
+ protected $_lists = array();
16
+
17
+ public function _construct()
18
+ {
19
+ $this->gather();
20
+ return parent::_construct();
21
+ }
22
+
23
+ /**
24
+ * Inspiration for this code was from Alan Storm's module list extension.
25
+ * Be sure to check it out some time at http://alanstorm.com/magento_list_module
26
+ * @return $this
27
+ */
28
+ public function gather()
29
+ {
30
+ $config = Mage::getConfig();
31
+ foreach($config->getNode('modules')->children() as $item)
32
+ {
33
+ $o = new Varien_Object();
34
+ $o->setName($item->getName());
35
+ $o->setActive((string)$item->active);
36
+ $o->setCodePool((string)$item->codePool);
37
+
38
+ $isLogEnabled = Mage::getSingleton('logmanager/manager')->isEnabled($item->getName());
39
+ $o->setLogEnabled($isLogEnabled);
40
+
41
+ //use same logic from Mage_Core_Model_Config::getModuleDir
42
+ //but recreated here to allow for poorly configued modules
43
+ $codePool = $config->getModuleConfig($item->getName())->codePool;
44
+ $dir = $config->getOptions()->getCodeDir().DS.$codePool.DS.uc_words($item->getName(),DS);
45
+ $o->setPath($dir);
46
+
47
+ $exists = file_exists($o->getPath());
48
+ $exists = $exists ? 'yes' : 'no';
49
+ $o->setPathExists($exists);
50
+
51
+ $exists = file_exists($o->getPath() . DS . 'etc'.DS.'config.xml');
52
+ $exists = $exists ? 'yes' : 'no';
53
+ $o->setConfigExists($exists);
54
+
55
+
56
+ if(!array_key_exists($o->getCodePool(), $this->_lists))
57
+ {
58
+ $this->_lists[$o->getCodePool()] = array();
59
+ }
60
+ $this->_lists[$o->getCodePool()][] = $o->toArray();
61
+
62
+
63
+ }
64
+
65
+ return $this;
66
+ }
67
+
68
+ /**
69
+ * @return array
70
+ */
71
+ public function getModules()
72
+ {
73
+ $modules = array_merge($this->_lists['local'], $this->_lists['community']);
74
+ return $modules;
75
+ }
76
+ }
app/code/community/Wf/Logmanager/Helper/Data.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Helper
5
+ * @category Log Manager
6
+ * @package Wf_Logmanager
7
+ * @author Magecredit Team <hi@magecredit.com>
8
+ */
9
+ class Wf_Logmanager_Helper_Data extends Mage_Core_Helper_Abstract
10
+ {
11
+
12
+ }
app/code/community/Wf/Logmanager/Model/Manager.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * @category Log Manager
6
+ * @package Wf_Logmanager
7
+ * @author Magecredit Team <hi@magecredit.com>
8
+ */
9
+ class Wf_Logmanager_Model_Manager extends Varien_Object
10
+ {
11
+ /**
12
+ * This is a local store of configured disabled log modules
13
+ * @var null
14
+ */
15
+ protected $_cfg = null;
16
+
17
+ /**
18
+ * Provide an extension key (ie TBT_Rewards) to disable the logging output from that module.
19
+ * @param string $moduleKey
20
+ * @return $this
21
+ */
22
+ public function disableLogging($moduleKey)
23
+ {
24
+ return $this->toggleLogging($moduleKey, false);
25
+ }
26
+
27
+ /**
28
+ * Provide an extension key (ie TBT_Rewards) to enable the logging output from that module.
29
+ * @param string $moduleKey
30
+ * @return $this
31
+ */
32
+ public function enableLogging($moduleKey)
33
+ {
34
+ return $this->toggleLogging($moduleKey, true);
35
+ }
36
+
37
+ /**
38
+ * Provide an extension key (ie TBT_Rewards) to disable the logging output from that module.
39
+ * @param string $moduleKey
40
+ * @param bool $disable if true, log output will be disabled for the specified module.
41
+ * @return $this
42
+ */
43
+ public function toggleLogging($moduleKey, $disable)
44
+ {
45
+ $oldCfg = $this->_getCfg();
46
+
47
+ $key = array_search($moduleKey, $oldCfg);
48
+ if($disable) {
49
+ if($key !== false) {
50
+ unset($oldCfg[$key]);
51
+ }
52
+ } else {
53
+ if($key === false) {
54
+ $oldCfg[] = $moduleKey;
55
+ }
56
+ }
57
+ $newCfg = implode(",", $oldCfg);
58
+
59
+
60
+ $cfg = new Mage_Core_Model_Config();
61
+ $cfg ->saveConfig('dev/log/disabled_modules', $newCfg, 'default', 0);
62
+
63
+ return $this;
64
+
65
+ }
66
+
67
+
68
+ /**
69
+ * Tells you if an extension's log output is currently enabled
70
+ * @param string $moduleKey
71
+ * @return boolean
72
+ */
73
+ public function isEnabled($moduleKey)
74
+ {
75
+ $cfg = $this->_getCfg();
76
+
77
+ $key = array_search($moduleKey, $cfg);
78
+ if($key !== false) {
79
+ return false;
80
+ }
81
+
82
+ return true;
83
+ }
84
+
85
+ /**
86
+ * Get the local store of config values
87
+ * @return array
88
+ */
89
+ protected function _getCfg()
90
+ {
91
+ if($this->_cfg != null) {
92
+ return $this->_cfg;
93
+ }
94
+ $cfg = Mage::getStoreConfig("dev/log/disabled_modules");
95
+
96
+ if(empty($cfg)) {
97
+ $this->_cfg = array();
98
+ } else {
99
+ $this->_cfg = explode(",", $cfg);
100
+ }
101
+
102
+ return $this->_cfg;
103
+ }
104
+
105
+ }
app/code/community/Wf/Logmanager/Model/Stream.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * @category Log Manager
5
+ * @package Wf_Logmanager
6
+ * @author Magecredit Team <hi@magecredit.com>
7
+ */
8
+ class Wf_Logmanager_Model_Stream extends Wf_Logmanager_Model_Stream_Abstract
9
+ {
10
+ /**
11
+ * Write a message to the log.
12
+ *
13
+ * @param array $event event data
14
+ * @return void
15
+ */
16
+ protected function _write($event)
17
+ {
18
+ $backtrace = debug_backtrace();
19
+ array_shift($backtrace);
20
+ array_shift($backtrace);
21
+ array_shift($backtrace);
22
+ $file = $backtrace[0]['file'];
23
+
24
+ $moduleDir = $file;
25
+
26
+ // The way this works is it sifts backwards through the log to find which module called this log.
27
+ $codeStart = stripos($file, DS.'code'.DS);
28
+ $moduleDir = substr($moduleDir, $codeStart +strlen(DS.'code'.DS));
29
+ $moduleDir = str_ireplace('community' . DS, '', $moduleDir);
30
+ $moduleDir = str_ireplace('local' . DS, '', $moduleDir);
31
+
32
+ $endIndex = stripos($moduleDir, DS, stripos($moduleDir, DS)+1);
33
+ $moduleKey = str_replace(DS, "_", substr($moduleDir, 0, $endIndex));
34
+
35
+ if(!Mage::getSingleton('logmanager/manager')->isEnabled($moduleKey)) {
36
+ return $this;
37
+ }
38
+
39
+ return parent::_write($event);
40
+ }
41
+
42
+ }
app/code/community/Wf/Logmanager/Model/Stream/Abstract.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * @category Log Manager
5
+ * @package Wf_Logmanager
6
+ * @author Magecredit Team <hi@magecredit.com>
7
+ */
8
+
9
+ if(class_exists("FireGento_Logger_Model_Stream") && Mage::helper('core')->isModuleEnabled('FireGento_Logger')) {
10
+ class Wf_Logmanager_Model_Stream_Abstract extends FireGento_Logger_Model_Stream { }
11
+ } else {
12
+ class Wf_Logmanager_Model_Stream_Abstract extends Zend_Log_Writer_Stream { }
13
+ }
app/code/community/Wf/Logmanager/controllers/Adminhtml/ManagelogController.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Wf_Logmanager_Adminhtml_ManagelogController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+ /**
6
+ * Lists the modules and gives the user the option to dsiable/enable log output for them.
7
+ * @return $this
8
+ */
9
+ public function indexAction()
10
+ {
11
+
12
+ $this->_title($this->__('Module Log Manager'))->_title($this->__('Module Log Manager'));
13
+
14
+ $this->loadLayout();
15
+
16
+ $this->_setActiveMenu('system/config/logmanager');
17
+
18
+ $listBlock = $this->getLayout()->createBlock('logmanager/adminhtml_list', 'logmanager_list')->setTemplate('wf/logmanager/list.phtml');
19
+ $this->_addContent(
20
+ $listBlock
21
+ );
22
+
23
+ $this->renderLayout();
24
+ }
25
+
26
+ /**
27
+ * Disables povided module key's log output
28
+ * @return $this
29
+ */
30
+ public function disableAction()
31
+ {
32
+ $moduleKey = $this->getRequest()->getParam('module');
33
+
34
+ Mage::getSingleton('logmanager/manager')->disableLogging($moduleKey);
35
+
36
+ $successMsg = Mage::helper('logmanager')->__("Logging for the module '%s' was successfully DISABLED.", $moduleKey);
37
+ Mage::getSingleton('core/session')->addSuccess($successMsg);
38
+
39
+ $this->_redirect("adminhtml/managelog/index");
40
+
41
+ return $this;
42
+ }
43
+
44
+
45
+ /**
46
+ * Disables povided module key's log output
47
+ * @return $this
48
+ */
49
+ public function enableAction()
50
+ {
51
+ $moduleKey = $this->getRequest()->getParam('module');
52
+
53
+ Mage::getSingleton('logmanager/manager')->enableLogging($moduleKey);
54
+
55
+ $successMsg = Mage::helper('logmanager')->__("Logging for the module '%s' was successfully ENABLED.", $moduleKey);
56
+ Mage::getSingleton('core/session')->addSuccess($successMsg);
57
+
58
+ $this->_redirect("adminhtml/managelog/index");
59
+
60
+ return $this;
61
+ }
62
+
63
+ /**
64
+ * Test function to see if log restrictions are working. Try restricting log for the Wf_Logmanager module.
65
+ * @return $this
66
+ */
67
+ public function testlogAction()
68
+ {
69
+ Mage::log("This is a test from the Wf_Logmanager module.");
70
+
71
+ die("Check logs now...");
72
+
73
+ return $this;
74
+ }
75
+
76
+ /**
77
+ * If they're not allowed to acces the config then they're probably not allowed to access this section.
78
+ * @return boolean
79
+ */
80
+ protected function _isAllowed()
81
+ {
82
+ return Mage::getSingleton('admin/session')->isAllowed('system/config');
83
+ }
84
+
85
+ }
app/code/community/Wf/Logmanager/etc/adminhtml.xml ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <acl>
3
+ <resources>
4
+ <admin>
5
+ <children>
6
+ <system>
7
+ <children>
8
+ <tools>
9
+ <children>
10
+ <logmanager translate="title" module="logmanager">
11
+ <title>Module Log Manager</title>
12
+ <sort_order>120</sort_order>
13
+ </logmanager>
14
+ </children>
15
+ </tools>
16
+ </children>
17
+ </system>
18
+ </children>
19
+ </admin>
20
+ </resources>
21
+ </acl>
22
+ <menu>
23
+ <system>
24
+ <children>
25
+ <tools>
26
+ <children>
27
+ <logmanager translate="title" module="logmanager">
28
+ <title>Module Log Manager</title>
29
+ <sort_order>120</sort_order>
30
+ <action>adminhtml/managelog</action>
31
+ </logmanager>
32
+ </children>
33
+ </tools>
34
+ </children>
35
+ </system>
36
+ </menu>
37
+ </config>
app/code/community/Wf/Logmanager/etc/config.xml ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Wf_Logmanager>
5
+ <version>0.1.0.0</version>
6
+ </Wf_Logmanager>
7
+ </modules>
8
+ <global>
9
+ <resources>
10
+ <logmanager_setup>
11
+ <setup>
12
+ <module>Wf_Logmanager</module>
13
+ </setup>
14
+ </logmanager_setup>
15
+ </resources>
16
+ <models>
17
+ <logmanager>
18
+ <class>Wf_Logmanager_Model</class>
19
+ </logmanager>
20
+ </models>
21
+ <blocks>
22
+ <logmanager>
23
+ <class>Wf_Logmanager_Block</class>
24
+ </logmanager>
25
+ </blocks>
26
+ <helpers>
27
+ <logmanager>
28
+ <class>Wf_Logmanager_Helper</class>
29
+ </logmanager>
30
+ </helpers>
31
+ <log>
32
+ <core>
33
+ <writer_model>Wf_Logmanager_Model_Stream</writer_model>
34
+ </core>
35
+ </log>
36
+ </global>
37
+ <admin>
38
+ <routers>
39
+ <adminhtml>
40
+ <args>
41
+ <modules>
42
+ <logmanager before="Mage_Adminhtml">Wf_Logmanager_Adminhtml</logmanager>
43
+ </modules>
44
+ </args>
45
+ </adminhtml>
46
+ </routers>
47
+ </admin>
48
+ <adminhtml>
49
+ <translate>
50
+ <modules>
51
+ <Wf_Logmanager>
52
+ <files>
53
+ <default>Wf_Logmanager.csv</default>
54
+ </files>
55
+ </Wf_Logmanager>
56
+ </modules>
57
+ </translate>
58
+ </adminhtml>
59
+ </config>
app/etc/modules/Wf_Logmanager.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Wf_Logmanager>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Wf_Logmanager>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Wf_Logmanager</name>
4
+ <version>0.1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>GPL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Lets you view, disable or enable any extension's ability to log to the core Magento system.</summary>
10
+ <description>Lets you view, disable or enable any extension's ability to log to the core Magento system.&#xD;
11
+ &#xD;
12
+ This is useful if you're working with a client or you are a merchant that has a ton of extensions installed that are all writing to the same log files and you want to debug an issue without all the clutter.</description>
13
+ <notes>First release</notes>
14
+ <authors><author><name>Jay El-Kaake</name><user>magecredit</user><email>hi@magecredit.com</email></author></authors>
15
+ <date>2015-02-23</date>
16
+ <time>18:40:20</time>
17
+ <contents><target name="mageetc"><dir name="modules"><file name="Wf_Logmanager.xml" hash="f0a76bb50413c5c1eafaf81e6d827ecc"/></dir></target><target name="magecommunity"><dir name="Wf"><dir name="Logmanager"><dir name="Block"><dir name="Adminhtml"><file name="List.php" hash="faf889eb3a74f34d266e883f681354cf"/></dir></dir><dir name="Helper"><file name="Data.php" hash="5ce61dbc1a500c0594e24bb39a74f4bf"/></dir><dir name="Model"><file name="Manager.php" hash="fe25f42b20b584d7f85a137c4fbddb1d"/><dir name="Stream"><file name="Abstract.php" hash="a7df6b537e8e1c181e9e89673efc06c1"/></dir><file name="Stream.php" hash="e7bb1e08deebf08d734ac4b7e108b154"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="ManagelogController.php" hash="d78bb0d511f8149e7c673e1f6a751b15"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="a6c59dca8e4206955a0231510464bcab"/><file name="config.xml" hash="6c1d456285524d8f9b19ac8162d68845"/></dir></dir></dir></target></contents>
18
+ <compatible/>
19
+ <dependencies><required><php><min>5.2.9</min><max>5.4.0</max></php></required></dependencies>
20
+ </package>