ScopedPsrLogger.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\AppFramework;
  8. use Psr\Log\LoggerInterface;
  9. use function array_merge;
  10. class ScopedPsrLogger implements LoggerInterface {
  11. /** @var LoggerInterface */
  12. private $inner;
  13. /** @var string */
  14. private $appId;
  15. public function __construct(LoggerInterface $inner,
  16. string $appId) {
  17. $this->inner = $inner;
  18. $this->appId = $appId;
  19. }
  20. public function emergency($message, array $context = []): void {
  21. $this->inner->emergency(
  22. $message,
  23. array_merge(
  24. [
  25. 'app' => $this->appId,
  26. ],
  27. $context
  28. )
  29. );
  30. }
  31. public function alert($message, array $context = []): void {
  32. $this->inner->alert(
  33. $message,
  34. array_merge(
  35. [
  36. 'app' => $this->appId,
  37. ],
  38. $context
  39. )
  40. );
  41. }
  42. public function critical($message, array $context = []): void {
  43. $this->inner->critical(
  44. $message,
  45. array_merge(
  46. [
  47. 'app' => $this->appId,
  48. ],
  49. $context
  50. )
  51. );
  52. }
  53. public function error($message, array $context = []): void {
  54. $this->inner->error(
  55. $message,
  56. array_merge(
  57. [
  58. 'app' => $this->appId,
  59. ],
  60. $context
  61. )
  62. );
  63. }
  64. public function warning($message, array $context = []): void {
  65. $this->inner->warning(
  66. $message,
  67. array_merge(
  68. [
  69. 'app' => $this->appId,
  70. ],
  71. $context
  72. )
  73. );
  74. }
  75. public function notice($message, array $context = []): void {
  76. $this->inner->notice(
  77. $message,
  78. array_merge(
  79. [
  80. 'app' => $this->appId,
  81. ],
  82. $context
  83. )
  84. );
  85. }
  86. public function info($message, array $context = []): void {
  87. $this->inner->info(
  88. $message,
  89. array_merge(
  90. [
  91. 'app' => $this->appId,
  92. ],
  93. $context
  94. )
  95. );
  96. }
  97. public function debug($message, array $context = []): void {
  98. $this->inner->debug(
  99. $message,
  100. array_merge(
  101. [
  102. 'app' => $this->appId,
  103. ],
  104. $context
  105. )
  106. );
  107. }
  108. public function log($level, $message, array $context = []): void {
  109. $this->inner->log(
  110. $level,
  111. $message,
  112. array_merge(
  113. [
  114. 'app' => $this->appId,
  115. ],
  116. $context
  117. )
  118. );
  119. }
  120. }