Skip to content

Allow setting levels in Target constructor#128

Merged
samdark merged 11 commits intomasterfrom
copilot/add-target-levels-constructor
Dec 13, 2025
Merged

Allow setting levels in Target constructor#128
samdark merged 11 commits intomasterfrom
copilot/add-target-levels-constructor

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 5, 2025

Q A
Is bugfix?
New feature? ✔️
Breaks BC?
Fixed issues -

Description

Adds optional $levels parameter to Target::__construct() allowing log level filtering to be configured at instantiation rather than requiring a separate setLevels() call.

Changes

  • Target: Constructor accepts optional array $levels = [] parameter
  • StreamTarget/PsrTarget: Constructors forward $levels to parent
  • Tests: Added coverage for constructor-based level configuration
  • CHANGELOG.md: Added entry documenting the new feature

Usage

Before:

$target = new StreamTarget('php://stdout');
$target->setLevels([LogLevel::ERROR, LogLevel::WARNING]);

After:

$target = new StreamTarget('php://stdout', [LogLevel::ERROR, LogLevel::WARNING]);

Both approaches remain valid. Empty array (default) accepts all levels.

Original prompt

This section details on the original issue you should resolve

<issue_title>Allow to set levels in Target via constructor</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits December 5, 2025 06:27
Co-authored-by: samdark <47294+samdark@users.noreply.github.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.55%. Comparing base (9595587) to head (42b3c8a).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #128   +/-   ##
=========================================
  Coverage     99.55%   99.55%           
  Complexity      161      161           
=========================================
  Files            11       11           
  Lines           448      449    +1     
=========================================
+ Hits            446      447    +1     
  Misses            2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI changed the title [WIP] Allow setting levels in Target via constructor Allow setting levels in Target constructor Dec 5, 2025
Copilot AI requested a review from samdark December 5, 2025 06:34
@samdark
Copy link
Copy Markdown
Member

samdark commented Dec 6, 2025

@copilot add a line for changelog.

Co-authored-by: samdark <47294+samdark@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 6, 2025

@copilot add a line for changelog.

Added changelog entry in 17be2bf.

@samdark samdark marked this pull request as ready for review December 9, 2025 17:19
Copilot AI review requested due to automatic review settings December 9, 2025 17:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds the ability to set log level filtering directly in the Target constructor, simplifying configuration by eliminating the need for a separate setLevels() call after instantiation.

  • Adds optional $levels parameter to Target::__construct() and all concrete implementations
  • Maintains backward compatibility with default empty array accepting all log levels
  • Includes comprehensive test coverage for the new feature

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Target.php Added optional $levels parameter to constructor, calls setLevels() during initialization, improved PHPDoc
src/StreamTarget.php Updated constructor to accept and forward $levels parameter to parent
src/PsrTarget.php Updated constructor to accept and forward $levels parameter to parent
tests/TestAsset/DummyTarget.php Updated test fixture constructor to support $levels parameter
tests/TargetTest.php Added tests verifying level filtering via constructor with both specific levels and empty array
tests/StreamTargetTest.php Added test demonstrating level filtering in StreamTarget constructor
tests/PsrTargetTest.php Added test demonstrating level filtering in PsrTarget constructor
CHANGELOG.md Documented the new feature as entry #128 for version 2.1.2

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@samdark samdark requested a review from vjik December 9, 2025 17:51
Comment thread tests/TargetTest.php Outdated
Comment thread tests/TargetTest.php Outdated
samdark and others added 2 commits December 10, 2025 12:08
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
@samdark samdark merged commit ac45993 into master Dec 13, 2025
28 of 29 checks passed
@samdark samdark deleted the copilot/add-target-levels-constructor branch December 13, 2025 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to set levels in Target via constructor

5 participants