86 |
* @return module |
* @return module |
87 |
*/ |
*/ |
88 |
public function __construct(string $dir, application $framework, ?lien_module $object_link_instance = null, ?om_dbform $object = null) { |
public function __construct(string $dir, application $framework, ?lien_module $object_link_instance = null, ?om_dbform $object = null) { |
89 |
|
$this->framework = $framework; |
90 |
$this->log(__METHOD__, ''); |
$this->log(__METHOD__, ''); |
91 |
$this->dir = $dir; |
$this->dir = $dir; |
|
$this->framework = $framework; |
|
92 |
$this->object_link_instance = $object_link_instance; |
$this->object_link_instance = $object_link_instance; |
93 |
$this->object = $object; |
$this->object = $object; |
94 |
$this->load_conf(); |
$this->load_conf(); |
378 |
} |
} |
379 |
|
|
380 |
/** |
/** |
381 |
* Renvoie une méthode sans le namespace courant et tronquée à la longueur spécifiée. |
* Log un message en lui ajoutant un préfixe. |
382 |
* |
* |
383 |
* @param string $method La méthode |
* @param string $method La méthode d'où provient le message (càd: __METHOD__) |
384 |
* @param int $length La longueur max |
* @param string $message Le message à écire dans le ficheir de logs |
385 |
|
* @param string $level Le niveau de log |
386 |
* |
* |
387 |
* @return string |
* @return void |
388 |
*/ |
*/ |
389 |
protected function shorten_method(string $method, int $length) { |
protected function log(string $method, string $message, string $level = 'DEBUG') { |
|
$ref = new \ReflectionClass($this); |
|
390 |
|
|
391 |
// remplace la classe parente par la classe courante |
// remplace la classe parente par la classe courante |
392 |
|
$ref = new \ReflectionClass($this); |
393 |
$parent_class_escaped = str_replace('\\', '\\\\', $ref->getParentClass()->getName()); |
$parent_class_escaped = str_replace('\\', '\\\\', $ref->getParentClass()->getName()); |
394 |
$method = preg_replace( |
$method = preg_replace( |
395 |
'/^'.$parent_class_escaped.'/', |
'/^'.$parent_class_escaped.'/', |
399 |
$namespace_escaped = str_replace('\\', '\\\\', $ref->getNamespaceName()); |
$namespace_escaped = str_replace('\\', '\\\\', $ref->getNamespaceName()); |
400 |
$method_short = preg_replace('/^'.$namespace_escaped.'\\\\/', '', $method); |
$method_short = preg_replace('/^'.$namespace_escaped.'\\\\/', '', $method); |
401 |
|
|
402 |
if (strlen($method_short) > ($length - 1)) { |
$this->framework->log($method_short, $message, $level); |
403 |
$method_short = substr($method_short, 0, $length - 1).'…'; |
//$this->framework->log($method_short, $message, $level, 'modules'); |
|
} |
|
|
|
|
|
return $method_short; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Log un message en lui ajoutant un préfixe. |
|
|
* |
|
|
* @param string $message |
|
|
* |
|
|
* @return void |
|
|
*/ |
|
|
protected function log($method, $message, $type = DEBUG_MODE) { |
|
|
$logger = logger::instance(); |
|
|
|
|
|
$logger->log($method." [] ".$message, $type); |
|
|
$method_len = 52; |
|
|
$method_short = $this->shorten_method($method, $method_len); |
|
|
|
|
|
$prefix = sprintf( |
|
|
" %11s %-${method_len}s ", |
|
|
$logger->types_to_show[$type], |
|
|
$method_short); |
|
|
foreach(explode("\n", $message) as $line) { |
|
|
//$logger->log_to_file('modules.log', $prefix.$line); |
|
|
$logger->log_to_file('debug.log', $prefix.$line); |
|
|
} |
|
404 |
} |
} |
405 |
} |
} |