============ Installation ============ To install the Logger component, you will need to use Composer. Run the following command in your terminal: .. code-block:: console composer require runopencode/logger This will download and install the Logger component along with its dependencies. Basic setup ----------- In your project, you will need to initialize the Logger by wrapping an existing PSR-3 logger implementation: .. code-block:: php :linenos: pushHandler(new StreamHandler('/path/to/logs/app.log', LogLevel::DEBUG)); // Wrap it with RunOpenCode Logger $logger = new Logger( decorated: $psrLogger, contextProviders: [], // Optional: context providers debug: false, // Optional: debug mode (default: false) defaultLevel: LogLevel::CRITICAL // Optional: default log level (default: CRITICAL) ); The Logger component is a decorator that wraps any PSR-3 logger implementation and adds additional functionality on top of it. Using the interface ------------------- It is highly recommended to use the ``LoggerInterface`` from this component as a dependency in your classes, rather than the concrete implementation: .. code-block:: php :linenos: repository->delete($userId); } catch (\Throwable $exception) { $this->logger->exception( $exception, 'Failed to delete user', ['user_id' => $userId] ); // ... } } } The ``LoggerInterface`` extends PSR-3's ``LoggerInterface`` and adds the ``exception()`` and ``throw()`` methods for convenient exception logging. Debug mode ---------- When creating a Logger instance, you can enable debug mode. In debug mode, the ``exception()`` method will throw the exception after logging it, which is useful during development: .. code-block:: php :linenos: exception($exception); // You can still override it per-call $logger->exception($exception, level: LogLevel::CRITICAL); The default log level is ``LogLevel::CRITICAL`` if not specified. Symfony integration ------------------- If you are using Symfony framework, you should use the ``runopencode/logger-bundle`` package which automatically registers the Logger as a service in your container and provides configuration options. See the :doc:`Logger Bundle documentation <../../bundles/logger-bundle/index>` for more information about Symfony integration.