PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / google / google / auth / src / Logging / StdOutLogger.php

StdOutLogger.php in Media Cloud Sync 1.4.1, at includes/sdk/google/google/auth/src/Logging/StdOutLogger.php

70 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Copyright 2024 Google Inc. All Rights Reserved.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 namespace Dudlewebs\WPMCS\GCP\Google\Auth\Logging;
19
20 use InvalidArgumentException;
21 use Dudlewebs\WPMCS\GCP\Psr\Log\LoggerInterface;
22 use Dudlewebs\WPMCS\GCP\Psr\Log\LoggerTrait;
23 use Dudlewebs\WPMCS\GCP\Psr\Log\LogLevel;
24 use Stringable;
25 /**
26 * A basic logger class to log into stdOut for GCP logging.
27 *
28 * @internal
29 */
30 class StdOutLogger implements LoggerInterface
31 {
32 use LoggerTrait;
33 /**
34 * @var array<string,int>
35 */
36 private array $levelMapping = [LogLevel::EMERGENCY => 7, LogLevel::ALERT => 6, LogLevel::CRITICAL => 5, LogLevel::ERROR => 4, LogLevel::WARNING => 3, LogLevel::NOTICE => 2, LogLevel::INFO => 1, LogLevel::DEBUG => 0];
37 private int $level;
38 /**
39 * Constructs a basic PSR-3 logger class that logs into StdOut for GCP Logging
40 *
41 * @param string $level The level of the logger instance.
42 */
43 public function __construct(string $level = LogLevel::DEBUG)
44 {
45 $this->level = $this->getLevelFromName($level);
46 }
47 /**
48 * {@inheritdoc}
49 */
50 public function log($level, string|Stringable $message, array $context = []) : void
51 {
52 if ($this->getLevelFromName($level) < $this->level) {
53 return;
54 }
55 print $message . "\n";
56 }
57 /**
58 * @param string $levelName
59 * @return int
60 * @throws InvalidArgumentException
61 */
62 private function getLevelFromName(string $levelName) : int
63 {
64 if (!\array_key_exists($levelName, $this->levelMapping)) {
65 throw new InvalidArgumentException('The level supplied to the Logger is not valid');
66 }
67 return $this->levelMapping[$levelName];
68 }
69 }
70