Download the PHP package initphp/logger without Composer
On this page you can find all versions of the php package initphp/logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download initphp/logger
More information about initphp/logger
Files in initphp/logger
Package logger
Short Description PSR-3 compliant logger with File and PDO handlers, plus a multiplexer for sending each log record to several handlers at once.
License MIT
Informations about the package logger
InitPHP Logger
A small, focused, PSR-3 compliant logger for PHP 8.0+. Ships with two built-in handlers and a tiny multiplexer that fans every log record out to several handlers at once.
At a glance
FileLogger— appends each record as a single line to a file, with optional date-token placeholders in the path ({year}/{month}/{day}/...).PDOLogger— inserts each record as a row in a relational table, using prepared statements. Works with any PDO driver (MySQL, PostgreSQL, SQLite…).Logger— accepts any number ofPsr\Log\LoggerInterfaceinstances and forwards every call to all of them, in registration order.
Everything implements Psr\Log\LoggerInterface (PSR-3 v3), so you can drop the
package into any framework or library that consumes that contract — or compose
it with handlers from other PSR-3 packages.
Requirements
| Requirement | Version |
|---|---|
| PHP | >= 8.0 |
psr/log |
^3.0 |
ext-pdo |
Required only for PDOLogger |
Installation
Quick start
Produces, for example:
Handlers
FileLogger
Path tokens ({year}, {month}, {day}, {hour}, {minute}, {second}) are
resolved once, at construction time, against the process clock. The parent
directory is created automatically (mode 0775) if it does not already exist.
Writes use FILE_APPEND | LOCK_EX, so concurrent processes do not interleave
bytes within a single record.
Full reference: docs/02-file-logger.md.
PDOLogger
Reference DDL for MySQL:
PostgreSQL and SQLite variants are documented in
docs/03-pdo-logger.md.
Multi-handler logging
Logger accepts any Psr\Log\LoggerInterface, including handlers from other
PSR-3 packages — see docs/05-custom-handlers.md.
PSR-3 surface
Every handler exposes the full PSR-3 API:
Context placeholders ({name}) are expanded with the matching key from
$context. Booleans render as true / false, null renders as the empty
string, \Throwable values render as Class(code): message in file:line,
and anything implementing __toString() is cast to string. Arrays and
non-stringable objects are skipped — see
docs/06-psr3-context.md.
Unknown log levels throw Psr\Log\InvalidArgumentException, per PSR-3 §1.1.
Documentation
Topic-by-topic guides live in docs/:
01-getting-started.md02-file-logger.md03-pdo-logger.md04-multi-logger.md05-custom-handlers.md06-psr3-context.md07-recipes.md08-testing-your-logging.md
Testing the package itself
Contributing
Please read the org-wide
CONTRIBUTING.md
before opening a pull request. Bug reports and feature ideas go through
Issues and
Discussions.
Security
If you discover a security vulnerability, please follow the instructions in the
org-wide
SECURITY.md. Do
not open a public issue.
License
Released under the MIT License. Copyright © InitPHP.