Skip to content

Why is includeStacktraces an option that cannot be set in constructor? #1603

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

Closed
rajyan opened this issue Oct 9, 2021 · 4 comments
Closed
Labels
Milestone

Comments

@rajyan
Copy link

rajyan commented Oct 9, 2021

Monolog version 2

Thank you for this great logging tool!

I wanted to ask,

Why is includeStacktraces an option that cannot be set in constructor in LineFormatter and JsonFormatter?

because we have to call includeStacktraces() to enable stacktrace, we need to create an custom formatter just to enable stacktrace in some frameworks.

ex.

note.

If includeStacktraces could be set in constructor, we don't need to create a custom formatter class for these usages and configure it in framework config files.

@rajyan rajyan added the Support label Oct 9, 2021
@juan-morales
Copy link
Contributor

Thanks to this issue I found that the code needs to be refactor (IMO). I Will create a PR sometime this Week End or next week... and let you know also

@juan-morales
Copy link
Contributor

I honestly dont see like a big benefit of adding this parameter in the constructor.

I am thinking that maybe, the method includeStacktraces can return self, so for the laravel code snippet could look like:

protected function formatter()
    {
        return (new LineFormatter(null, $this->dateFormat, true, true))->includeStacktraces();
    }

But still, dont see the benefit.

Also, in LineFormatter the constructor accepts parameters that are overwritten by calling method includeStacktraces() ... so, just adding this parameter in the constructor will not be semantically correct.

I would like to know someone else opinion on this one.

@Seldaek Seldaek added Feature and removed Support labels Mar 13, 2022
@Seldaek Seldaek added this to the 2.x milestone Mar 13, 2022
@Seldaek
Copy link
Owner

Seldaek commented Mar 13, 2022

I think it could be added. It would still implicitly force allowInlineLineBreaks to true in LineFormatter but that can be documented (and possibly throw if allowInlineLineBreaks=false is passed with includeStacktraces=true)

@rajyan
Copy link
Author

rajyan commented Mar 14, 2022

@Seldaek
Thanks for your response and fixes!

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.

3 participants