parent e9d51cd5e0
commit c658f7b94e
  1. 15
      Json_Logger.php
  2. 14
      Logger.php

@ -146,11 +146,20 @@ class Harmonious_Json_Logger {
throw new RuntimeException("Log directory '$dir' not writable."); throw new RuntimeException("Log directory '$dir' not writable.");
} }
$data['error_level_int'] = $level; if (is_array($data)) {
$data['error_level'] = $this->levels[$level]; $object = $data;
} elseif (is_object($data)) {
$object = (array)$data;
} else {
$object = array();
$object['text'] = (string)$data;
}
$object['error_level_int'] = $level;
$object['error_level'] = $this->levels[$level];
$object['time'] = date('c');
if ( $level <= $this->getLevel() ) { if ( $level <= $this->getLevel() ) {
$this->write(json_encode($data)); $this->write(json_encode($object)."\n");
} }
} }

@ -151,11 +151,15 @@ class Harmonious_Logger {
throw new RuntimeException("Log directory '$dir' not writable."); throw new RuntimeException("Log directory '$dir' not writable.");
} }
if ( $level <= $this->getLevel() ) { if ( $level <= $this->getLevel() ) {
if (is_string($data)) $message = $data; if (is_object($data)) $data = (array)$data;
elseif (isset($data['message'])) $message = (string)$data['message']; if (is_array($data)) {
else { if (isset($data['message'])) $message = (string)$data['message'];
reset($data); else {
$message = (string)current($data); reset($data);
$message = (string)current($data);
}
} else {
$message = (string)$data;
} }
$this->write(sprintf("[%s] %s - %s\r\n", $this->levels[$level], date('c'), $message)); $this->write(sprintf("[%s] %s - %s\r\n", $this->levels[$level], date('c'), $message));
} }

Loading…
Cancel
Save