abstract class Logger in Module Object Oriented Programming API 6.2
Same name in this branch
Same name and namespace in other branches
Logger.
Hierarchy
Expanded class hierarchy of Logger
2 string references to 'Logger'
- Application::getAdminForm in component/
moopapi.component.inc - Application::submitAdminForm in component/
moopapi.component.inc
File
- component/
decorator/ logger/ moopapi.logger.inc, line 12
View source
abstract class Logger extends Decorator {
const LOGGER_DATE_FORMAT = 'Y/m/d H:i:s';
// A bitmask.
const LOGGER_DISABLED = 0;
const LOGGER_FILE = 1;
// 1 << 0 001
const LOGGER_DB = 2;
// 1 << 1 010
const LOGGER_EMAIL = 4;
// 1 << 2 100
protected $date_format;
protected $destination;
protected $level;
public function __construct($decorators_applied = array(), &$relations = array(), $app) {
parent::__construct($decorators_applied, $relations, $app);
$this
->setLevel(variable_get('botcha_logger_level', self::LOGGER_DISABLED));
$this
->setDestination(variable_get('botcha_logger_destination', LOGGER_DESTINATION));
$this
->setDateFormat(variable_get('botcha_logger_date_format', self::LOGGER_DATE_FORMAT));
}
public function setDateFormat($date_format) {
$this->date_format = $date_format;
}
public function getDateFormat() {
return $this->date_format;
}
public function setDestination($destination) {
$this->destination = $destination;
}
public function getDestination() {
return $this->destination;
}
public function setLevel($level) {
$this->level = $level;
}
public function getLevel() {
return $this->level;
}
protected function logCall($method, $arguments) {
$app = $this->original;
$class = get_class($app);
$this
->log("!class::!method(!args) <=", array(
'!class' => $class,
'!method' => $method,
'!args' => print_r($arguments, TRUE),
));
$return = call_user_func_array(array(
$app,
$method,
), $arguments);
$this
->log("!class::!method(!args) return !return", array(
'!class' => $class,
'!method' => $method,
'!args' => print_r($arguments, TRUE),
'!return' => print_r($return, TRUE),
));
return $return;
}
public function log($message, $placeholders = array()) {
$levels = self::getLevels();
foreach ($levels as $level) {
if ($this->level & $level) {
$this
->put2log($message, $placeholders);
}
}
}
protected static function getLevels() {
return array(
self::LOGGER_DISABLED,
self::LOGGER_FILE,
self::LOGGER_DB,
self::LOGGER_EMAIL,
);
}
protected function put2log($message, $placeholders = array()) {
$destination = NULL;
$extra_headers = NULL;
// Match corresponding log levels of error_log function.
$message_type = 0;
switch ($this->level) {
case self::LOGGER_FILE:
$message_type = 3;
$destination = $this
->getDestination();
break;
case self::LOGGER_EMAIL:
$message_type = 1;
// @todo Real headers.
$extra_headers = NULL;
case self::LOGGER_DB:
default:
// Just use default logging behavior.
break;
}
error_log(date($this->date_format, time()) . ' ' . t($message, $placeholders) . "\n", $message_type, $destination, $extra_headers);
}
}