forked from froxlor/Froxlor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Michael Kaufmann <[email protected]>
- Loading branch information
Showing
3 changed files
with
98 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
namespace Froxlor\System; | ||
|
||
use Monolog\Handler\AbstractProcessingHandler; | ||
use Monolog\Logger; | ||
|
||
class MysqlHandler extends AbstractProcessingHandler | ||
{ | ||
|
||
protected $pdoStatement = null; | ||
|
||
protected static $froxlorLevels = array( | ||
Logger::DEBUG => LOG_DEBUG, | ||
Logger::INFO => LOG_INFO, | ||
Logger::NOTICE => LOG_NOTICE, | ||
Logger::WARNING => LOG_WARNING, | ||
Logger::ERROR => LOG_ERR, | ||
Logger::CRITICAL => LOG_ERR, | ||
Logger::ALERT => LOG_ERR, | ||
Logger::EMERGENCY => LOG_ERR | ||
); | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param bool|int $level | ||
* Debug level which this handler should store | ||
* @param bool $bubble | ||
*/ | ||
public function __construct($level = Logger::DEBUG, $bubble = true) | ||
{ | ||
parent::__construct($level, $bubble); | ||
} | ||
|
||
/** | ||
* Insert the data to the logger table | ||
* | ||
* @param array $data | ||
* @return bool | ||
*/ | ||
protected function insert(array $data) | ||
{ | ||
if ($this->pdoStatement === null) { | ||
$sql = "INSERT INTO `panel_syslog` SET `text` = :message, `user` = :contextUser, `action` = :contextAction, `type` = :level, `date` = :datetime"; | ||
$this->pdoStatement = \Froxlor\Database\Database::prepare($sql); | ||
} | ||
return $this->pdoStatement->execute($data); | ||
} | ||
|
||
/** | ||
* Writes the record down to the log | ||
* | ||
* @param array $record | ||
* @return void | ||
*/ | ||
protected function write(array $record) | ||
{ | ||
$this->insert([ | ||
':message' => $record['message'], | ||
':contextUser' => (isset($record['context']['loginname']) ? $record['context']['loginname'] : 'unknown'), | ||
':contextAction' => (isset($record['context']['action']) ? $record['context']['action'] : '0'), | ||
':level' => self::$froxlorLevels[$record['level']], | ||
':datetime' => $record['datetime']->format('U') | ||
]); | ||
} | ||
} |
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