{"id":40463903,"url":"https://github.com/neuron-php/logging","last_synced_at":"2026-01-20T18:00:52.753Z","repository":{"id":40992695,"uuid":"258261387","full_name":"Neuron-PHP/logging","owner":"Neuron-PHP","description":"Comprehensive logging package. Supports multiple destinations and formats including stdout, stderr, files, slack, sockets and webhooks.","archived":false,"fork":false,"pushed_at":"2026-01-13T18:15:46.000Z","size":473,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"develop","last_synced_at":"2026-01-18T14:52:30.443Z","etag":null,"topics":["logging","logging-library","php8","psr-3","psr-3-compliant"],"latest_commit_sha":null,"homepage":"https://neuronphp.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Neuron-PHP.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-04-23T16:16:54.000Z","updated_at":"2026-01-13T18:16:12.000Z","dependencies_parsed_at":"2024-12-13T16:53:27.677Z","dependency_job_id":"bddbee37-bc84-4980-af63-a6db364b603b","html_url":"https://github.com/Neuron-PHP/logging","commit_stats":{"total_commits":72,"total_committers":1,"mean_commits":72.0,"dds":0.0,"last_synced_commit":"0fb8c0f90f351666233583c2a67f59722aa93428"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"purl":"pkg:github/Neuron-PHP/logging","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neuron-PHP%2Flogging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neuron-PHP%2Flogging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neuron-PHP%2Flogging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neuron-PHP%2Flogging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Neuron-PHP","download_url":"https://codeload.github.com/Neuron-PHP/logging/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neuron-PHP%2Flogging/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28607959,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T16:10:39.856Z","status":"ssl_error","status_checked_at":"2026-01-20T16:10:39.493Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["logging","logging-library","php8","psr-3","psr-3-compliant"],"created_at":"2026-01-20T18:00:24.630Z","updated_at":"2026-01-20T18:00:52.737Z","avatar_url":"https://github.com/Neuron-PHP.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CI](https://github.com/Neuron-PHP/logging/actions/workflows/ci.yml/badge.svg)](https://github.com/Neuron-PHP/logging/actions)\n[![codecov](https://codecov.io/gh/Neuron-PHP/logging/branch/develop/graph/badge.svg)](https://codecov.io/gh/Neuron-PHP/logging)\n# Neuron-PHP Logging\n\nA flexible and powerful logging component for PHP 8.4+ applications, part of the Neuron-PHP framework.\n\n## Features\n\n- **PSR-3 Compatible**: Full PSR-3 logger interface with array contexts and message interpolation\n- **Multiple Destinations**: Write logs to files, console, Slack, webhooks, syslog, Nightwatch, and more\n- **Flexible Formatting**: Support for plain text, JSON, HTML, CSV, and custom formats\n- **Log Levels**: Full PSR-3 compliant log levels (debug, info, notice, warning, error, critical, alert, emergency)\n- **Array Context Support**: Pass complex arrays, objects, and exceptions as context\n- **Message Interpolation**: Use `{placeholders}` in messages for automatic substitution\n- **Channels**: Manage multiple independent loggers with automatic channel tracking\n- **Filters**: Apply custom filters to control which logs are written\n- **Multiplexing**: Write to multiple destinations simultaneously with different run levels\n- **Exception Tracking**: Automatic exception formatting with stack traces\n- **Laravel Nightwatch**: Full integration with special context handling\n\n## Requirements\n\n- PHP 8.4 or higher\n- ext-curl (for webhook/Slack destinations)\n- ext-json (for JSON formatting)\n- ext-sockets (for socket destination)\n\n## Installation\n\nInstall via Composer:\n\n```bash\ncomposer require neuron-php/logging\n```\n\n## Quick Start\n\nThe simplest way to start logging is using the singleton facade:\n\n```php\nuse Neuron\\Log\\Log;\n\n// Set the minimum log level\nLog::setRunLevel( 'debug' );\n\n// Write log messages\nLog::debug( 'Debug message' );\nLog::info( 'Information message' );\nLog::notice( 'Notice: user registration started' );\nLog::warning( 'Warning message' );\nLog::error( 'Error message' );\nLog::critical( 'Critical: database connection lost' );\nLog::alert( 'Alert: disk space critically low' );\nLog::emergency( 'Emergency: system is shutting down' );\n\n// With array context and interpolation (PSR-3 style)\nLog::error( 'User {userId} failed login from {ip}', [\n\t'userId' =\u003e 12345,\n\t'ip' =\u003e '192.168.1.1',\n\t'attempts' =\u003e 3\n] );\n```\n\n## Destinations\n\nThe logging component supports writing to various destinations:\n\n### Available Destinations\n\n- **Echo**: Output to browser/console\n- **Email**: Send logs via email\n- **File**: Write to log files\n- **Memory**: Store logs in memory for testing\n- **Nightwatch**: Send to Laravel Nightwatch monitoring service\n- **Null**: Discard logs (useful for testing)\n- **Papertrail**: Send to Papertrail cloud logging service\n- **Slack**: Post to Slack channels\n- **Socket**: Send over network sockets\n- **Sqs**: Send to Amazon SQS for queue-based processing\n- **StdErr**: Write to standard error\n- **StdOut**: Write to standard output\n- **StdOutStdErr**: Write to both stdout and stderr based on level\n- **SysLog**: System logging\n- **Webhook**: Send to custom webhooks\n- **WebSocket**: Stream logs in real-time via WebSocket\n\n### Formats\n\nEach destination can use different formatting:\n\n- **CSV**: Comma-separated values\n- **HTML**: HTML formatted output\n- **HTMLEmail**: HTML optimized for emails\n- **JSON**: Structured JSON output\n- **Nightwatch**: Laravel Nightwatch-specific JSON formatting\n- **PlainText**: Human-readable text format\n- **Raw**: Unformatted output\n- **Slack**: Slack-specific formatting\n\n## Usage Examples\n\n### Basic Logging\n\n```php\nuse Neuron\\Log\\Log;\n\n// Configure run level\nLog::setRunLevel( 'debug' );\n\n// Simple logging\nLog::debug( 'Debug information' );\nLog::info( 'Application started' );\nLog::warning( 'Memory usage high' );\n\n// With array context\nLog::error( 'Database connection failed', [\n\t'host' =\u003e 'db.example.com',\n\t'port' =\u003e 3306,\n\t'error' =\u003e 'Connection timeout'\n] );\n\n// With message interpolation\nLog::info( 'User {user} performed {action}', [\n\t'user' =\u003e 'admin@example.com',\n\t'action' =\u003e 'delete_records',\n\t'count' =\u003e 42\n] );\n```\n\n### File Logging\n\n```php\nuse Neuron\\Log\\Logger;\nuse Neuron\\Log\\Destination\\File;\nuse Neuron\\Log\\Format\\PlainText;\n\n// Create a file logger\n$fileDestination = new File( new PlainText() );\n$fileDestination-\u003eopen( [ 'path' =\u003e '/var/log/app.log' ] );\n\n$logger = new Logger( $fileDestination );\n$logger-\u003esetRunLevel( 'info' );\n$logger-\u003einfo( 'Application event logged to file' );\n```\n\n### JSON Logging\n\n```php\nuse Neuron\\Log\\Logger;\nuse Neuron\\Log\\Destination\\File;\nuse Neuron\\Log\\Format\\JSON;\n\n// Log in JSON format for structured logging\n$jsonDestination = new File( new JSON() );\n$jsonDestination-\u003eopen( [ 'path' =\u003e '/var/log/app.json' ] );\n\n$jsonLogger = new Logger( $jsonDestination );\n\n// Array context is automatically included in JSON output\n$jsonLogger-\u003eerror( 'Database error', [\n\t'query' =\u003e 'SELECT * FROM users',\n\t'error_code' =\u003e 1054,\n\t'duration' =\u003e 234.5\n] );\n```\n\n### Slack Integration\n\n```php\nuse Neuron\\Log\\Log;\nuse Neuron\\Log\\Logger;\nuse Neuron\\Log\\Destination\\Slack;\nuse Neuron\\Log\\Format\\SlackFormat;\n\n$slack = new Slack( new SlackFormat() );\n$slack-\u003eopen( [\n\t'endpoint' =\u003e $_ENV['LOG_SLACK_WEBHOOK_URL'],\n\t'params' =\u003e [\n\t\t'channel'  =\u003e '#alerts',\n\t\t'username' =\u003e 'AppLogger',\n\t\t'icon_emoji' =\u003e ':warning:'\n\t]\n] );\n\n$slackLogger = new Logger( $slack );\n$slackLogger-\u003esetRunLevel( 'error' );\n\n// Add to the multiplexer\nLog::getInstance()-\u003eLogger-\u003eaddLog( $slackLogger );\n\n// Now errors and above will also go to Slack with context\nLog::error( 'Payment processing failed', [\n\t'transaction_id' =\u003e 'txn_12345',\n\t'amount' =\u003e 99.99,\n\t'currency' =\u003e 'USD'\n] );\n```\n\n### Laravel Nightwatch Integration\n\n```php\nuse Neuron\\Log\\Logger;\nuse Neuron\\Log\\Destination\\Nightwatch;\nuse Neuron\\Log\\Format\\Nightwatch as NightwatchFormat;\n\n// Create Nightwatch destination with default channel\n$nightwatch = new Nightwatch( new NightwatchFormat() );\n$nightwatch-\u003eopen( [\n\t'token' =\u003e $_ENV['NIGHTWATCH_TOKEN'],  // Your Nightwatch API token\n\t'endpoint' =\u003e 'https://nightwatch.laravel.com/api/logs', // Optional, uses default\n\t'batch_size' =\u003e 10,  // Optional: batch logs for better performance\n\t'timeout' =\u003e 5       // Optional: API request timeout in seconds\n] );\n\n$nightwatchLogger = new Logger( $nightwatch );\n$nightwatchLogger-\u003esetRunLevel( 'info' );\n\n// Log messages will be sent to Nightwatch\n$nightwatchLogger-\u003einfo( 'Application started' );\n$nightwatchLogger-\u003eerror( 'Database connection failed', [\n\t'host' =\u003e 'db.example.com',\n\t'port' =\u003e 3306,\n\t'error' =\u003e 'Connection timeout'\n] );\n\n// For production use with the singleton\nuse Neuron\\Log\\Log;\n\n// Add Nightwatch to the global logger\nLog::getInstance()-\u003eLogger-\u003eaddLog( $nightwatchLogger );\n\n// Now all logs at info level and above go to Nightwatch\nLog::info( 'User logged in', [ 'user_id' =\u003e 123 ] );\nLog::warning( 'API rate limit approaching', [ 'requests' =\u003e 950, 'limit' =\u003e 1000 ] );\nLog::error( 'Payment processing failed', [ 'transaction_id' =\u003e 'txn_abc123' ] );\n```\n\n#### Nightwatch with Channels\n\nThe channel name is automatically passed to Nightwatch when using named channels:\n\n```php\nuse Neuron\\Log\\Log;\nuse Neuron\\Log\\Logger;\nuse Neuron\\Log\\Destination\\Nightwatch;\nuse Neuron\\Log\\Format\\Nightwatch as NightwatchFormat;\n\n// Create a single Nightwatch format instance\n$nightwatchFormat = new NightwatchFormat( 'neuron', 'my-app' );\n\n// Create Nightwatch destination\n$nightwatch = new Nightwatch( $nightwatchFormat );\n$nightwatch-\u003eopen( [ 'token' =\u003e $_ENV['NIGHTWATCH_TOKEN'] ] );\n\n// Create logger and add to multiple channels\n$logger = new Logger( $nightwatch );\nLog::addChannel( 'audit', $logger );\nLog::addChannel( 'security', $logger );\nLog::addChannel( 'payments', $logger );\n\n// Logs automatically include the channel name\nLog::channel( 'audit' )-\u003einfo( 'User updated profile', [ 'user_id' =\u003e 123 ] );\n// Nightwatch receives: {\"channel\": \"audit\", \"message\": \"User updated profile\", ...}\n\nLog::channel( 'security' )-\u003ewarning( 'Failed login attempt', [ 'ip' =\u003e '192.168.1.1' ] );\n// Nightwatch receives: {\"channel\": \"security\", \"message\": \"Failed login attempt\", ...}\n\nLog::channel( 'payments' )-\u003eerror( 'Payment failed', [ 'amount' =\u003e 99.99 ] );\n// Nightwatch receives: {\"channel\": \"payments\", \"message\": \"Payment failed\", ...}\n```\n\nThe channel name appears in the Nightwatch dashboard for easy filtering and monitoring.\n\n### Papertrail Integration\n\nPapertrail is a cloud-based logging service that aggregates and centralizes logs from multiple sources. The Papertrail destination sends logs using the remote syslog protocol with optional TLS encryption.\n\n```php\nuse Neuron\\Log\\Logger;\nuse Neuron\\Log\\Destination\\Papertrail;\nuse Neuron\\Log\\Format\\PlainText;\n\n// Create Papertrail destination\n$papertrail = new Papertrail( new PlainText() );\n$papertrail-\u003eopen( [\n\t'host' =\u003e 'logs5.papertrailapp.com',  // Your Papertrail host\n\t'port' =\u003e 12345,                       // Your Papertrail port\n\t'system_name' =\u003e 'my-app-prod',        // Optional: System name (defaults to hostname)\n\t'use_tls' =\u003e true,                     // Optional: Use TLS encryption (default: true)\n\t'facility' =\u003e 16,                      // Optional: Syslog facility (default: 16 for local0)\n\t'sd_id' =\u003e 'mycompany@12345'          // Optional: Structured Data ID (default: 'neuron@32473')\n] );\n\n$papertrailLogger = new Logger( $papertrail );\n$papertrailLogger-\u003esetRunLevel( 'info' );\n\n// Logs are sent to Papertrail with structured data\n$papertrailLogger-\u003eerror( 'Payment processing failed', [\n\t'transaction_id' =\u003e 'txn_12345',\n\t'amount' =\u003e 99.99,\n\t'currency' =\u003e 'USD',\n\t'error_code' =\u003e 'INSUFFICIENT_FUNDS'\n] );\n\n// Context is included as structured data in syslog format\n$papertrailLogger-\u003einfo( 'User action', [\n\t'user_id' =\u003e 456,\n\t'action' =\u003e 'purchase',\n\t'items' =\u003e [ 'SKU-123', 'SKU-456' ]\n] );\n```\n\nThe Papertrail destination:\n- Sends logs using RFC 5424 syslog format over TCP/TLS\n- Automatically maps log levels to syslog severities\n- Includes context as structured data for easy filtering in Papertrail\n- Supports automatic reconnection if the connection is lost\n- Allows custom SD-ID for organizations with IANA Private Enterprise Numbers\n\n### Amazon SQS Integration\n\nSend logs to Amazon SQS for scalable, queue-based processing:\n\n```php\nuse Neuron\\Log\\Logger;\nuse Neuron\\Log\\Destination\\Sqs;\nuse Neuron\\Log\\Format\\JSON;\n\n// Create SQS destination\n$sqs = new Sqs( new JSON() );\n$sqs-\u003eopen( [\n\t'queue_url' =\u003e 'https://sqs.us-east-1.amazonaws.com/123456789/my-log-queue',\n\t'region' =\u003e 'us-east-1',\n\t'credentials' =\u003e [                    // Optional: Use IAM role if not provided\n\t\t'key' =\u003e $_ENV['AWS_ACCESS_KEY'],\n\t\t'secret' =\u003e $_ENV['AWS_SECRET_KEY']\n\t],\n\t'batch_size' =\u003e 10,                   // Optional: Batch messages (1-10, default 1)\n\t'attributes' =\u003e [                     // Optional: Message attributes\n\t\t'Environment' =\u003e 'production',\n\t\t'Application' =\u003e 'neuron-app'\n\t],\n\t'max_retries' =\u003e 3,                   // Optional: Retry attempts (default 3)\n\t'retry_delay' =\u003e 1.0                  // Optional: Initial retry delay in seconds\n] );\n\n$sqsLogger = new Logger( $sqs );\n$sqsLogger-\u003esetRunLevel( 'info' );\n\n// Logs are sent to SQS with automatic batching\n$sqsLogger-\u003eerror( 'Critical system error', [\n\t'service' =\u003e 'payment-processor',\n\t'error_code' =\u003e 'GATEWAY_TIMEOUT',\n\t'retry_count' =\u003e 3\n] );\n\n// Context and channel are included in message body\n$sqsLogger-\u003einfo( 'Order processed', [\n\t'order_id' =\u003e 'ORD-12345',\n\t'amount' =\u003e 299.99,\n\t'items' =\u003e 5\n] );\n```\n\nThe SQS destination:\n- Sends logs as JSON messages to SQS queues\n- Supports batching up to 10 messages for improved performance\n- Automatic retry with exponential backoff\n- Message attributes for filtering and routing\n- Works with IAM roles or explicit credentials\n- Includes log level and channel as message attributes\n\n**Required**: Install the AWS SDK via Composer:\n```bash\ncomposer require aws/aws-sdk-php\n```\n\n### WebSocket Real-Time Streaming\n\nStream logs in real-time to web browsers or monitoring dashboards using WebSocket connections:\n\n```php\nuse Neuron\\Log\\Logger;\nuse Neuron\\Log\\Destination\\WebSocket;\nuse Neuron\\Log\\Format\\JSON;\n\n// Create WebSocket destination\n$websocket = new WebSocket( new JSON() );\n$websocket-\u003eopen( [\n\t'url' =\u003e 'ws://localhost:8080/logs',  // WebSocket server URL\n\t'max_reconnect_attempts' =\u003e 5,        // Optional: Max reconnection attempts (default: 5)\n\t'reconnect_delay' =\u003e 1.0              // Optional: Initial reconnect delay in seconds\n] );\n\n$wsLogger = new Logger( $websocket );\n$wsLogger-\u003esetRunLevel( 'debug' );\n\n// Logs are streamed in real-time to connected WebSocket clients\n$wsLogger-\u003einfo( 'Real-time event', [\n\t'event_type' =\u003e 'user_login',\n\t'user_id' =\u003e 123,\n\t'timestamp' =\u003e time()\n] );\n```\n\nThe WebSocket destination:\n- Maintains persistent WebSocket connections\n- Automatically reconnects with exponential backoff\n- Sends logs as WebSocket text frames\n- Perfect for real-time monitoring dashboards\n- Works with any WebSocket server implementation\n\n### Array Context Support (PSR-3 Compatible)\n\n```php\nuse Neuron\\Log\\Log;\n\n// Pass array context as second parameter\nLog::error( 'Database query failed', [\n\t'query' =\u003e 'SELECT * FROM orders WHERE id = ?',\n\t'params' =\u003e [12345],\n\t'duration' =\u003e 1234.5,\n\t'error' =\u003e 'Connection timeout'\n] );\n\n// Complex nested arrays\nLog::info( 'Order processed', [\n\t'order' =\u003e [\n\t\t'id' =\u003e 'ORD-12345',\n\t\t'items' =\u003e [\n\t\t\t[ 'sku' =\u003e 'WIDGET-1', 'qty' =\u003e 2 ],\n\t\t\t[ 'sku' =\u003e 'GADGET-5', 'qty' =\u003e 1 ]\n\t\t],\n\t\t'total' =\u003e 149.99\n\t],\n\t'customer_id' =\u003e 789\n] );\n\n// Exception tracking with automatic formatting\ntry\n{\n\t// some operation\n}\ncatch( Exception $e )\n{\n\tLog::error( 'Operation failed', [\n\t\t'exception' =\u003e $e,  // Stack trace automatically captured\n\t\t'operation' =\u003e 'process_payment',\n\t\t'user_id' =\u003e $userId\n\t] );\n}\n```\n\n### Message Interpolation\n\n```php\n// Use {placeholders} in messages - PSR-3 style\nLog::info( 'User {userId} logged in from {ip} at {time}', [\n\t'userId' =\u003e 12345,\n\t'ip' =\u003e '192.168.1.100',\n\t'time' =\u003e date( 'H:i:s' )\n] );\n// Output: User 12345 logged in from 192.168.1.100 at 14:30:45\n\n// Interpolation works with all log levels\nLog::error( 'Failed to send email to {email}: {error}', [\n\t'email' =\u003e 'user@example.com',\n\t'error' =\u003e 'SMTP connection refused',\n\t'retry_count' =\u003e 3\n] );\n```\n\n### Global and Local Context\n\n```php\nuse Neuron\\Log\\Log;\n\n// Set global context that applies to all logs\nLog::setContext( 'app_version', '2.0.0' );\nLog::setContext( 'environment', 'production' );\nLog::setContext( 'server', gethostname() );\n\n// Can also set array values in global context\nLog::setContext( 'tags', [ 'monitoring', 'production' ] );\n\n// Local context in log call is merged with global\nLog::info( 'User action', [\n\t'action' =\u003e 'profile_update',\n\t'user_id' =\u003e 456\n] );\n// Both global and local context are included\n\n### Multiple Channels\n\n```php\nuse Neuron\\Log\\Log;\nuse Neuron\\Log\\Logger;\nuse Neuron\\Log\\Destination\\File;\nuse Neuron\\Log\\Destination\\Slack;\nuse Neuron\\Log\\Format\\PlainText;\nuse Neuron\\Log\\Format\\SlackFormat;\n\n// Create an audit logger\n$auditFile = new File( new PlainText() );\n$auditFile-\u003eopen( [ 'path' =\u003e '/var/log/audit.log' ] );\n$auditLogger = new Logger( $auditFile );\n\n// Create a real-time alerts logger\n$alertSlack = new Slack( new SlackFormat() );\n$alertSlack-\u003eopen( [\n\t'endpoint' =\u003e $_ENV['SLACK_WEBHOOK'],\n\t'params' =\u003e [ 'channel' =\u003e '#alerts' ]\n] );\n$alertLogger = new Logger( $alertSlack );\n\n// Register channels\nLog::addChannel( 'audit', $auditLogger );\nLog::addChannel( 'alerts', $alertLogger );\n\n// Use specific channels\nLog::channel( 'audit' )-\u003einfo( 'User login', [ 'user' =\u003e $username ] );\nLog::channel( 'alerts' )-\u003eemergency( 'System down!' );\n```\n\n### Multiplexer (Multiple Destinations)\n\n```php\nuse Neuron\\Log\\LogMux;\nuse Neuron\\Log\\Logger;\nuse Neuron\\Log\\Destination\\File;\nuse Neuron\\Log\\Destination\\StdErr;\nuse Neuron\\Log\\Format\\PlainText;\nuse Neuron\\Log\\Format\\JSON;\n\n// Create multiple loggers\n$fileLogger = new Logger( new File( new JSON() ) );\n$fileLogger-\u003egetDestination()-\u003eopen( [ 'path' =\u003e '/var/log/app.json' ] );\n$fileLogger-\u003esetRunLevel( 'debug' );\n\n$consoleLogger = new Logger( new StdErr( new PlainText() ) );\n$consoleLogger-\u003esetRunLevel( 'warning' );\n\n// Create multiplexer\n$mux = new LogMux();\n$mux-\u003eaddLog( $fileLogger );\n$mux-\u003eaddLog( $consoleLogger );\n\n// Logs go to both destinations based on their run levels\n$mux-\u003edebug( 'Debug info' );     // Only to file\n$mux-\u003ewarning( 'Warning!' );     // To both file and console\n$mux-\u003eerror( 'Error occurred' ); // To both file and console\n```\n\n### PSR-3 Adapter\n\nThe 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.).\n\n#### Basic Usage\n\n```php\nuse Neuron\\Log\\Logger;\nuse Neuron\\Log\\Adapter\\Psr3Adapter;\nuse Neuron\\Log\\Destination\\File;\nuse Neuron\\Log\\Format\\JSON;\n\n// Create a Neuron logger\n$destination = new File( new JSON() );\n$destination-\u003eopen( [ 'path' =\u003e '/var/log/app.json' ] );\n$neuronLogger = new Logger( $destination );\n$neuronLogger-\u003esetRunLevel( 'info' );\n\n// Wrap it with the PSR-3 adapter\n$psr3Logger = new Psr3Adapter( $neuronLogger );\n\n// Now use it with any PSR-3 expecting code\n$psr3Logger-\u003einfo( 'Application started' );\n$psr3Logger-\u003eerror( 'Database connection failed', [\n\t'host' =\u003e 'db.example.com',\n\t'error' =\u003e 'Connection timeout'\n] );\n```\n\n#### Framework Integration\n\nThe adapter makes it easy to integrate Neuron logging into frameworks that expect PSR-3:\n\n```php\nuse Neuron\\Log\\Log;\nuse Neuron\\Log\\Adapter\\Psr3Adapter;\n\n// Get Neuron's singleton logger and wrap it\n$psr3Logger = new Psr3Adapter( Log::getInstance()-\u003eLogger );\n\n// Use with Symfony components\n$httpClient = new \\Symfony\\Component\\HttpClient\\CurlHttpClient( [\n\t'logger' =\u003e $psr3Logger\n] );\n\n// Use with Guzzle\n$guzzleClient = new \\GuzzleHttp\\Client( [\n\t'handler' =\u003e $handlerStack,\n\t'logger' =\u003e $psr3Logger\n] );\n\n// Use with any PSR-3 compatible library\n$thirdPartyService = new ThirdPartyService( $psr3Logger );\n```\n\n#### Level Mapping\n\nThe adapter automatically maps PSR-3 log levels to Neuron's RunLevel enum:\n\n| PSR-3 Level | Neuron RunLevel | Numeric Value |\n|-------------|-----------------|---------------|\n| emergency   | EMERGENCY       | 50            |\n| alert       | ALERT           | 45            |\n| critical    | CRITICAL        | 40            |\n| error       | ERROR           | 30            |\n| warning     | WARNING         | 20            |\n| notice      | NOTICE          | 15            |\n| info        | INFO            | 10            |\n| debug       | DEBUG           | 0             |\n\n#### Advanced Features\n\nThe adapter maintains full compatibility with Neuron's advanced features:\n\n```php\nuse Neuron\\Log\\Logger;\nuse Neuron\\Log\\Adapter\\Psr3Adapter;\nuse Neuron\\Log\\Destination\\File;\nuse Neuron\\Log\\Format\\JSON;\n\n// Create Neuron logger with multiple destinations\n$fileLogger = new Logger( new File( new JSON() ) );\n$fileLogger-\u003egetDestination()-\u003eopen( [ 'path' =\u003e '/var/log/app.json' ] );\n\n// Add filters, context, and other Neuron features\n$fileLogger-\u003esetContext( 'app_version', '2.0.0' );\n$fileLogger-\u003esetContext( 'environment', 'production' );\n\n// Wrap with PSR-3 adapter\n$psr3Logger = new Psr3Adapter( $fileLogger );\n\n// PSR-3 calls use Neuron features underneath\n$psr3Logger-\u003ewarning( 'API rate limit approaching', [\n\t'requests' =\u003e 950,\n\t'limit' =\u003e 1000\n] );\n// Context includes: app_version, environment, requests, limit\n\n// Access the underlying Neuron logger if needed\n$neuronLogger = $psr3Logger-\u003egetNeuronLogger();\n$neuronLogger-\u003esetRunLevel( 'debug' );\n```\n\n#### Why Use the Adapter?\n\n1. **Framework Integration**: Use Neuron's powerful logging with any PSR-3 expecting library\n2. **Gradual Migration**: Migrate from other PSR-3 loggers without changing application code\n3. **Best of Both Worlds**: Keep Neuron's advanced features (multiple destinations, formats, filters) while maintaining PSR-3 compatibility\n4. **Drop-in Replacement**: Works as a drop-in replacement for Monolog, PSR-3 Log, or other PSR-3 implementations\n\n### Custom Filters\n\n```php\nuse Neuron\\Log\\Logger;\nuse Neuron\\Log\\Filter\\IFilter;\nuse Neuron\\Log\\RunLevel;\n\nclass ProductionFilter implements IFilter\n{\n\tpublic function shouldLog( RunLevel $level, string $message, array $context ): bool\n\t{\n\t\t// Don't log debug messages in production\n\t\tif( $level === RunLevel::DEBUG \u0026\u0026 $_ENV['APP_ENV'] === 'production' )\n\t\t{\n\t\t\treturn false;\n\t\t}\n\n\t\t// Don't log sensitive data\n\t\tif( str_contains( $message, 'password' ) || str_contains( $message, 'token' ) )\n\t\t{\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n}\n\n$logger = new Logger( $destination );\n$logger-\u003eaddFilter( new ProductionFilter() );\n```\n\n## Advanced Configuration\n\n### Environment-Based Configuration\n\n```php\nuse Neuron\\Log\\Log;\nuse Neuron\\Log\\Logger;\nuse Neuron\\Log\\Destination\\File;\nuse Neuron\\Log\\Destination\\StdOut;\nuse Neuron\\Log\\Format\\JSON;\nuse Neuron\\Log\\Format\\PlainText;\n\n$environment = $_ENV['APP_ENV'] ?? 'development';\n\nif( $environment === 'production' )\n{\n\t// Production: JSON to file\n\t$destination = new File( new JSON() );\n\t$destination-\u003eopen( [ 'path' =\u003e '/var/log/app.json' ] );\n\t$runLevel = 'warning';\n}\nelse\n{\n\t// Development: Plain text to console\n\t$destination = new StdOut( new PlainText( true ) );\n\t$runLevel = 'debug';\n}\n\n$logger = new Logger( $destination );\n$logger-\u003esetRunLevel( $runLevel );\n\nLog::getInstance()-\u003eLogger-\u003eaddLog( $logger );\n```\n\n### Testing with Memory Logger\n\n```php\nuse Neuron\\Log\\Logger;\nuse Neuron\\Log\\Destination\\Memory;\nuse Neuron\\Log\\Format\\Raw;\n\n// For unit testing\n$memoryDestination = new Memory( new Raw() );\n$testLogger = new Logger( $memoryDestination );\n\n$testLogger-\u003eerror( 'Test error' );\n$testLogger-\u003einfo( 'Test info' );\n\n// Retrieve logged messages\n$logs = $memoryDestination-\u003egetLogs();\nassert( count( $logs ) === 2 );\nassert( $logs[0]['level'] === 'error' );\n```\n\n## API Reference\n\n### Log Levels\n\nThe following PSR-3 compliant log levels are supported (from lowest to highest severity):\n\n- `debug` (0) - Detailed debug information for development and troubleshooting\n- `info` (10) - Informational messages about application flow\n- `notice` (15) - Normal but significant events\n- `warning` (20) - Warning messages about potentially harmful situations\n- `error` (30) - Error events that allow the application to continue running\n- `critical` (40) - Critical conditions that need immediate attention\n- `alert` (45) - Action must be taken immediately\n- `emergency` (50) - System is unusable, requires immediate intervention\n\n### Logger Methods\n\nAll logger methods accept an optional array context for additional data:\n\n```php\n$logger-\u003edebug( string $message, array $context = [] );\n$logger-\u003einfo( string $message, array $context = [] );\n$logger-\u003enotice( string $message, array $context = [] );\n$logger-\u003ewarning( string $message, array $context = [] );\n$logger-\u003eerror( string $message, array $context = [] );\n$logger-\u003ecritical( string $message, array $context = [] );\n$logger-\u003ealert( string $message, array $context = [] );\n$logger-\u003eemergency( string $message, array $context = [] );\n$logger-\u003elog( string $message, RunLevel $level, array $context = [] );\n\n// Set minimum log level\n$logger-\u003esetRunLevel( mixed $level );           // Accepts RunLevel enum or string\n$logger-\u003esetRunLevelText( string $level );      // Set by text: 'debug', 'info', etc.\n$logger-\u003egetRunLevel(): RunLevel;               // Get current run level\n\n// Context management\n$logger-\u003esetContext( string $name, mixed $value );  // Add global context\n$logger-\u003egetContext(): array;                       // Get all context\n$logger-\u003ereset();                                   // Clear all context\n```\n\n## Testing\n\nRun the test suite:\n\n```bash\n./vendor/bin/phpunit tests\n```\n\nRun tests with coverage:\n\n```bash\n./vendor/bin/phpunit tests --coverage-text\n```\n\n## Contributing\n\nContributions are welcome! Please ensure all tests pass and maintain code coverage above 95%.\n\n## License\n\nMIT License - see LICENSE file for details.\n\n## More Information\n\n- Full documentation: [neuronphp.com](http://neuronphp.com)\n- GitHub: [github.com/neuron-php/logging](https://github.com/neuron-php/logging)\n- Issues: [github.com/neuron-php/logging/issues](https://github.com/neuron-php/logging/issues)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuron-php%2Flogging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneuron-php%2Flogging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuron-php%2Flogging/lists"}