12 use Monolog\Logger as MLogger;
63 Logger::getInstance()->addLogger($this);
74 if (!isset($instance)) {
76 $instance =
new $class();
90 $this->activated =
false;
100 error_reporting(E_ALL | E_STRICT);
102 $this->activated =
true;
104 if (!$this->monolog) {
106 $this->monolog = new \Monolog\Logger(
'app');
107 $proc =
new WebProcessor();
108 $this->monolog->pushProcessor($proc);
109 $this->monolog->pushProcessor(array($this,
'xoopsDataProcessor'));
111 $formatter =
new LineFormatter();
113 switch ($this->configs[
'logging_threshold']) {
115 $threshold=MLogger::ERROR;
121 $threshold=MLogger::INFO;
125 $threshold=MLogger::DEBUG;
128 if (intval($this->configs[
'max_versions']) == 0) {
129 $stream =
new StreamHandler($this->configs[
'log_file_path'], $threshold);
131 $stream =
new RotatingFileHandler(
132 $this->configs[
'log_file_path'],
133 $this->configs[
'max_versions'],
137 $stream->setFormatter($formatter);
138 $this->monolog->pushHandler($stream);
156 $record[
'extra'][
'user'] =
'?';
157 @$record[
'extra'][
'user'] =
$xoops->isUser() ?
$xoops->user->getVar(
'uname') :
'n/a';
202 $this->starttimes[
$name] = microtime(
true);
214 if ($this->activated) {
215 if (array_key_exists(
$name, $this->starttimes)) {
216 $elapsed = microtime(
true) - $this->starttimes[
$name];
221 $this->
log(LogLevel::INFO,
$msg, $context);
238 if ($this->activated) {
239 $level = LogLevel::INFO;
241 $level = LogLevel::ERROR;
244 'channel'=>
'Queries',
247 'query_time'=>$query_time
249 $this->
log($level,
$sql, $context);
264 if ($this->activated) {
265 $context = array(
'channel'=>
'Blocks',
'cached'=>$cached,
'cachetime'=>$cachetime);
266 $this->
log(LogLevel::INFO,
$name, $context);
280 if ($this->activated) {
281 $context = array(
'channel'=>
'Extra',
'name'=>
$name);
282 $this->
log(LogLevel::INFO,
$msg, $context);
295 if ($this->activated) {
309 if ($this->activated) {
312 $this->
messageTag(
'_MD_MONOLOG_EXCEPTION',
'Exception* : %s : file %s line %s'),
317 array(
'exception' => $e)
347 public function emergency($message, array $context = array())
349 if ($this->activated) {
350 $this->
log(LogLevel::EMERGENCY, $message, $context);
365 public function alert($message, array $context = array())
367 if ($this->activated) {
368 $this->
log(LogLevel::ALERT, $message, $context);
382 public function critical($message, array $context = array())
384 if ($this->activated) {
385 $this->
log(LogLevel::CRITICAL, $message, $context);
398 public function error($message, array $context = array())
400 if ($this->activated) {
401 $this->
log(LogLevel::ERROR, $message, $context);
416 public function warning($message, array $context = array())
418 if ($this->activated) {
431 public function notice($message, array $context = array())
433 if ($this->activated) {
434 $this->
log(LogLevel::NOTICE, $message, $context);
448 public function info($message, array $context = array())
450 if ($this->activated) {
451 $this->
log(LogLevel::INFO, $message, $context);
463 public function debug($message, array $context = array())
465 if ($this->activated) {
466 $this->
log(LogLevel::DEBUG, $message, $context);
482 return defined($tag) ? constant($tag) : $default;
494 public function log($level, $message, array $context = array())
496 if (!$this->activated) {
500 $channel =
'messages';
507 if (isset($context[
'channel'])) {
508 $chan = strtolower($context[
'channel']);
511 if (!$this->configs[
'include_blocks']) {
516 if ($context[
'cached']) {
523 if (!$this->configs[
'include_deprecated']) {
527 $msg = $this->
messageTag(
'_MD_MONOLOG_DEPRECATED',
'Deprecated*') .
' : ' . $message;
531 if (!$this->configs[
'include_extra']) {
538 if (!$this->configs[
'include_queries']) {
543 $qt = empty($context[
'query_time']) ?
544 '' : sprintf(
'%0.6f - ', $context[
'query_time']);
545 if ($level == LogLevel::ERROR) {
549 $msg .=
' -- Error number: '
550 . (is_scalar($context[
'errno']) ? $context[
'errno'] :
'?')
552 . (is_scalar($context[
'error']) ? $context[
'error'] :
'?');
557 if (!$this->configs[
'include_timers']) {
560 $msg = $this->
messageTag(
'_MD_MONOLOG_TIMERS',
'Timers*') .
' : ' . $message;
563 $msg = $this->
messageTag(
'_MD_MONOLOG_ERRORS',
'Errors*') .
' : ' . $message;
567 $msg = $this->
messageTag(
'_MD_MONOLOG_MESSAGES',
'Message*') .
' : ' . $message;
570 case LogLevel::EMERGENCY:
571 $this->monolog->emergency(
$msg, $context);
573 case LogLevel::ALERT:
574 $this->monolog->alert(
$msg, $context);
576 case LogLevel::CRITICAL:
577 $this->monolog->critical(
$msg, $context);
579 case LogLevel::ERROR:
580 $this->monolog->error(
$msg, $context);
583 $this->monolog->warning(
$msg, $context);
585 case LogLevel::NOTICE:
586 $this->monolog->notice(
$msg, $context);
589 $this->monolog->info(
$msg, $context);
591 case LogLevel::DEBUG:
593 $this->monolog->debug(
$msg, $context);
if(empty($settings['ROOT_PATH'])) elseif(empty($settings['DB_PARAMETERS'])) $error
error($message, array $context=array())
addBlock($name, $cached=false, $cachetime=0)
notice($message, array $context=array())
debug($message, array $context=array())
alert($message, array $context=array())
emergency($message, array $context=array())
critical($message, array $context=array())
log($level, $message, array $context=array())
const _MD_MONOLOG_TIMETOLOAD
info($message, array $context=array())
addQuery($sql, $error=null, $errno=null, $query_time=null)
warning($message, array $context=array())
if(!is_object($module)||!$module->getVar('isactive')) $msg
messageTag($tag, $default)
startTime($name= 'XOOPS')
xoopsDataProcessor($record)
const _MD_MONOLOG_NOT_CACHED