* @author Froxlor team (2010-) * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt * @package Logger * * @link http://www.nutime.de/ * * Logger - MySQL-Logger-Class */ class MysqlLogger extends AbstractLogger { /** * Userinfo * @var array */ private $userinfo = array(); /** * Syslogger Objects Array * @var loggers */ static private $loggers = array(); /** * Class constructor. * * @param array userinfo * @param array settings */ protected function __construct($userinfo, $settings) { parent::setupLogger($settings); $this->userinfo = $userinfo; } /** * Singleton ftw ;-) * */ static public function getInstanceOf($_usernfo, $_settings) { if (!isset(self::$loggers[$_usernfo['loginname']])) { self::$loggers[$_usernfo['loginname']] = new MysqlLogger($_usernfo, $_settings); } return self::$loggers[$_usernfo['loginname']]; } public function logAction($action = USR_ACTION, $type = LOG_NOTICE, $text = null) { if (parent::isEnabled()) { if (parent::getSeverity() <= 1 && $type == LOG_NOTICE ) { return; } if (!isset($this->userinfo['loginname']) || $this->userinfo['loginname'] == '' ) { $name = 'unknown'; } else { $name = $this->userinfo['loginname']; } $now = time(); $stmt = Database::prepare(" INSERT INTO `panel_syslog` SET `type` = :type, `date` = :now, `action` = :action, `user` = :user, `text` = :text" ); $ins_data = array( 'type' => $type, 'now' => $now, 'action' => $action, 'user' => $name ); if ($text != null && $text != '' ) { $ins_data['text'] = $text; Database::pexecute($stmt, $ins_data); } else { $ins_data['text'] = 'No text given!!! Check scripts!'; Database::pexecute($stmt, $ins_data); } } } }