Elgg  Version 5.1
Go to the documentation of this file.
1 <?php
3 namespace Elgg\Traits;
6 use Elgg\Logger;
14 trait Loggable {
19  private $logger;
28  public function setLogger(LoggerInterface $logger = null) {
29  $this->logger = $logger;
30  }
37  public function getLogger() {
39  if ($this->logger) {
40  return $this->logger;
41  } else if (Application::$_instance) {
42  return Application::$_instance->internal_services->logger;
43  }
45  // Application hasn't been bootstrapped
46  return Logger::factory();
47  }
58  public function log($level, $message, array $context = []) {
59  if ($message instanceof \Throwable) {
60  $context['exception'] = $message;
61  }
63  // PSR interface is void, but Monolog returns a boolean
64  $logged = $this->getLogger()->log($level, $message, $context);
65  return $logged ?? true;
66  }
76  public function logDeprecatedMessage(string $message, string $version): void {
77  $this->getLogger()->warning("Deprecated in {$version}: {$message}");
78  }
79 }
Definition: add.php:8
static $_instance
Reference to the loaded Application.
Definition: Application.php:72
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
static factory(InputInterface $input=null, OutputInterface $output=null)
Build a new logger.
Definition: Logger.php:77
setLogger(LoggerInterface $logger=null)
Set (or remove) the logger.
Definition: Loggable.php:28
log($level, $message, array $context=[])
Log a message.
Definition: Loggable.php:58
Returns logger.
Definition: Loggable.php:37
logDeprecatedMessage(string $message, string $version)
Sends a message about deprecated use of a function, view, etc.
Definition: Loggable.php:76