Skip to content

Matomo application logs can now be written in syslog and errorlog #17764

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

Merged
merged 10 commits into from
Jul 18, 2021
Merged

Matomo application logs can now be written in syslog and errorlog #17764

merged 10 commits into from
Jul 18, 2021

Conversation

mwithheld
Copy link
Contributor

Description:

Issue #9400 Add log handlers syslog and errorlog; Add config for syslog ident; Document options.

Review

  • Functional review done
  • Potential edge cases thought about (behavior of the code with strange input, with strange internal state or possible interactions with other Matomo subsystems)
  • Usability review done (is anything maybe unclear or think about anything that would cause people to reach out to support)
  • Security review done see checklist
  • Code review done
  • Tests were added if useful/possible
  • Reviewed for breaking changes
  • Developer changelog updated if needed
  • Documentation added if needed
  • Existing documentation updated if needed

@mwithheld
Copy link
Contributor Author

This is an update to PR #17745

@@ -97,6 +99,13 @@
'Piwik\Plugins\Monolog\Handler\FileHandler' => DI\create()
->constructor(DI\get('log.file.filename'), DI\get('log.level.file'))
->method('setFormatter', DI\get('log.lineMessageFormatter.file')),

'\Monolog\Handler\ErrorLogHandler' => DI\create()
->constructor(null, DI\get('log.level.errorlog'))
Copy link
Member

Choose a reason for hiding this comment

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

Looking at the ErrorHandler constructor, it seems like this shouldn't be set to null. If you want to only set the level parameter, and use defaults for the rest, you can use:

->constructorParameter('level', DI\get('log.level.errorlog'))

Copy link
Contributor Author

@mwithheld mwithheld Jul 14, 2021

Choose a reason for hiding this comment

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

That is one nifty dependency injection system you've got going! So would it be like this?

   '\Monolog\Handler\ErrorLogHandler' => DI\create()
   ->constructorParameter('level', DI\get('log.level.errorlog'))
   ->method('setFormatter', DI\get('log.lineMessageFormatter.file')),

Thanks so much for the guidance dizzy!

Copy link
Member

Choose a reason for hiding this comment

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

@mwithheld yes, that looks correct! And yes it is definitely a nifty DI system! The library is called php-di and the creator, @/mnapoli, worked w/ us for a while so our integration works rather well.

@diosmosis
Copy link
Member

@mwithheld Thanks for fixing the issues! I left one other comment. After it's addressed it should be good to merge.

Avoid null in ErrorLogHandler constructor call: Use level param; default others
@mwithheld
Copy link
Contributor Author

Added commit 14992a8 ErrorLogHandler constructor: Avoid null

->method('setFormatter', DI\get('log.lineMessageFormatter.file')),

'\Monolog\Handler\SyslogHandler' => DI\create()
->constructor(DI\get('log.syslog.ident'), 'syslog', DI\get('log.level.syslog')),
Copy link
Member

Choose a reason for hiding this comment

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

Apologies for the back and forth, but one last question here: was it intentional not to use ->method('setFormatter', DI\get('log.lineMessageFormatter.file')) here?

@mwithheld
Copy link
Contributor Author

mwithheld commented Jul 16, 2021 via email

@diosmosis diosmosis added this to the 4.4.0 milestone Jul 18, 2021
@diosmosis diosmosis merged commit af97af6 into matomo-org:4.x-dev Jul 18, 2021
@diosmosis
Copy link
Member

@mwithheld I've merged the PR, thanks for going through the trouble of creating the PR and following up on it! The contribution is greatly appreciated.

@mattab
Copy link
Member

mattab commented Jul 26, 2021

@diosmosis could you please document this new capability in https://matomo.org/faq/troubleshooting/faq_115/ ? Thanks

@diosmosis
Copy link
Member

documented

@mattab mattab changed the title Add log handlers syslog and errorlog Matomo application logs can now be written in syslog and errorlog Jul 28, 2021
@mattab mattab added c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself. Easier debugging For issues that make troubleshooting issues for developers easier. labels Jul 28, 2021
->method('setFormatter', DI\get('log.lineMessageFormatter.file')),

'\Monolog\Handler\SyslogHandler' => DI\create()
->constructor(DI\get('log.syslog.ident'), 'syslog', DI\get('log.level.syslog'))
Copy link

Choose a reason for hiding this comment

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

Is this logging to the "syslog" facility? I would guess that "user" is most appropriate, but "syslog" is definitely not correct =)

(Discovered while trying to match on the facility and program name using syslog-ng.)

Lazy reference: https://en.wikipedia.org/wiki/Syslog#Facility

Copy link
Contributor Author

@mwithheld mwithheld Aug 3, 2021

Choose a reason for hiding this comment

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

You are correct this should be 'user'.
Should probably use

->constructorParameter('ident'=>DI\get('log.syslog.ident'))
->constructorParameter('level'=>DI\get('log.level.syslog'))

@mwithheld mwithheld deleted the patch-2 branch August 3, 2021 20:01
@mwithheld mwithheld restored the patch-2 branch August 3, 2021 20:18
@diosmosis
Copy link
Member

Hi @mwithheld, thanks for creating the change so quickly! Would you be able to put it in a new pull request? This one has already been merged so it's no longer useful to push here.

@orlitzky
Copy link

orlitzky commented Aug 3, 2021

Ok, thanks! And thanks for adding syslog support in the first place. Obviously, I was waiting for it =)

diosmosis added a commit that referenced this pull request Aug 24, 2021
* Add log handlers syslog and errorlog

Issue#9400

* Add log handlers syslog and errorlog

* syslog/errorlog: fix namespace; add log.syslog.ident

* syslog/errorlog: Document options

* ErrorLogHandler constructor: Avoid null

Avoid null in ErrorLogHandler constructor call: Use level param; default others

* missing comma

* fix two di definitions

* Use Monolog constructor-default facility

Issue #17764

* #17855 SyslogHandler: Fix typo

* Update plugins/Monolog/config/config.php

Co-authored-by: diosmosis <diosmosis@users.noreply.github.com>
Co-authored-by: root <root@127.0.0.1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself. Easier debugging For issues that make troubleshooting issues for developers easier.
Development

Successfully merging this pull request may close these issues.

4 participants