Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
tests:
name: PHP ${{ matrix.php }} - ${{ matrix.dependencies }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: ['8.0', '8.1', '8.2', '8.3', '8.4']
dependencies: ['highest']
include:
- php: '8.0'
dependencies: 'lowest'

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: pdo, pdo_sqlite
coverage: xdebug
tools: composer:v2

- name: Validate composer.json
run: composer validate --strict

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-php-${{ matrix.php }}-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }}
restore-keys: |
${{ runner.os }}-php-${{ matrix.php }}-${{ matrix.dependencies }}-

- name: Install dependencies (highest)
if: matrix.dependencies == 'highest'
run: composer update --no-interaction --no-progress --prefer-dist

- name: Install dependencies (lowest)
if: matrix.dependencies == 'lowest'
run: composer update --no-interaction --no-progress --prefer-dist --prefer-lowest

- name: Run PHPUnit
run: vendor/bin/phpunit --colors=always

static-analysis:
name: Static Analysis
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: pdo, pdo_sqlite
tools: composer:v2

- name: Install dependencies
run: composer update --no-interaction --no-progress --prefer-dist

- name: PHPStan
run: vendor/bin/phpstan analyse --no-progress

coding-standards:
name: Coding Standards
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
tools: composer:v2

- name: Install dependencies
run: composer update --no-interaction --no-progress --prefer-dist

- name: PHP-CS-Fixer (dry-run)
run: vendor/bin/php-cs-fixer fix --dry-run --diff --using-cache=no
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
/.vs/
/.vscode/
/vendor/
/composer.lock
/composer.lock
/.phpunit.result.cache
/.phpunit.cache/
/.php-cs-fixer.cache
/build/
/coverage/
30 changes: 30 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
->name('*.php');

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'declare_strict_types' => true,
'no_unused_imports' => true,
'ordered_imports' => [
'sort_algorithm' => 'alpha',
'imports_order' => ['class', 'function', 'const'],
],
'single_quote' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'native_function_invocation' => false,
'native_constant_invocation' => false,
'phpdoc_align' => ['align' => 'left'],
'phpdoc_separation' => true,
'phpdoc_trim' => true,
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
])
->setFinder($finder);
81 changes: 81 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Changelog

All notable changes to `initphp/logger` are documented here.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Full PSR-3 v3 compliance: every handler now implements
`Psr\Log\LoggerInterface` directly, including `Logger`, which previously
relied on `__call()` for dispatch.
- `Throwable` rendering for context placeholders β€” any `\Throwable` value in
the context array is rendered as `Class(code): message in file:line`.
- `string|\Stringable` accepted as message type across all handlers.
- `FileLogger`:
- Automatic creation of the parent directory (mode `0775`).
- Concurrent-safe writes via `FILE_APPEND | LOCK_EX`.
- `getPath()` accessor returning the token-interpolated path.
- `PDOLogger`:
- Table-name validation against `/^[A-Za-z_][A-Za-z0-9_]*$/` to prevent
identifier injection.
- Distinct, specific error messages for each invalid construction path.
- `getTable()` accessor.
- `Logger`:
- At least one logger is now required at construction time.
- Variadic `LoggerInterface` typing β€” non-`LoggerInterface` arguments raise
`TypeError` instead of being silently dropped.
- `getLoggers()` accessor.
- Comprehensive PHPUnit test suite (45 tests, 80 assertions).
- PHPStan (`level: max`) and PHP-CS-Fixer (PSR-12) configured and CI-enforced.
- GitHub Actions CI matrix: PHP 8.0 / 8.1 / 8.2 / 8.3 / 8.4.
- `docs/` directory with eight topic guides (getting started, file logger,
PDO logger, multi-logger, custom handlers, PSR-3 context, recipes, testing).

### Changed

- **Minimum PHP version raised to 8.0** (was 5.6). PHP 8.0+ is required for
PSR-3 v3 anyway.
- **`psr/log` constraint bumped to `^3.0`** (was the pinned `1.1.4`).
- All source files now declare `strict_types=1` and use property/parameter/
return-type declarations.
- `Logger` is now `final`. Sub-classing it was never documented; users who
need to customise fan-out behaviour should compose with `LoggerInterface`.
- Log lines emitted by `FileLogger` now terminate with `PHP_EOL` instead of
beginning with one β€” the previous behaviour produced a stray empty line at
the top of every log file and made tailing awkward.

### Fixed

- `HelperTrait::$levels` no longer contains `LogLevel::WARNING` twice; the
list now mirrors the canonical eight PSR-3 levels in severity order.
- `FileLogger` no longer silently swallows write failures with the `@`
operator; failures are reported through `error_log()`.
- `FileLogger` rejects missing/empty/non-string `path` options at
construction with a clear `InvalidArgumentException`, instead of failing
obliquely at the first write.
- `PDOLogger` raises specific, actionable `InvalidArgumentException` messages
for each missing or wrongly-typed option (previously a single generic
"It must be a PDO object." message was thrown for several distinct
failures).
- `PDOLogger` uses `Psr\Log\InvalidArgumentException` consistently per
PSR-3 Β§1.1 (the previous code imported it but threw the SPL variant).
- `PDOLogger::__destruct` removed β€” manually nulling an injected PDO is not
the logger's responsibility and could mislead readers about ownership.

### Removed

- `Logger::__call()` magic dispatch. The class now implements
`LoggerInterface` properly.

**Behaviour change for callers:** Previously, calling an unknown method on
`Logger` (e.g. `$logger->banana()`) silently no-op'd via `__call()`.
Such calls now raise `Error: Call to undefined method
InitPHP\Logger\Logger::banana()` at the PHP level. Legitimate PSR-3 calls
(`emergency()` … `debug()`, `log()`) are unaffected.

## 1.0 - 2022-03-11

Initial release.
Loading
Loading