@@ -8,7 +8,7 @@ A flexible and powerful logging component for PHP 8.4+ applications, part of the
88- ** PSR-3 Compatible** : Full PSR-3 logger interface with array contexts and message interpolation
99- ** Multiple Destinations** : Write logs to files, console, Slack, webhooks, syslog, Nightwatch, and more
1010- ** Flexible Formatting** : Support for plain text, JSON, HTML, CSV, and custom formats
11- - ** Log Levels** : Full support for standard log levels (debug, info, warning, error, fatal )
11+ - ** Log Levels** : Full PSR-3 compliant log levels (debug, info, notice, warning, error, critical, alert, emergency )
1212- ** Array Context Support** : Pass complex arrays, objects, and exceptions as context
1313- ** Message Interpolation** : Use ` {placeholders} ` in messages for automatic substitution
1414- ** Channels** : Manage multiple independent loggers with automatic channel tracking
@@ -45,9 +45,12 @@ Log::setRunLevel( 'debug' );
4545// Write log messages
4646Log::debug( 'Debug message' );
4747Log::info( 'Information message' );
48+ Log::notice( 'Notice: user registration started' );
4849Log::warning( 'Warning message' );
4950Log::error( 'Error message' );
50- Log::fatal( 'Fatal error' );
51+ Log::critical( 'Critical: database connection lost' );
52+ Log::alert( 'Alert: disk space critically low' );
53+ Log::emergency( 'Emergency: system is shutting down' );
5154
5255// With array context and interpolation (PSR-3 style)
5356Log::error( 'User {userId} failed login from {ip}', [
@@ -515,7 +518,7 @@ Log::addChannel( 'alerts', $alertLogger );
515518
516519// Use specific channels
517520Log::channel( 'audit' )->info( 'User login', [ 'user' => $username ] );
518- Log::channel( 'alerts' )->fatal ( 'System down!' );
521+ Log::channel( 'alerts' )->emergency ( 'System down!' );
519522```
520523
521524### Multiplexer (Multiple Destinations)
@@ -547,6 +550,116 @@ $mux->warning( 'Warning!' ); // To both file and console
547550$mux->error( 'Error occurred' ); // To both file and console
548551```
549552
553+ ### PSR-3 Adapter
554+
555+ The Neuron logging component provides a PSR-3 adapter that allows you to use Neuron loggers with any library or framework that expects a PSR-3 compliant logger (like Symfony, Laravel packages, Monolog alternatives, etc.).
556+
557+ #### Basic Usage
558+
559+ ``` php
560+ use Neuron\Log\Logger;
561+ use Neuron\Log\Adapter\Psr3Adapter;
562+ use Neuron\Log\Destination\File;
563+ use Neuron\Log\Format\JSON;
564+
565+ // Create a Neuron logger
566+ $destination = new File( new JSON() );
567+ $destination->open( [ 'path' => '/var/log/app.json' ] );
568+ $neuronLogger = new Logger( $destination );
569+ $neuronLogger->setRunLevel( 'info' );
570+
571+ // Wrap it with the PSR-3 adapter
572+ $psr3Logger = new Psr3Adapter( $neuronLogger );
573+
574+ // Now use it with any PSR-3 expecting code
575+ $psr3Logger->info( 'Application started' );
576+ $psr3Logger->error( 'Database connection failed', [
577+ 'host' => 'db.example.com',
578+ 'error' => 'Connection timeout'
579+ ] );
580+ ```
581+
582+ #### Framework Integration
583+
584+ The adapter makes it easy to integrate Neuron logging into frameworks that expect PSR-3:
585+
586+ ``` php
587+ use Neuron\Log\Log;
588+ use Neuron\Log\Adapter\Psr3Adapter;
589+
590+ // Get Neuron's singleton logger and wrap it
591+ $psr3Logger = new Psr3Adapter( Log::getInstance()->Logger );
592+
593+ // Use with Symfony components
594+ $httpClient = new \Symfony\Component\HttpClient\CurlHttpClient( [
595+ 'logger' => $psr3Logger
596+ ] );
597+
598+ // Use with Guzzle
599+ $guzzleClient = new \GuzzleHttp\Client( [
600+ 'handler' => $handlerStack,
601+ 'logger' => $psr3Logger
602+ ] );
603+
604+ // Use with any PSR-3 compatible library
605+ $thirdPartyService = new ThirdPartyService( $psr3Logger );
606+ ```
607+
608+ #### Level Mapping
609+
610+ The adapter automatically maps PSR-3 log levels to Neuron's RunLevel enum:
611+
612+ | PSR-3 Level | Neuron RunLevel | Numeric Value |
613+ | -------------| -----------------| ---------------|
614+ | emergency | EMERGENCY | 50 |
615+ | alert | ALERT | 45 |
616+ | critical | CRITICAL | 40 |
617+ | error | ERROR | 30 |
618+ | warning | WARNING | 20 |
619+ | notice | NOTICE | 15 |
620+ | info | INFO | 10 |
621+ | debug | DEBUG | 0 |
622+
623+ #### Advanced Features
624+
625+ The adapter maintains full compatibility with Neuron's advanced features:
626+
627+ ``` php
628+ use Neuron\Log\Logger;
629+ use Neuron\Log\Adapter\Psr3Adapter;
630+ use Neuron\Log\Destination\File;
631+ use Neuron\Log\Format\JSON;
632+
633+ // Create Neuron logger with multiple destinations
634+ $fileLogger = new Logger( new File( new JSON() ) );
635+ $fileLogger->getDestination()->open( [ 'path' => '/var/log/app.json' ] );
636+
637+ // Add filters, context, and other Neuron features
638+ $fileLogger->setContext( 'app_version', '2.0.0' );
639+ $fileLogger->setContext( 'environment', 'production' );
640+
641+ // Wrap with PSR-3 adapter
642+ $psr3Logger = new Psr3Adapter( $fileLogger );
643+
644+ // PSR-3 calls use Neuron features underneath
645+ $psr3Logger->warning( 'API rate limit approaching', [
646+ 'requests' => 950,
647+ 'limit' => 1000
648+ ] );
649+ // Context includes: app_version, environment, requests, limit
650+
651+ // Access the underlying Neuron logger if needed
652+ $neuronLogger = $psr3Logger->getNeuronLogger();
653+ $neuronLogger->setRunLevel( 'debug' );
654+ ```
655+
656+ #### Why Use the Adapter?
657+
658+ 1 . ** Framework Integration** : Use Neuron's powerful logging with any PSR-3 expecting library
659+ 2 . ** Gradual Migration** : Migrate from other PSR-3 loggers without changing application code
660+ 3 . ** Best of Both Worlds** : Keep Neuron's advanced features (multiple destinations, formats, filters) while maintaining PSR-3 compatibility
661+ 4 . ** Drop-in Replacement** : Works as a drop-in replacement for Monolog, PSR-3 Log, or other PSR-3 implementations
662+
550663### Custom Filters
551664
552665``` php
@@ -636,23 +749,41 @@ assert( $logs[0]['level'] === 'error' );
636749
637750### Log Levels
638751
639- The following log levels are supported (from lowest to highest severity):
752+ The following PSR-3 compliant log levels are supported (from lowest to highest severity):
640753
641- - ` debug ` - Detailed debug information
642- - ` info ` - Informational messages
643- - ` warning ` - Warning messages
644- - ` error ` - Error conditions
645- - ` fatal ` - Fatal conditions
754+ - ` debug ` (0) - Detailed debug information for development and troubleshooting
755+ - ` info ` (10) - Informational messages about application flow
756+ - ` notice ` (15) - Normal but significant events
757+ - ` warning ` (20) - Warning messages about potentially harmful situations
758+ - ` error ` (30) - Error events that allow the application to continue running
759+ - ` critical ` (40) - Critical conditions that need immediate attention
760+ - ` alert ` (45) - Action must be taken immediately
761+ - ` emergency ` (50) - System is unusable, requires immediate intervention
646762
647763### Logger Methods
648764
765+ All logger methods accept an optional array context for additional data:
766+
649767``` php
650768$logger->debug( string $message, array $context = [] );
651769$logger->info( string $message, array $context = [] );
770+ $logger->notice( string $message, array $context = [] );
652771$logger->warning( string $message, array $context = [] );
653772$logger->error( string $message, array $context = [] );
654- $logger->fatal( string $message, array $context = [] );
655- $logger->log( RunLevel $level, string $message, array $context = [] );
773+ $logger->critical( string $message, array $context = [] );
774+ $logger->alert( string $message, array $context = [] );
775+ $logger->emergency( string $message, array $context = [] );
776+ $logger->log( string $message, RunLevel $level, array $context = [] );
777+
778+ // Set minimum log level
779+ $logger->setRunLevel( mixed $level ); // Accepts RunLevel enum or string
780+ $logger->setRunLevelText( string $level ); // Set by text: 'debug', 'info', etc.
781+ $logger->getRunLevel(): RunLevel; // Get current run level
782+
783+ // Context management
784+ $logger->setContext( string $name, mixed $value ); // Add global context
785+ $logger->getContext(): array; // Get all context
786+ $logger->reset(); // Clear all context
656787```
657788
658789## Testing
0 commit comments