8000 Consider adding logging.handlers.LocalSysLogHandler · Issue #96339 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Consider adding logging.handlers.LocalSysLogHandler #96339

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

Open
ronaldoussoren opened this issue Aug 27, 2022 · 8 comments
Open

Consider adding logging.handlers.LocalSysLogHandler #96339

ronaldoussoren opened this issue Aug 27, 2022 · 8 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ronaldoussoren
Copy link
Contributor

Feature or enhancement

Add a handler to the logging package that uses syslog.syslog to log

Pitch

As mentioned in #91070 the logging.handlers.SysLogHandler cannot log to the local system log on recent versions of macOS. It is possible to log using syslog.syslog, I've checked that the code below results in a message in the system log:

syslog.syslog(syslog.LOG_WARNING|syslog.LOG_LOCAL7, "message from python")

Because of this it might be useful to define a LocalSysLogHander class that logs locally using the syslog module.

There is a design challenge here though: The syslog module (and libc function) has proces global configuration. This in particular affects the "ident" field which can only be set as proces global configuration. Another challenge is the interaction between the logging package handling of priorities and handling of those in syslog(3).

@ronaldoussoren ronaldoussoren added the type-feature A feature request or enhancement label Aug 27, 2022
@AlexWaygood AlexWaygood added the stdlib Python modules in the Lib dir label Aug 27, 2022
@vsajip
Copy link
Member
vsajip commented Aug 27, 2022

Isn't there also a potential thread-safety issue in how the syslog module works? I seem to remember that was an issue, when last I looked at it.

@ronaldoussoren
Copy link
Contributor Author

Not as far as I know. Syslog(3) should be thread safe (according to POSIX), and the code in Modules/syslog.c looks fine to me.

It is possible to introduce threading issues by emulating to much of SysLogHandler because of the process global configuration of syslog(3). It's probably best to not have a configuration option for setting the "ident", but let users set this value through the syslog module if they need to change it, and likewise for the syslog options (like LOG_NDELAY). E.g., don't call syslog.openlog in the logging handler.

@vsajip
Copy link
Member
vsajip commented Aug 27, 2022

How about adding it as a separate project on PyPI, rather than adding to the stdlib now? It's only really for users of new macOS versions.

@ronaldoussoren
Copy link
Contributor Author

Why not add it to the stdlib? That way we can tell users to use the new handler to log locally. "Users of new macOS versions" will be "everyone on macOS that want to log to the system logs" in a couple of years. I can create a PR for this.

Alternatively update the SysLogHandler to use the syslog module when instantiated using the default log target, but that could lead to subtle behaviour changes and would unnecessarily complicate the implementation.

@vsajip
Copy link
Member
vsajip commented Aug 28, 2022

My main concern is that I don't use macOS, don't have access to a macOS machine and so might have difficulty supporting this addition.

@vsajip
Copy link
Member
vsajip commented Aug 29, 2022

Perhaps you could add this suggestion to the "Core development" category on Discourse? I'd like to get other core devs' opinions on this, too.

@ronaldoussoren
Copy link
Contributor Author

My main concern is that I don't use macOS, don't have access to a macOS machine and so might have difficulty supporting this addition.

This is not a macOS specific feature, the handler would work on every system supported by the syslog module, which is basically any unix-y system including Linux.

Perhaps you could add this suggestion to the "Core development" category on Discourse? I'd like to get other core devs' opinions on this, too.

I'll do that over the weekend.

@ronaldoussoren
Copy link
Contributor Author

I finally got around to posting about this: https://discuss.python.org/t/logging-hander-using-the-syslog-module/18993.

Sorry about the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
Status: No status
Development

No branches or pull requests

3 participants
0