summaryrefslogtreecommitdiff
path: root/vendor/open-telemetry/api/Behavior/LogsMessagesTrait.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/open-telemetry/api/Behavior/LogsMessagesTrait.php')
-rw-r--r--vendor/open-telemetry/api/Behavior/LogsMessagesTrait.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/vendor/open-telemetry/api/Behavior/LogsMessagesTrait.php b/vendor/open-telemetry/api/Behavior/LogsMessagesTrait.php
new file mode 100644
index 000000000..d0207e4b1
--- /dev/null
+++ b/vendor/open-telemetry/api/Behavior/LogsMessagesTrait.php
@@ -0,0 +1,50 @@
+<?php
+
+declare(strict_types=1);
+
+namespace OpenTelemetry\API\Behavior;
+
+use OpenTelemetry\API\Behavior\Internal\Logging;
+use Psr\Log\LogLevel;
+
+trait LogsMessagesTrait
+{
+ private static function shouldLog(string $level): bool
+ {
+ return Logging::level($level) >= Logging::logLevel();
+ }
+
+ private static function doLog(string $level, string $message, array $context): void
+ {
+ $writer = Logging::logWriter();
+ if (self::shouldLog($level)) {
+ $context['source'] = get_called_class();
+ $writer->write($level, $message, $context);
+ }
+ }
+
+ protected static function logDebug(string $message, array $context = []): void
+ {
+ self::doLog(LogLevel::DEBUG, $message, $context);
+ }
+
+ protected static function logInfo(string $message, array $context = []): void
+ {
+ self::doLog(LogLevel::INFO, $message, $context);
+ }
+
+ protected static function logNotice(string $message, array $context = []): void
+ {
+ self::doLog(LogLevel::NOTICE, $message, $context);
+ }
+
+ protected static function logWarning(string $message, array $context = []): void
+ {
+ self::doLog(LogLevel::WARNING, $message, $context);
+ }
+
+ protected static function logError(string $message, array $context = []): void
+ {
+ self::doLog(LogLevel::ERROR, $message, $context);
+ }
+}