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.

ScopedPsrLogger.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. * @author Maxence Lange <maxence@artificial-owl.com>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OC\AppFramework;
  26. use Psr\Log\LoggerInterface;
  27. use function array_merge;
  28. class ScopedPsrLogger implements LoggerInterface {
  29. /** @var LoggerInterface */
  30. private $inner;
  31. /** @var string */
  32. private $appId;
  33. public function __construct(LoggerInterface $inner,
  34. string $appId) {
  35. $this->inner = $inner;
  36. $this->appId = $appId;
  37. }
  38. public function emergency($message, array $context = []) {
  39. $this->inner->emergency(
  40. $message,
  41. array_merge(
  42. [
  43. 'app' => $this->appId,
  44. ],
  45. $context
  46. )
  47. );
  48. }
  49. public function alert($message, array $context = []) {
  50. $this->inner->alert(
  51. $message,
  52. array_merge(
  53. [
  54. 'app' => $this->appId,
  55. ],
  56. $context
  57. )
  58. );
  59. }
  60. public function critical($message, array $context = []) {
  61. $this->inner->critical(
  62. $message,
  63. array_merge(
  64. [
  65. 'app' => $this->appId,
  66. ],
  67. $context
  68. )
  69. );
  70. }
  71. public function error($message, array $context = []) {
  72. $this->inner->error(
  73. $message,
  74. array_merge(
  75. [
  76. 'app' => $this->appId,
  77. ],
  78. $context
  79. )
  80. );
  81. }
  82. public function warning($message, array $context = []) {
  83. $this->inner->warning(
  84. $message,
  85. array_merge(
  86. [
  87. 'app' => $this->appId,
  88. ],
  89. $context
  90. )
  91. );
  92. }
  93. public function notice($message, array $context = []) {
  94. $this->inner->notice(
  95. $message,
  96. array_merge(
  97. [
  98. 'app' => $this->appId,
  99. ],
  100. $context
  101. )
  102. );
  103. }
  104. public function info($message, array $context = []) {
  105. $this->inner->info(
  106. $message,
  107. array_merge(
  108. [
  109. 'app' => $this->appId,
  110. ],
  111. $context
  112. )
  113. );
  114. }
  115. public function debug($message, array $context = []) {
  116. $this->inner->debug(
  117. $message,
  118. array_merge(
  119. [
  120. 'app' => $this->appId,
  121. ],
  122. $context
  123. )
  124. );
  125. }
  126. public function log($level, $message, array $context = []) {
  127. $this->inner->log(
  128. $level,
  129. $message,
  130. array_merge(
  131. [
  132. 'app' => $this->appId,
  133. ],
  134. $context
  135. )
  136. );
  137. }
  138. }