{"id":21771127,"url":"https://github.com/initphp/logger","last_synced_at":"2026-05-24T13:01:08.540Z","repository":{"id":56991540,"uuid":"470087007","full_name":"InitPHP/Logger","owner":"InitPHP","description":"Library developed for logging to file or database in PSR-3 standards.","archived":false,"fork":false,"pushed_at":"2023-12-15T17:30:50.000Z","size":6,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-06T17:59:09.927Z","etag":null,"topics":["logger","php","php-logger","php-logging","php-logging-library","psr-3"],"latest_commit_sha":null,"homepage":"","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/InitPHP.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}},"created_at":"2022-03-15T09:25:25.000Z","updated_at":"2022-05-26T19:36:34.000Z","dependencies_parsed_at":"2025-04-13T16:51:43.648Z","dependency_job_id":null,"html_url":"https://github.com/InitPHP/Logger","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/InitPHP/Logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InitPHP%2FLogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InitPHP%2FLogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InitPHP%2FLogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InitPHP%2FLogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/InitPHP","download_url":"https://codeload.github.com/InitPHP/Logger/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InitPHP%2FLogger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30287446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T02:57:19.223Z","status":"ssl_error","status_checked_at":"2026-03-09T02:56:26.373Z","response_time":61,"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":["logger","php","php-logger","php-logging","php-logging-library","psr-3"],"created_at":"2024-11-26T14:15:09.834Z","updated_at":"2026-05-24T13:01:08.406Z","avatar_url":"https://github.com/InitPHP.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# InitPHP Logger\n\nA small, focused, PSR-3 compliant logger for PHP 8.0+. Ships with two built-in\nhandlers and a tiny multiplexer that fans every log record out to several\nhandlers at once.\n\n[![Latest Stable Version](https://poser.pugx.org/initphp/logger/v)](https://packagist.org/packages/initphp/logger)\n[![Total Downloads](https://poser.pugx.org/initphp/logger/downloads)](https://packagist.org/packages/initphp/logger)\n[![License](https://poser.pugx.org/initphp/logger/license)](https://packagist.org/packages/initphp/logger)\n[![PHP Version Require](https://poser.pugx.org/initphp/logger/require/php)](https://packagist.org/packages/initphp/logger)\n\n## At a glance\n\n- **`FileLogger`** — appends each record as a single line to a file, with\n  optional date-token placeholders in the path (`{year}/{month}/{day}/...`).\n- **`PDOLogger`** — inserts each record as a row in a relational table, using\n  prepared statements. Works with any PDO driver (MySQL, PostgreSQL, SQLite…).\n- **`Logger`** — accepts any number of `Psr\\Log\\LoggerInterface` instances and\n  forwards every call to all of them, in registration order.\n\nEverything implements `Psr\\Log\\LoggerInterface` (PSR-3 v3), so you can drop the\npackage into any framework or library that consumes that contract — or compose\nit with handlers from other PSR-3 packages.\n\n## Requirements\n\n| Requirement | Version |\n| --- | --- |\n| PHP | `\u003e= 8.0` |\n| [`psr/log`](https://packagist.org/packages/psr/log) | `^3.0` |\n| `ext-pdo` | Required only for `PDOLogger` |\n\n## Installation\n\n```bash\ncomposer require initphp/logger\n```\n\n## Quick start\n\n```php\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse InitPHP\\Logger\\FileLogger;\nuse InitPHP\\Logger\\Logger;\n\n$logger = new Logger(\n    new FileLogger(['path' =\u003e __DIR__ . '/logs/app.log'])\n);\n\n$logger-\u003einfo('Service booted in {ms}ms', ['ms' =\u003e 42]);\n$logger-\u003eerror('Payment {id} failed', ['id' =\u003e 9182]);\n```\n\nProduces, for example:\n\n```\n2026-05-24T14:08:22+03:00 [INFO] Service booted in 42ms\n2026-05-24T14:08:22+03:00 [ERROR] Payment 9182 failed\n```\n\n## Handlers\n\n### FileLogger\n\n```php\nuse InitPHP\\Logger\\FileLogger;\n\n$logger = new FileLogger([\n    'path' =\u003e __DIR__ . '/logs/app-{year}-{month}-{day}.log',\n]);\n```\n\nPath tokens (`{year}`, `{month}`, `{day}`, `{hour}`, `{minute}`, `{second}`) are\nresolved once, at construction time, against the process clock. The parent\ndirectory is created automatically (mode `0775`) if it does not already exist.\nWrites use `FILE_APPEND | LOCK_EX`, so concurrent processes do not interleave\nbytes within a single record.\n\nFull reference: [`docs/02-file-logger.md`](docs/02-file-logger.md).\n\n### PDOLogger\n\n```php\nuse InitPHP\\Logger\\PDOLogger;\n\n$pdo = new PDO('mysql:host=localhost;dbname=app;charset=utf8mb4', 'app', 'secret');\n$pdo-\u003esetAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\n\n$logger = new PDOLogger(['pdo' =\u003e $pdo, 'table' =\u003e 'logs']);\n\n$logger-\u003eerror('User {user} caused an error.', ['user' =\u003e 'muhammetsafak']);\n// INSERT INTO logs (level, message, date) VALUES ('ERROR', 'User muhammetsafak caused an error.', '2026-05-24 14:08:22')\n```\n\nReference DDL for MySQL:\n\n```sql\nCREATE TABLE `logs` (\n    `id`      BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n    `level`   ENUM('EMERGENCY','ALERT','CRITICAL','ERROR','WARNING','NOTICE','INFO','DEBUG') NOT NULL,\n    `message` TEXT NOT NULL,\n    `date`    DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n    KEY `idx_logs_level_date` (`level`, `date`)\n) ENGINE = InnoDB CHARSET = utf8mb4 COLLATE utf8mb4_general_ci;\n```\n\nPostgreSQL and SQLite variants are documented in\n[`docs/03-pdo-logger.md`](docs/03-pdo-logger.md).\n\n### Multi-handler logging\n\n```php\nuse InitPHP\\Logger\\FileLogger;\nuse InitPHP\\Logger\\Logger;\nuse InitPHP\\Logger\\PDOLogger;\n\n$logger = new Logger(\n    new FileLogger(['path' =\u003e __DIR__ . '/logs/app.log']),\n    new PDOLogger(['pdo' =\u003e $pdo, 'table' =\u003e 'logs'])\n);\n\n$logger-\u003ewarning('cache miss for key {key}', ['key' =\u003e 'user:42']);\n// Goes to BOTH the file and the database table.\n```\n\n`Logger` accepts any `Psr\\Log\\LoggerInterface`, including handlers from other\nPSR-3 packages — see [`docs/05-custom-handlers.md`](docs/05-custom-handlers.md).\n\n## PSR-3 surface\n\nEvery handler exposes the full PSR-3 API:\n\n```php\n$logger-\u003eemergency(string|\\Stringable $message, array $context = []): void;\n$logger-\u003ealert    (string|\\Stringable $message, array $context = []): void;\n$logger-\u003ecritical (string|\\Stringable $message, array $context = []): void;\n$logger-\u003eerror    (string|\\Stringable $message, array $context = []): void;\n$logger-\u003ewarning  (string|\\Stringable $message, array $context = []): void;\n$logger-\u003enotice   (string|\\Stringable $message, array $context = []): void;\n$logger-\u003einfo     (string|\\Stringable $message, array $context = []): void;\n$logger-\u003edebug    (string|\\Stringable $message, array $context = []): void;\n$logger-\u003elog      ($level, string|\\Stringable $message, array $context = []): void;\n```\n\nContext placeholders (`{name}`) are expanded with the matching key from\n`$context`. Booleans render as `true` / `false`, `null` renders as the empty\nstring, `\\Throwable` values render as `Class(code): message in file:line`,\nand anything implementing `__toString()` is cast to string. Arrays and\nnon-stringable objects are skipped — see\n[`docs/06-psr3-context.md`](docs/06-psr3-context.md).\n\nUnknown log levels throw `Psr\\Log\\InvalidArgumentException`, per PSR-3 §1.1.\n\n## Documentation\n\nTopic-by-topic guides live in [`docs/`](docs/):\n\n- [`01-getting-started.md`](docs/01-getting-started.md)\n- [`02-file-logger.md`](docs/02-file-logger.md)\n- [`03-pdo-logger.md`](docs/03-pdo-logger.md)\n- [`04-multi-logger.md`](docs/04-multi-logger.md)\n- [`05-custom-handlers.md`](docs/05-custom-handlers.md)\n- [`06-psr3-context.md`](docs/06-psr3-context.md)\n- [`07-recipes.md`](docs/07-recipes.md)\n- [`08-testing-your-logging.md`](docs/08-testing-your-logging.md)\n\n## Testing the package itself\n\n```bash\ncomposer install\ncomposer test         # PHPUnit\ncomposer phpstan      # PHPStan (level max)\ncomposer cs-check     # PHP-CS-Fixer dry-run\ncomposer ci           # all of the above\n```\n\n## Contributing\n\nPlease read the org-wide\n[`CONTRIBUTING.md`](https://github.com/InitPHP/.github/blob/main/CONTRIBUTING.md)\nbefore opening a pull request. Bug reports and feature ideas go through\n[Issues](https://github.com/InitPHP/Logger/issues) and\n[Discussions](https://github.com/orgs/InitPHP/discussions).\n\n## Security\n\nIf you discover a security vulnerability, please follow the instructions in the\norg-wide\n[`SECURITY.md`](https://github.com/InitPHP/.github/blob/main/SECURITY.md). Do\n**not** open a public issue.\n\n## License\n\nReleased under the [MIT License](LICENSE). Copyright © InitPHP.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finitphp%2Flogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finitphp%2Flogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finitphp%2Flogger/lists"}