Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to handle formatted message in PsrHandler #1070

Closed
shouze opened this issue Oct 30, 2017 · 3 comments
Closed

Add ability to handle formatted message in PsrHandler #1070

shouze opened this issue Oct 30, 2017 · 3 comments
Labels
Milestone

Comments

@shouze
Copy link

shouze commented Oct 30, 2017

This is just a proposal, I own this implementation inside of one of my own projects repo but maybe it would be useful for some other people? WDYT? Is it the way it should be implemented?

class PsrHandler extends AbstractProcessingHandler
{
    protected $logger;
    public function __construct(LoggerInterface $logger, $level = Logger::DEBUG, $bubble = true)
    {
        parent::__construct($level, $bubble);
        $this->logger = $logger;
    }
    public function write(array $record)
    {
        if (!$this->isHandling($record)) {
            return false;
        }

        $message = isset($record['formatted']) ? $record['formatted'] : $record['message'];

        $this->logger->log(strtolower($record['level_name']), $message, $record['context']);

        return false === $this->bubble;
    }
}
@shouze shouze changed the title Add ability to pass formatted message in PsrHandler Add ability to pass handle message in PsrHandler Oct 30, 2017
@shouze shouze changed the title Add ability to pass handle message in PsrHandler Add ability to handle formatted message in PsrHandler Oct 30, 2017
@Seldaek
Copy link
Owner

Seldaek commented Jun 7, 2018

Seems fine to me but I think this should be a 2.0 feature only as it can introduce some breakage. The question though is what should the default be? Should it format by default or rather pass-through by default but if you configure a formatter then it uses it to format?

@Seldaek Seldaek added this to the 2.0 milestone Jun 7, 2018
@Seldaek Seldaek added the Feature label Jun 7, 2018
@shouze
Copy link
Author

shouze commented Jun 18, 2018

Seems fine to me but I think this should be a 2.0 feature only as it can introduce some breakage. The question though is what should the default be?

👍 for 2.0 of course. Should use the formatted message (if a formatted is configured of course) by default I guess, no?

Should it format by default or rather pass-through by default but if you configure a formatter then it uses it to format?

Yes, only if you configure a formatter.

@Seldaek
Copy link
Owner

Seldaek commented Jun 18, 2018

Ok then I guess go for a PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants