-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from nerds-and-company/feature/better_log_proce…
…ssing Better log processing
- Loading branch information
Showing
5 changed files
with
92 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace Craft; | ||
|
||
/** | ||
* Log Helper Plugin. | ||
* | ||
* Advanced logging options | ||
* | ||
* @author Nerds & Company | ||
* @copyright Copyright (c) 2016, Nerds & Company | ||
* | ||
* @link https://www.nerds.company | ||
*/ | ||
abstract class LogHelper_BaseLogRoute extends \CLogRoute | ||
{ | ||
// Public Methods | ||
// ========================================================================= | ||
|
||
/** | ||
* Initializes the log route. This method is invoked after the log route is created by the route manager. | ||
* | ||
* @return null | ||
*/ | ||
public function init() | ||
{ | ||
$this->levels = craft()->config->get('devMode') ? '' : 'error,warning'; | ||
$this->filter = craft()->config->get('devMode') ? 'Craft\\LogFilter' : null; | ||
|
||
parent::init(); | ||
} | ||
|
||
// Protected Methods | ||
// ========================================================================= | ||
|
||
/** | ||
* Saves log messages in files. | ||
* | ||
* @param array $logs The list of log messages | ||
* | ||
* @return null | ||
*/ | ||
protected function processLogs($logs) | ||
{ | ||
$processed = array(); | ||
|
||
foreach ($logs as $log) { | ||
$message = LoggingHelper::redact($log[0]); | ||
$level = $log[1]; | ||
$category = $log[2]; | ||
$time = $log[3]; | ||
$force = (isset($log[4]) && $log[4] == true) ? true : false; | ||
$plugin = isset($log[5]) ? StringHelper::toLowerCase($log[5]) : 'craft'; | ||
|
||
$processed[] = $this->formatLogMessageWithForce($message, $level, $category, $time, $force, $plugin); | ||
} | ||
|
||
return $processed; | ||
} | ||
|
||
/** | ||
* Formats a log message given different fields. | ||
* | ||
* @param string $message The message content. | ||
* @param int $level The message level. | ||
* @param string $category The message category. | ||
* @param int $time The message timestamp. | ||
* @param bool $force Whether the message was forced or not. | ||
* | ||
* @return string The formatted message. | ||
*/ | ||
protected function formatLogMessageWithForce($message, $level, $category, $time, $force) | ||
{ | ||
return "[$level] [$category]".($force ? " [Forced]" : "")." $message"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters