You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
2.8 KiB

3 years ago
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  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 Psr\Log\LoggerInterface;
  26. use function array_merge;
  27. class ScopedPsrLogger implements LoggerInterface {
  28. /** @var LoggerInterface */
  29. private $inner;
  30. /** @var string */
  31. private $appId;
  32. public function __construct(LoggerInterface $inner,
  33. string $appId) {
  34. $this->inner = $inner;
  35. $this->appId = $appId;
  36. }
  37. public function emergency($message, array $context = []) {
  38. $this->inner->emergency(
  39. $message,
  40. array_merge(
  41. [
  42. 'app' => $this->appId,
  43. ],
  44. $context
  45. )
  46. );
  47. }
  48. public function alert($message, array $context = []) {
  49. $this->inner->alert(
  50. $message,
  51. array_merge(
  52. [
  53. 'app' => $this->appId,
  54. ],
  55. $context
  56. )
  57. );
  58. }
  59. public function critical($message, array $context = []) {
  60. $this->inner->critical(
  61. $message,
  62. array_merge(
  63. [
  64. 'app' => $this->appId,
  65. ],
  66. $context
  67. )
  68. );
  69. }
  70. public function error($message, array $context = []) {
  71. $this->inner->error(
  72. $message,
  73. array_merge(
  74. [
  75. 'app' => $this->appId,
  76. ],
  77. $context
  78. )
  79. );
  80. }
  81. public function warning($message, array $context = []) {
  82. $this->inner->warning(
  83. $message,
  84. array_merge(
  85. [
  86. 'app' => $this->appId,
  87. ],
  88. $context
  89. )
  90. );
  91. }
  92. public function notice($message, array $context = []) {
  93. $this->inner->notice(
  94. $message,
  95. array_merge(
  96. [
  97. 'app' => $this->appId,
  98. ],
  99. $context
  100. )
  101. );
  102. }
  103. public function info($message, array $context = []) {
  104. $this->inner->info(
  105. $message,
  106. array_merge(
  107. [
  108. 'app' => $this->appId,
  109. ],
  110. $context
  111. )
  112. );
  113. }
  114. public function debug($message, array $context = []) {
  115. $this->inner->debug(
  116. $message,
  117. array_merge(
  118. [
  119. 'app' => $this->appId,
  120. ],
  121. $context
  122. )
  123. );
  124. }
  125. public function log($level, $message, array $context = []) {
  126. $this->inner->log(
  127. $message,
  128. array_merge(
  129. [
  130. 'app' => $this->appId,
  131. ],
  132. $context
  133. )
  134. );
  135. }
  136. }