Logger.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OC\AppFramework;
  25. use OCP\ILogger;
  26. class Logger implements ILogger {
  27. /** @var ILogger */
  28. private $logger;
  29. /** @var string */
  30. private $appName;
  31. public function __construct(ILogger $logger, string $appName) {
  32. $this->logger = $logger;
  33. $this->appName = $appName;
  34. }
  35. private function extendContext(array $context): array {
  36. if (!isset($context['app'])) {
  37. $context['app'] = $this->appName;
  38. }
  39. return $context;
  40. }
  41. public function emergency(string $message, array $context = []) {
  42. $this->logger->emergency($message, $this->extendContext($context));
  43. }
  44. public function alert(string $message, array $context = []) {
  45. $this->logger->alert($message, $this->extendContext($context));
  46. }
  47. public function critical(string $message, array $context = []) {
  48. $this->logger->critical($message, $this->extendContext($context));
  49. }
  50. public function error(string $message, array $context = []) {
  51. $this->logger->emergency($message, $this->extendContext($context));
  52. }
  53. public function warning(string $message, array $context = []) {
  54. $this->logger->warning($message, $this->extendContext($context));
  55. }
  56. public function notice(string $message, array $context = []) {
  57. $this->logger->notice($message, $this->extendContext($context));
  58. }
  59. public function info(string $message, array $context = []) {
  60. $this->logger->info($message, $this->extendContext($context));
  61. }
  62. public function debug(string $message, array $context = []) {
  63. $this->logger->debug($message, $this->extendContext($context));
  64. }
  65. public function log(int $level, string $message, array $context = []) {
  66. $this->logger->log($level, $message, $this->extendContext($context));
  67. }
  68. public function logException(\Throwable $exception, array $context = []) {
  69. $this->logger->logException($exception, $this->extendContext($context));
  70. }
  71. }