Skip to content

Commit

Permalink
Merge pull request #69 from firegento/develop
Browse files Browse the repository at this point in the history
Merge Develop to Master
  • Loading branch information
daim2k5 committed Feb 17, 2016
2 parents 6561270 + a6170ff commit a353d47
Show file tree
Hide file tree
Showing 16 changed files with 604 additions and 10 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Configure the different loggers in `System > Configuration > Advanced > Firegent
* Daniel Kröger
* Michael Ryvlin
* Tobias Zander
* Achim Rosenhagen

### Current Status of Project

Expand All @@ -88,6 +89,7 @@ Complete, working logger interfaces:
- Graylog2
- RSyslog (UDP)
- Loggly (UDP/HTTPS)
- Papertrail (UDP)
- Chromelogger
- Logstash

Expand All @@ -96,6 +98,7 @@ It is possible to use **Multiple-Targets**!
### Other Features
- Log Live View (Like a tail in terminal)
- Report View (Shows content of a report in backend)
- Manage modules log output (enable/disable log messages of extensions)

### Further work

Expand All @@ -109,9 +112,10 @@ For ChromeLogger we use https://github.com/ccampbell/chromephp
Make a fork, commit to develop branch and make a pull request

### Some Hints
* There are combinations there doesn't work together
** You can't use Chromelogger with the embeded queueing model, because the queueing takes place after the response
* There are combinations that don't work together
* You can't use Chromelogger with the embeded queueing model, because the queueing takes place after the response
is send to the client
** You can't use Papertrail with the embeded queueing model

Licence
-------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ class FireGento_Logger_Block_Adminhtml_LiveView extends Mage_Adminhtml_Block_Tem
public function getLogFiles()
{
$logFiles = array();
$logFolderPath = Mage::getBaseDir('var') . DS . 'log';

if (!file_exists($logFolderPath)) {
mkdir($logFolderPath, 0755, true);
}

$directory = new DirectoryIterator($logFolderPath);

$directory = new DirectoryIterator(Mage::getBaseDir('var') . DS . 'log');
foreach ($directory as $fileInfo) {
if (!$fileInfo->isFile() || !preg_match('/\.(?:log)$/', $fileInfo->getFilename())) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ protected function _prepareColumns()

$this->addColumn('timestamp', array(
'header' => Mage::helper('firegento_logger')->__('Timestamp'),
'type' => 'datetime',
'align' => 'left',
'index' => 'timestamp',
));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* This file is part of a FireGento e.V. module.
*
* This FireGento e.V. module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This script is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
*
* @category FireGento
* @package FireGento_Logger
* @author FireGento Team <[email protected]>
* @copyright 2013 FireGento Team (http://www.firegento.com)
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
*/
/**
* Block for manage modules log output in the backend
*
* @category FireGento
* @package FireGento_Logger
* @author FireGento Team <[email protected]>
*/
class FireGento_Logger_Block_Adminhtml_Logger_Manager extends Mage_Core_Block_Template
{

/**
* Local store of the list of modules
* @var array
*/
protected $_lists = array();

public function _construct()
{
$this->gather();
return parent::_construct();
}

/**
* Inspiration for this code was from Alan Storm's module list extension.
* Be sure to check it out some time at http://alanstorm.com/magento_list_module
* @return $this
*/
public function gather()
{
$config = Mage::getConfig();
foreach ($config->getNode('modules')->children() as $item) {
$o = new Varien_Object();
$o->setName($item->getName());
$o->setActive((string)$item->active);
$o->setCodePool((string)$item->codePool);
$isLogEnabled = Mage::getSingleton('firegento_logger/manager')->isEnabled($item->getName());
$o->setLogEnabled($isLogEnabled);
//use same logic from Mage_Core_Model_Config::getModuleDir
//but recreated here to allow for poorly configued modules
$codePool = $config->getModuleConfig($item->getName())->codePool;
$dir = $config->getOptions()->getCodeDir().DS.$codePool.DS.uc_words($item->getName(),DS);
$o->setPath($dir);
$exists = file_exists($o->getPath());
$exists = $exists ? 'yes' : 'no';
$o->setPathExists($exists);
$exists = file_exists($o->getPath() . DS . 'etc'.DS.'config.xml');
$exists = $exists ? 'yes' : 'no';
$o->setConfigExists($exists);
if(!array_key_exists($o->getCodePool(), $this->_lists)) {
$this->_lists[$o->getCodePool()] = array();
}
$this->_lists[$o->getCodePool()][] = $o->toArray();
}
return $this;
}

/**
* @return array
*/
public function getModules()
{
$modules = array_merge($this->_lists['local'], $this->_lists['community']);
return $modules;
}
}
1 change: 1 addition & 0 deletions src/app/code/community/FireGento/Logger/Model/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ protected function _write($event)
$dataToInsert['advanced_info'] = $this->getAdvancedInfo($event);
}

$dataToInsert['timestamp'] = Mage::getSingleton('core/date')->gmtDate();
$this->_db->insert($this->_table, $dataToInsert);

/** @var Varien_Db_Adapter_Pdo_Mysql $db */
Expand Down
21 changes: 16 additions & 5 deletions src/app/code/community/FireGento/Logger/Model/Logstash.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class FireGento_Logger_Model_Logstash extends Zend_Log_Writer_Abstract
protected $_logstashPort = false;
protected $_logstashProtocol = false;
protected $_options = null;
protected $_logFileName = '';
/**
* @var int The timeout to apply when sending data to Loggly servers, in seconds.
*/
Expand All @@ -52,6 +53,8 @@ public function __construct($filename)
$this->_logstashServer = $helper->getLoggerConfig('logstash/host');
$this->_logstashPort = $helper->getLoggerConfig('logstash/port');
$this->_logstashProtocol = $helper->getLoggerConfig('logstash/protocol');
$logDir = Mage::getBaseDir('var') . DS . 'log' . DS;
$this->_logFileName = str_replace($logDir, '', $filename);

}

Expand Down Expand Up @@ -90,13 +93,21 @@ protected function buildJSONMessage($event, $enableBacktrace = false)
$fields = array();
$fields['@timestamp'] = date('c', strtotime($event->getTimestamp()));
$fields['@version'] = "1";
$fields['level'] = $event->getPriority();
$fields['file'] = $event->getFile();
$fields['Level'] = $event->getPriorityName();
$fields['File'] = $event->getFile();
$fields['LineNumber'] = $event->getLine();
$fields['StoreCode'] = $event->getStoreCode();
$fields['TimeElapsed'] = $event->getTimeElapsed();
$fields['source_host'] = $event->getHostname();
$fields['message'] = $event->getMessage();
$fields['SourceHost'] = $event->getHostname();
$fields['Message'] = $event->getMessage();
$fields['Backtrace'] = $event->getBacktrace();
$fields['RequestMethod'] = $event->getRequestMethod();
$fields['RequestData'] = $event->getRequestData();
$fields['RemoteAddress'] = $event->getRemoteAddress();
$fields['HttpHost'] = Mage::app()->getRequest()->getHttpHost();
$fields['LogFileName'] = $this->_logFileName;
$fields['SessionId'] = Mage::getSingleton("core/session")->getEncryptedSessionId();
$fields['CustomerId'] = Mage::getSingleton('customer/session')->getCustomerId();

// udp/tcp inputs require a trailing EOL character.
$encodedMessage = trim(json_encode($fields)) . "\n";
Expand Down Expand Up @@ -130,7 +141,7 @@ protected function publishMessage($message)
if ($result == false) {
throw new Zend_Log_Exception(
sprintf($helper->__('Error occurred posting log message to logstash via tcp. Posted Message: %s'),
$message)
$message)
);
}
} catch (Exception $e) {
Expand Down
113 changes: 113 additions & 0 deletions src/app/code/community/FireGento/Logger/Model/Manager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php
/**
* This file is part of a FireGento e.V. module.
*
* This FireGento e.V. module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This script is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
*
* @category FireGento
* @package FireGento_Logger
* @author FireGento Team <[email protected]>
* @copyright 2013 FireGento Team (http://www.firegento.com)
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
*/
/**
* Log Manager
*
* @category FireGento
* @package FireGento_Logger
* @author FireGento Team <[email protected]>
*/
class FireGento_Logger_Model_Manager extends Varien_Object
{
/**
* This is a local store of configured disabled log modules
* @var null
*/
protected $_cfg = null;

/**
* Provide an extension key (ie TBT_Rewards) to disable the logging output from that module.
* @param string $moduleKey
* @return $this
*/
public function disableLogging($moduleKey)
{
return $this->toggleLogging($moduleKey, false);
}

/**
* Provide an extension key (ie TBT_Rewards) to enable the logging output from that module.
* @param string $moduleKey
* @return $this
*/
public function enableLogging($moduleKey)
{
return $this->toggleLogging($moduleKey, true);
}

/**
* Provide an extension key (ie TBT_Rewards) to disable the logging output from that module.
* @param string $moduleKey
* @param bool $disable if true, log output will be disabled for the specified module.
* @return $this
*/
public function toggleLogging($moduleKey, $disable)
{
$oldCfg = $this->_getCfg();
$key = array_search($moduleKey, $oldCfg);
if ($disable) {
if ($key !== false) {
unset($oldCfg[$key]);
}
} else {
if ($key === false) {
$oldCfg[] = $moduleKey;
}
}
$newCfg = implode(",", $oldCfg);
$cfg = new Mage_Core_Model_Config();
$cfg ->saveConfig('dev/log/disabled_modules', $newCfg, 'default', 0);
return $this;
}


/**
* Tells you if an extension's log output is currently enabled
* @param string $moduleKey
* @return boolean
*/
public function isEnabled($moduleKey)
{
$cfg = $this->_getCfg();
$key = array_search($moduleKey, $cfg);
if ($key !== false) {
return false;
}
return true;
}

/**
* Get the local store of config values
* @return array
*/
protected function _getCfg()
{
if ($this->_cfg != null) {
return $this->_cfg;
}
$cfg = Mage::getStoreConfig("dev/log/disabled_modules");
if (empty($cfg)) {
$this->_cfg = array();
} else {
$this->_cfg = explode(",", $cfg);
}
return $this->_cfg;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* This file is part of a FireGento e.V. module.
*
* This FireGento e.V. module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This script is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* PHP version 5
*
* @category FireGento
* @package FireGento_Logger
* @author FireGento Team <[email protected]>
* @copyright 2013 FireGento Team (http://www.firegento.com)
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
*/
/**
* Implementation of Remote Syslog Message for Papertrail.
*
* @category FireGento
* @package FireGento_Logger
* @author FireGento Team <[email protected]>
*/
class FireGento_Logger_Model_Papertrail_PapertrailSyslogMessage extends SyslogMessage
{

/**
* Puts all Log Message elements together to form a string that will be passed
* to the Papertrail Server.
*
* @return string The Message as a string.
*/
protected function FormatMessage() {
return sprintf('%s %s',
$this->Facility,
$this->Message
);
}

/**
* @return array
*/
public function GetMessageChunks()
{
return array($this->FormatMessage());
}
}
Loading

0 comments on commit a353d47

Please sign in to comment.