Skip to content

Allow setting levels in Target constructor#55

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

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

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 7, 2025

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

Adds $levels parameter to SyslogTarget constructor to match the base Target class API from yiisoft/log#128.

Changes:

  • Added optional array $levels = [] parameter to constructor, passed to parent::__construct()
  • Updated config/di.php to support optional levels parameter with safe fallback
  • Added test coverage for level filtering behavior
  • Updated CHANGELOG.md with entry for the new feature
  • Updated yiisoft/log requirement to ^2.2 to ensure compatibility with the new constructor signature

Usage:

use Psr\Log\LogLevel;
use Yiisoft\Log\Target\Syslog\SyslogTarget;

// Filter to only log errors and warnings
$target = new SyslogTarget(
    'app',
    LOG_ODELAY | LOG_PID,
    LOG_USER,
    [LogLevel::ERROR, LogLevel::WARNING]
);

Backward compatible - defaults to empty array (all levels). Users can optionally configure levels in their own params configuration.

Original prompt

This section details on the original issue you should resolve

<issue_title>Allow setting levels in Target constructor</issue_title>
<issue_description>### Proposed new feature or change

See yiisoft/log#128</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.

Co-authored-by: samdark <47294+samdark@users.noreply.github.com>
Copilot AI changed the title [WIP] Allow setting levels in Target constructor Allow setting levels in Target constructor Dec 7, 2025
Copilot AI requested a review from samdark December 7, 2025 07:53
@samdark
Copy link
Copy Markdown
Member

samdark commented Dec 7, 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 7, 2025

@copilot add a line for CHANGELOG.

Added in commit fdcc7dd

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

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 support for setting log levels directly in the SyslogTarget constructor, bringing it in line with the base Target class API from yiisoft/log#128. This allows developers to filter log levels at instantiation time rather than only through configuration.

Key changes:

  • Added optional $levels parameter to SyslogTarget constructor that passes to parent
  • Updated configuration examples to demonstrate the new levels parameter
  • Added comprehensive test coverage for level filtering functionality

Reviewed changes

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

Show a summary per file
File Description
src/SyslogTarget.php Added optional $levels parameter to constructor with proper documentation
tests/SyslogTargetTest.php Added test case testConstructorWithLevels() to verify level filtering behavior
config/params.php Added commented example showing how to configure levels in parameters
config/di.php Updated DI configuration to support optional levels parameter with fallback
README.md Enhanced documentation with $levels parameter description and usage example
CHANGELOG.md Added entry documenting the new feature

💡 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:52
Comment thread config/params.php Outdated
Comment thread README.md Outdated
Copy link
Copy Markdown
Member

@vjik vjik left a comment

Choose a reason for hiding this comment

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

Version yiisoft/log in composer.json should be updated after yiisoft/log release.

Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
Comment thread config/params.php
Co-authored-by: samdark <47294+samdark@users.noreply.github.com>
Copilot AI requested a review from samdark December 11, 2025 16:22
@samdark
Copy link
Copy Markdown
Member

samdark commented Dec 13, 2025

@copilot require yiisoft/log ^2.2

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

Copilot AI commented Dec 13, 2025

@copilot require yiisoft/log ^2.2

Updated in commit 7848e9b

Comment thread src/SyslogTarget.php Outdated
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
@samdark samdark merged commit 41c9777 into master Dec 13, 2025
26 checks passed
@samdark samdark deleted the copilot/add-target-levels-support branch December 13, 2025 17:14
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 setting levels in Target constructor

4 participants