-
Notifications
You must be signed in to change notification settings - Fork 213
Composer backwards compatibility for psr/log #1775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @see https://github.com/php-fig/log/blob/1.0.0/Psr/Log/AbstractLogger.php | ||
| * @see https://github.com/php-fig/log/blob/1.0.0/Psr/Log/NullLogger.php | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Psr\Log; | ||
|
|
||
| /** | ||
| * This is a simple Logger implementation that other Loggers can inherit from. | ||
| * | ||
| * It simply delegates all log-level-specific methods to the `log` method to | ||
| * reduce boilerplate code that a simple Logger that does the same thing with | ||
| * messages regardless of the error level has to implement. | ||
| */ | ||
| abstract class AbstractLogger implements LoggerInterface | ||
| { | ||
| /** | ||
| * System is unusable. | ||
| * | ||
| * @param string $message | ||
| * @param array $context | ||
| * @return null | ||
| */ | ||
| public function emergency($message, array $context = []) | ||
| { | ||
| $this->log(LogLevel::EMERGENCY, $message, $context); | ||
| } | ||
|
|
||
| /** | ||
| * Action must be taken immediately. | ||
| * | ||
| * Example: Entire website down, database unavailable, etc. This should | ||
| * trigger the SMS alerts and wake you up. | ||
| * | ||
| * @param string $message | ||
| * @param array $context | ||
| * @return null | ||
| */ | ||
| public function alert($message, array $context = []) | ||
| { | ||
| $this->log(LogLevel::ALERT, $message, $context); | ||
| } | ||
|
|
||
| /** | ||
| * Critical conditions. | ||
| * | ||
| * Example: Application component unavailable, unexpected exception. | ||
| * | ||
| * @param string $message | ||
| * @param array $context | ||
| * @return null | ||
| */ | ||
| public function critical($message, array $context = []) | ||
| { | ||
| $this->log(LogLevel::CRITICAL, $message, $context); | ||
| } | ||
|
|
||
| /** | ||
| * Runtime errors that do not require immediate action but should typically | ||
| * be logged and monitored. | ||
| * | ||
| * @param string $message | ||
| * @param array $context | ||
| * @return null | ||
| */ | ||
| public function error($message, array $context = []) | ||
| { | ||
| $this->log(LogLevel::ERROR, $message, $context); | ||
| } | ||
|
|
||
| /** | ||
| * Exceptional occurrences that are not errors. | ||
| * | ||
| * Example: Use of deprecated APIs, poor use of an API, undesirable things | ||
| * that are not necessarily wrong. | ||
| * | ||
| * @param string $message | ||
| * @param array $context | ||
| * @return null | ||
| */ | ||
| public function warning($message, array $context = []) | ||
| { | ||
| $this->log(LogLevel::WARNING, $message, $context); | ||
| } | ||
|
|
||
| /** | ||
| * Normal but significant events. | ||
| * | ||
| * @param string $message | ||
| * @param array $context | ||
| * @return null | ||
| */ | ||
| public function notice($message, array $context = []) | ||
| { | ||
| $this->log(LogLevel::NOTICE, $message, $context); | ||
| } | ||
|
|
||
| /** | ||
| * Interesting events. | ||
| * | ||
| * Example: User logs in, SQL logs. | ||
| * | ||
| * @param string $message | ||
| * @param array $context | ||
| * @return null | ||
| */ | ||
| public function info($message, array $context = []) | ||
| { | ||
| $this->log(LogLevel::INFO, $message, $context); | ||
| } | ||
|
|
||
| /** | ||
| * Detailed debug information. | ||
| * | ||
| * @param string $message | ||
| * @param array $context | ||
| * @return null | ||
| */ | ||
| public function debug($message, array $context = []) | ||
| { | ||
| $this->log(LogLevel::DEBUG, $message, $context); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * This Logger can be used to avoid conditional log calls | ||
| * | ||
| * Logging should always be optional, and if no logger is provided to your | ||
| * library creating a NullLogger instance to have something to throw logs at | ||
| * is a good way to avoid littering your code with `if ($this->logger) { }` | ||
| * blocks. | ||
| */ | ||
| class NullLogger extends AbstractLogger | ||
| { | ||
| /** | ||
| * Logs with an arbitrary level. | ||
| * | ||
| * @param mixed $level | ||
| * @param string $message | ||
| * @param array $context | ||
| * @return null | ||
| */ | ||
| public function log($level, $message, array $context = []) | ||
| { | ||
| // noop | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\API; | ||
|
|
||
| use function class_exists; | ||
| use Composer\InstalledVersions; | ||
| use Composer\Semver\VersionParser; | ||
|
|
||
| if ( | ||
| // Provide a backwards-compatible Psr3 implementation when running under composer. | ||
| class_exists(InstalledVersions::class, false) | ||
| && InstalledVersions::satisfies(new VersionParser(), 'composer/composer', '~2.0') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must first check whether we are running as composer command, otherwise Additionally this might break setups with |
||
| ) { | ||
| require_once __DIR__ . '/Common/Compatibility/Psr3.php'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this file always be loaded before the SDK is autoloaded? Should IMO instead live in the SDK autoload script, using just the API package with composer scripts works fine. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
| "OpenTelemetry\\API\\": "." | ||
| }, | ||
| "files": [ | ||
| "_compat.php", | ||
| "Trace/functions.php" | ||
| ] | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\Tests\Integration\Composer; | ||
|
|
||
| use Composer\Script\Event; | ||
|
|
||
| final class Psr3Compatibility | ||
| { | ||
| public static function run(Event $event): void | ||
| { | ||
| require_once $event->getComposer()->getConfig()->get('vendor-dir') . '/autoload.php'; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
InstalledVersionsalways loaded during composer execution or do we have to drop theautoload: falseargument?