Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various improvements #140

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/app/code/community/FireGento/Logger/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class FireGento_Logger_Helper_Data extends Mage_Core_Helper_Abstract

protected $_targets;
protected $_targetMap;
protected $_targetsForFilename = [];
protected $_notificationRules;
protected $_maxBacktraceLines;
protected $_maxDataLength;
Expand Down Expand Up @@ -97,21 +98,24 @@ public function getMappedTargets($filename)
if ($this->_targetMap === null) {
$targetMap = $this->getLoggerConfig('general/target_map');
if ($targetMap && ($targetMap = @unserialize($targetMap))) {
$targets = array();
foreach ($targetMap as $map) {
if (@preg_match('/^'.$map['pattern'].'$/', $filename)) {
$targets[$map['target']] = (int) $map['backtrace'];
if ((int) $map['stop_on_match']) {
break;
}
$this->_targetMap = $targetMap;
} else {
$this->_targetMap = [];
}
}
if ( ! isset($this->_targetsForFilename[$filename])) {
$targets = array();
foreach ($this->_targetMap as $map) {
if (@preg_match('/^'.str_replace('/', '\\/', $map['pattern']).'$/', $filename)) {
$targets[$map['target']] = (int) $map['backtrace'];
if ((int) $map['stop_on_match']) {
break;
}
}
$this->_targetMap = $targets;
} else {
$this->_targetMap = false;
}
$this->_targetsForFilename[$filename] = $targets;
}
return $this->_targetMap;
return $this->_targetsForFilename[$filename];
}

/**
Expand Down Expand Up @@ -170,7 +174,7 @@ public function addEventMetadata(&$event, $notAvailable = null, $enableBacktrace
->setStoreCode(Mage::app()->getStore()->getCode());

// Add admin user data
if (Mage::app()->getStore()->isAdmin() && isset($_SESSION['admin'])) {
if (Mage::app()->getStore()->isAdmin() && isset($_SESSION) && isset($_SESSION['admin'])) {
colinmollenhour marked this conversation as resolved.
Show resolved Hide resolved
$session = Mage::getSingleton('admin/session');
if ($session->isLoggedIn()) {
$event->setAdminUserId($session->getUser()->getId());
Expand Down
2 changes: 1 addition & 1 deletion src/app/code/community/FireGento/Logger/Model/Logstash.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function buildJSONMessage($event, $enableBacktrace = false)
$fields['HttpHost'] = (!Mage::app()->getRequest()->getHttpHost()) ? 'cli': Mage::app()->getRequest()->getHttpHost();
$fields['LogFileName'] = $this->_logFileName;
// Only add session fields if a session was already instantiated and logger should not start a new session
if (isset($_SESSION)) {
if (isset($_SESSION) && isset($_SESSION['core'])) {
colinmollenhour marked this conversation as resolved.
Show resolved Hide resolved
$fields['SessionId'] = Mage::getSingleton("core/session")->getEncryptedSessionId();
$fields['CustomerId'] = Mage::getSingleton('customer/session')->getCustomerId();
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/code/community/FireGento/Logger/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@

<logger>
<general>
<targets>advanced</targets>
<targets>default,advanced</targets>
<target_map>a:2:{s:18:"_1575507325664_664";a:4:{s:7:"pattern";s:26:"system\.log|exception\.log";s:6:"target";s:8:"advanced";s:9:"backtrace";s:1:"1";s:13:"stop_on_match";s:1:"1";}s:18:"_1575507340100_100";a:4:{s:7:"pattern";s:2:".*";s:6:"target";s:7:"default";s:9:"backtrace";s:1:"0";s:13:"stop_on_match";s:1:"1";}}</target_map>
<priority>7</priority>
<format><![CDATA[
%timestamp% %priorityName% (%storeCode%): %requestMethod% %requestUri%
Expand Down