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
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpstan.neon export-ignore
/scripts export-ignore
/tests export-ignore
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:
pull_request:
branches: [master]
push:
branches: [master]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
verify:
name: PHP ${{ matrix.php }} (${{ matrix.deps }})
runs-on: ubuntu-24.04
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
include:
- { php: '8.4', deps: 'latest' }
- { php: '8.5', deps: 'latest' }
- { php: '8.4', deps: 'lowest' }
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: none
- name: Validate composer.json
run: composer validate --strict
- name: Resolve dependencies
run: |
if [ "${{ matrix.deps }}" = "lowest" ]; then
composer update --prefer-lowest --prefer-stable --no-interaction --prefer-dist --no-progress
else
composer update --no-interaction --prefer-dist --no-progress
fi
- name: Check platform requirements
run: composer check-platform-reqs
- name: PHP security patch floors
run: composer check:php-floors
- name: PHP syntax
run: composer lint:php
- name: Whitespace
run: composer lint:whitespace
- name: PHPStan
run: composer analyse
- name: Tests
run: composer test
- name: Composer audit
run: composer audit:deps

consumer-harness:
name: Consumer Verification Harness
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.5'
tools: composer:v2
coverage: none
- name: Harness (two clean consumer installs)
run: composer harness
- name: Examples smoke execution
run: composer examples

workflow-lint:
name: Workflow lint
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- run: scripts/lint-workflows.sh

gate:
name: CI gate
if: always()
needs: [verify, consumer-harness, workflow-lint]
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- name: Require every upstream job to succeed
run: |
echo "verify=${{ needs.verify.result }} consumer-harness=${{ needs.consumer-harness.result }} workflow-lint=${{ needs.workflow-lint.result }}"
[ "${{ needs.verify.result }}" = "success" ] && [ "${{ needs.consumer-harness.result }}" = "success" ] && [ "${{ needs.workflow-lint.result }}" = "success" ]
38 changes: 38 additions & 0 deletions .github/workflows/release-verification.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Release Artifact Verification

# Manual gate for a candidate release SHA and exact target version (CI Workflow Standard §2.5).
on:
workflow_dispatch:
inputs:
target:
description: 'Exact SemVer release target, e.g. 5.2.0 or 1.0.0-rc.1'
required: true
type: string

permissions:
contents: read

concurrency:
group: release-verification-${{ github.ref }}
cancel-in-progress: false

jobs:
verify-release-artifact:
name: Release Artifact Verification
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.5'
coverage: none
- name: Verify release artifact
env:
TARGET: ${{ inputs.target }}
run: |
set -euo pipefail
php scripts/verify-release-artifact.php "$TARGET" | tee verification.txt
{ echo '### Release Artifact Verification'; echo '```'; cat verification.txt; echo '```'; } >> "$GITHUB_STEP_SUMMARY"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor/
composer.lock
44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Changelog

## [Unreleased]

## [7.0.0]

### Changed (behaviour change)
- `sanitizeRequestUri()` also strips scheme, userinfo, host and port from absolute URLs and `//host/path` references (`https://user:pw@host/cb?x=1` is logged as `/cb`), and yields `''` for anything that is not an origin-form target or has an empty authority. Previously `//host/path` was logged as `/host/path`.
- Both backends now reject an unknown log level with `Psr\Log\InvalidArgumentException`; the file fallback previously accepted any string.
- Monolog log folders now receive the same `index.php` guard file as the fallback folders.
- `LoggerCleanupService` no longer follows or deletes symbolic links (previously a link inside the log directory could cause deletion of its target outside it).
- `LoggerCleanupService` no longer deletes `index.php` on age alone and removes a folder holding only an old guard file together with it.
- **Breaking:** `LoggerCleanupService` now defaults to the directory the logger writes to (`dirname(__DIR__, 4) . '/logs'`, the consumer project's `logs/`). Previously the default was `dirname(__DIR__, 2) . '/logs'`, which inside `vendor/` pointed at `vendor/maatify/logs` and cleaned nothing; callers relying on that default will now delete old files in the real log directory.
- File-fallback log entries now record only the **path** of `REQUEST_URI` (no query string, no fragment).
Signatures, tokens and one-time codes in query strings are no longer written to log files.
Anything parsing the `server.REQUEST_URI` field will no longer see the query string.
To restore the old behaviour, opt in explicitly with `Logger::logFullRequestUri(true)` (off by default).
- CLI (no `REQUEST_URI`) still writes an empty string.

### Added
- Redaction of secrets before anything is logged (Monolog and file-fallback paths):
- sensitive context keys (`password`, `token`, `secret`, `sig`, `authorization`, ...) are masked recursively;
- `key=value` secrets inside messages, exception messages and traces are scrubbed;
- `Logger::setSensitiveKeys([...])` replaces the key list, `Logger::setRedactor(callable)` adds a custom hook
that receives the full context. A throwing hook never breaks logging and never leaks the original context.
- Behaviour change: values under the default sensitive keys now appear as `***REDACTED***` in logs.
- Objects in the context are expanded and masked before reaching any backend (`JsonSerializable` output, `Stringable` string, public properties); a redaction hook's output is masked again. Object entries now log as `['class' => ..., 'properties' => ...]` instead of Monolog's own object rendering.
- `Throwable` objects placed anywhere in the context are converted to a scrubbed array (class, message, code, file, line, trace, previous) before reaching Monolog.
- `Authorization: Bearer/Basic <credentials>` values are redacted from free text.
- Redaction is depth-limited (8 levels), so circular or very deep contexts cannot exhaust memory.

### Removed
- The `version` field from `composer.json`; releases are identified by VCS tags.

### Documentation
- README rewritten to the Maatify presentation standard; added `LOGGER_PACKAGE_REFERENCE.md`, `docs/guides/USAGE_GUIDE.md`, `examples/`, `llms.txt`, `SECURITY.md`, `CODE_OF_CONDUCT.md` and `LICENSE` (proprietary, unchanged).
- Documented that with Monolog (the required backend) every entry goes to the `app_*.log` file; the per-call log file name routes files only in the file fallback.
- `composer.json` metadata: description, keywords and homepage now describe this package.

### CI and tooling
- GitHub Actions workflow (PHP 8.4/8.5 latest dependencies, PHP 8.4 lowest dependencies, workflow lint, stable `CI gate` job); actions pinned to commit SHAs, `contents: read` only.
- Composer scripts for every gate (`composer ci`), PHPStan level max without baseline, `CONTRIBUTING.md` mapping local commands to CI.
- **Breaking:** `require.php` is now `>=8.4.27 <8.5.0 || >=8.5.12 <8.6.0`. Previously no PHP constraint was declared (the code already required 8.3+ typed constants).
- `Logger::log()` now throws `Psr\Log\InvalidArgumentException` for a non-string or unknown level (previously an uncaught error from Monolog or `strtoupper`).
16 changes: 16 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Code of Conduct — maatify/logger

[![Maatify Logger](https://img.shields.io/badge/Maatify-Logger-blue?style=for-the-badge)](https://github.com/Maatify/Logger)
[![Maatify Ecosystem](https://img.shields.io/badge/Maatify-Ecosystem-9C27B0?style=for-the-badge)](https://github.com/Maatify)

## Participation

Take part respectfully and professionally. Make room for good-faith technical disagreement, discuss ideas and evidence, and address people with courtesy.

Harassment, discrimination, threats, doxing, intimidation, and abusive behavior are not acceptable.

These expectations apply to repository issues, pull requests, reviews, discussions, and official project channels.

## Reporting and moderation

Report conduct concerns privately to [support@maatify.dev](mailto:support@maatify.dev). Maintainers may moderate or remove content and restrict participation when necessary to protect the community.
53 changes: 53 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Contributing

## Package identity and boundaries

`maatify/logger` is a standalone PSR-3 logger package: logging, redaction of secrets and file output. Log shipping, rotation, retention and application-specific secret detection are out of scope. The supported contract is [LOGGER_PACKAGE_REFERENCE.md](LOGGER_PACKAGE_REFERENCE.md).

## Ways to contribute

Report bugs and propose changes through issues and pull requests. Discuss architecture-affecting changes (new public API, changed log format, changed redaction semantics, PHP constraint changes) in an issue before opening a pull request. Report vulnerabilities privately as described in [SECURITY.md](SECURITY.md), never in a public issue.

## Pull request expectations

- Work on a branch and open a pull request against `master`; do not push to `master`.
- Keep the change focused; update `CHANGELOG.md` under the right section and call out behavior changes.
- A fixed defect needs a test that detects its recurrence; show it failing before the fix when the defect can be reproduced safely.
- Observable behavior needs a system-level test through the public API (see `tests/EndToEndLoggingTest.php`).
- All gates below must pass; the `CI gate` job is the required check.

## Local verification commands and their CI mapping

Every CI step runs the same Composer script a developer can run locally (`composer ci` runs all of them except the workflow lint).

| Gate | Local command | CI step |
|---|---|---|
| Composer manifest | `composer validate:strict` | `composer validate --strict` |
| Platform requirements | `composer check:platform` | `composer check-platform-reqs` |
| PHP security patch floors | `composer check:php-floors` | same |
| PHP syntax | `composer lint:php` | same |
| Whitespace | `composer lint:whitespace` | same |
| PHPStan (level max, no baseline) | `composer analyse` | same |
| Tests | `composer test` | same |
| Consumer Verification Harness | `composer harness` | `consumer-harness` job |
| Examples smoke execution | `composer examples` | `consumer-harness` job |
| Composer audit | `composer audit:deps` | same |
| Workflow lint (actionlint 1.7.12) | `composer lint:workflows` | `workflow-lint` job |

CI (`.github/workflows/ci.yml`) runs PHP 8.4 and 8.5 with latest dependencies and PHP 8.4 with lowest dependencies, then a stable `CI gate` job that is the one to require in branch protection.

Prerequisites: PHP matching `require.php`, Composer 2, and `actionlint` (or Linux x86_64, where `scripts/lint-workflows.sh` downloads a checksum-verified copy). `composer check:php-floors` fails on an interpreter below the security patch floor; that is intentional.

`composer harness` and `composer examples` install a `git archive` of the committed tree (plus tracked working-tree edits; stage new files first; honours `.gitattributes` `export-ignore`) into a clean consumer project with `--no-dev` and production autoload. Locally, set `HARNESS_COMPOSER_FLAGS=--ignore-platform-req=php` if your PHP is below the patch floor (CI never does).

## Test and integration requirements

There is no database or service dependency, so no Integration infrastructure is needed. Unit tests are in `tests/`; the end-to-end test and the harness exercise the public API through a clean consumer root.

## `composer.lock` policy

`composer.lock` is not committed (reusable library); CI resolves dependencies with `composer update`.

## Release Artifact Verification

`composer release:verify <X>` (CI: the manual `Release Artifact Verification` workflow with the exact target) checks the archived tree of the candidate SHA for target `X`: manifest, required release-facing files, the undated `## [X]` CHANGELOG section, empty `[Unreleased]`, README install target, SECURITY identity badges, `llms.txt` structure and links, and archive contents. It prints the target, SHA and every check outcome, and fails closed. README and SECURITY wording still need the semantic review the standard requires.
16 changes: 16 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Proprietary License

Copyright (c) 2025 Maatify. All rights reserved.

This software and its associated documentation are proprietary to Maatify.

No rights or licenses are granted to use, copy, modify, merge, publish,
distribute, sublicense, sell, or otherwise transfer this software or any
substantial portion of it except under a separate written agreement or
with prior written permission from Maatify.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.

For licensing inquiries, contact Maatify through its official channels.
Loading