Download the PHP package uengage.io/php-logger without Composer
On this page you can find all versions of the php package uengage.io/php-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download uengage.io/php-logger
More information about uengage.io/php-logger
Files in uengage.io/php-logger
Package php-logger
Short Description Structured observability logging for uEngage platform services
License MIT
Informations about the package php-logger
uengage.io/php-logger
Structured observability logging for uEngage platform services. Write logs to a local file, POST them over HTTP, or emit to stdout - same JSON schema regardless of transport.
Table of Contents
- uengage.io/php-logger
- Table of Contents
- Overview
- Requirements
- Installation
- Quick Start
- File transporter (server / EC2)
- HTTP transporter (no cloud agent)
- Stdout transporter (Lambda / Docker)
- Log Schema
- Initialization
- Config Reference
- Transporters
- File Transporter
- HTTP Transporter
- Stdout Transporter
- Log Methods
- Method Signature
- Log Options Reference
- Level Filtering
- Graceful Shutdown
- CodeIgniter 2 Integration
- Prerequisite - load Composer autoloader
- Logger_service library
- Flushing HTTP batch mode in CI2
- CodeIgniter 4 Integration
- PHP-Specific Notes
- Examples
- Business event - order placed
- Engineering error - payment gateway timeout
- Warning - rate limit approaching
- Debug - database query
- Architecture
- Running Tests
Overview
uengage/logger provides a single Logger class with four log-level methods (info, error, debug, warn). On initialization you choose a transport:
| Transport | How it works | Best for |
|---|---|---|
file |
Appends NDJSON lines to {basePath}/application/{product}.log |
EC2/server - CloudWatch Agent, Datadog Agent, or Fluentd ships the file |
http |
POSTs JSON to an HTTP endpoint | Environments without a cloud agent |
stdout |
Writes one NDJSON line per entry to php://stdout |
Lambda (Bref / custom runtime), Docker |
The log schema is identical to the Node.js @uengage/logger package - uniform cross-service log analysis.
Requirements
- PHP >= 7.1
ext-curl(required for HTTP transporter; standard on virtually all hosting environments)- Composer
Installation
Quick Start
File transporter (server / EC2)
HTTP transporter (no cloud agent)
Stdout transporter (Lambda / Docker)
Log Schema
timestamp…message- always presentuser_id,error,context- omitted when not passed
Initialization
Validates synchronously; throws \InvalidArgumentException immediately if anything required is missing or invalid.
Config Reference
Transporters
File Transporter
Appends one NDJSON line per entry to {basePath}/application/{product}.log. The directory is created automatically; all services for the same product on a host share one file.
File rotation - when the file reaches maxFileSizeBytes:
Configure your cloud agent to watch application/edge.log* to pick up rotated files. Writes use FILE_APPEND | LOCK_EX - safe for concurrent PHP-FPM workers.
HTTP Transporter
POSTs log entries to an HTTP endpoint via cURL.
- Immediate mode (
batchSize: 1) - one POST per call; body is a plain JSON object. - Batch mode (default
batchSize: 5) - entries queue; body is a JSON array. Call$logger->destroy()before exit to flush the remaining queue. - cURL errors and non-2xx responses are written to
error_log()with prefix[uengage-logger][http]; the host application is never interrupted.
Stdout Transporter
Writes one NDJSON line per entry to php://stdout. No config knobs.
Best for AWS Lambda (Bref / custom PHP runtime) and Docker - the runtime captures stdout into CloudWatch Logs or your log-aggregation service. Uses php://stdout rather than the STDOUT constant, which is undefined under PHP-FPM and most Lambda runtime adapters.
Log Methods
Method Signature
Log Options Reference
Level Filtering
Set minLevel to suppress low-priority logs without changing call sites (default: 'warn'):
| minLevel | DEBUG | INFO | WARN | ERROR |
|---|---|---|---|---|
'warn' (default) |
- | - | ✓ | ✓ |
'info' |
- | ✓ | ✓ | ✓ |
'error' |
- | - | - | ✓ |
'debug' |
✓ | ✓ | ✓ | ✓ |
Graceful Shutdown
| Transport | Action needed |
|---|---|
file |
None - writes are synchronous. |
http (immediate, batchSize=1) |
None - each call fires synchronously. |
http (batch, default batchSize=5) |
Call $logger->destroy() before exit to flush the queue. |
stdout |
None - writes are synchronous. |
Register shutdown for HTTP batch mode:
CodeIgniter 2 Integration
Prerequisite - load Composer autoloader
CI2 does not load Composer's autoloader by default. Add one of the following:
Option A - application/config/config.php (recommended):
Option B - index.php (before the CI bootstrap):
Logger_service library
Logger_service acts as a lazy factory for the logger. Load it once per controller; it caches one Logger instance per service name for the lifetime of the request.
1. Load the library in your controller
2. Get a logger and write a log
3. Use from a library / helper (no $this)
How it works internally
| What | Detail |
|---|---|
| Factory method | get(string $service, string $component = 'edge-server') |
| Caching | One Logger instance per "service:component" key per request |
| Log file | loggerlogs/edge-{service}.log |
| Min level | warn in production, debug in all other environments |
| Fallback | If Logger construction fails, a NullLogger is returned - your code never throws |
Tip - dynamic log level
Flushing HTTP batch mode in CI2
Register destroy() via a post_system hook:
Or via register_shutdown_function in your base controller:
CodeIgniter 4 Integration
CI4 includes Composer autoloading out of the box - no manual require needed.
Register as a CI4 Service (app/Config/Services.php):
Use in any Controller, Model, or Library:
Flushing HTTP batch mode - register destroy() in a CI4 After-filter or your BaseController destructor:
PHP-Specific Notes
| Behaviour | PHP implementation | Note |
|---|---|---|
| Non-blocking writes | Synchronous - writes complete inline | PHP has no event loop |
flushIntervalMs |
Accepted in config but no-op | Use destroy() instead |
| UUID generation | openssl_random_pseudo_bytes (preferred) or mt_rand fallback |
|
| Deep clone | json_decode(json_encode($val), true) |
Equivalent to JS structuredClone() |
| Timestamp | gmdate() + microtime(true) ms |
Produces Z suffix matching ISO 8601 / Node output |
| Error output | error_log() |
Visible in /var/log/php_errors.log or Apache/Nginx error log |
| Concurrent file writes | file_put_contents(..., FILE_APPEND \| LOCK_EX) |
Prevents torn writes from concurrent FPM workers |
Examples
Business event - order placed
Engineering error - payment gateway timeout
Warning - rate limit approaching
Debug - database query
Architecture
Error contract: every transporter catches all internal errors and writes to error_log(). A logging failure never throws to the caller.
Running Tests
Expected output:
All versions of php-logger with dependencies
ext-curl Version *