Logging

The logger is present by default in the container. The app that is logging is set automatically.

The logger can be used in the following way:

  1. <?php
  2. namespace OCA\MyApp\Service;
  3. use Psr\Log\LoggerInterface;
  4. class AuthorService {
  5. private $logger;
  6. private $appName;
  7. public function __construct(LoggerInterface $logger, string $appName){
  8. $this->logger = $logger;
  9. $this->appName = $appName;
  10. }
  11. public function log($message) {
  12. $this->logger->error($message, ['extra_context' => 'my extra context']);
  13. }
  14. }

The following methods are available:

  • emergency
  • alert
  • critical
  • error
  • warning
  • notice
  • info
  • debug