Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Add syslog support#84

Merged
metachris merged 3 commits intometachris:masterfrom
brianlenz:syslog-logger
Mar 7, 2018
Merged

Add syslog support#84
metachris merged 3 commits intometachris:masterfrom
brianlenz:syslog-logger

Conversation

@brianlenz
Copy link

  • Adding syslog setup utility method so that you can easily use logzero to log directly to the syslog facility of your choice.

Still more to come for testing, adding documentation, and perhaps streamlining the implementation a bit.

* Adding syslog setup utility method so that you can easily use `logzero` to log directly to the `syslog` facility of your choice.

Still more to come for testing, adding documentation, and perhaps streamlining the implementation a bit.
logger.addHandler(rotating_filehandler)


def remove_internal_loggers(logger_to_update, disableStderrLogger=True):
Copy link
Owner

@metachris metachris Mar 5, 2018

Choose a reason for hiding this comment

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

perhaps add a default value like logger_to_update=logger? Like this it would raise an exception if no argument is passed for that.

Copy link
Author

Choose a reason for hiding this comment

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

How about we just make it private? I don't think this method should ever be used outside of logzero internals. I think the real, proper design would be to do what I described in Discord and make logzero loggers a class where this method would be a private class method, instead.

if isinstance(handler, RotatingFileHandler):
logger_to_update.removeHandler(handler)
elif isinstance(handler, logging.StreamHandler) and disableStderrLogger:
logger_to_update.removeHandler(handler)
Copy link
Owner

Choose a reason for hiding this comment

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

should this also remove the syslog handler?

Copy link
Author

Choose a reason for hiding this comment

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

Sure, that makes sense!

@metachris
Copy link
Owner

very nice, thanks! 2 small comments/questions.

logzero has grown from a tiny lib to a bit more. perhaps it's time to rethink the internal and custom logger setup and brainstorm on what could be good in a v2 ^^

Brian Lenz added 2 commits March 6, 2018 15:26
* A couple of improvements based on feedback from @metachris in code review.
* Added some documentation around logging to `syslog`.

* Added a primitive test of logging to syslog. No good way to capture syslog across all platforms, so only confirming that logging doesn't go to stdout or stderr currently.
@brianlenz
Copy link
Author

All of my changes are done here now, @metachris!

logger_to_update.removeHandler(handler)


def syslog(logger_to_update=logger, facility=SysLogHandler.LOG_USER, disableStderrLogger=True):
Copy link
Owner

Choose a reason for hiding this comment

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

I'd rather have disableStderrLogger default to False, as with the logfile setup. What do you think?

Copy link
Author

Choose a reason for hiding this comment

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

I think you can argue that this method shouldn't have a disableStderrLogger argument at all and should just remove every internal logger, as the name implies. It's purely an internal method, anyway. I left the param just for consistency, but I do think it makes sense that the default behavior is to remove every internal logger, as the name implies.

To be honest, I don't really care for the way that disableStderrLogger is passed all around (and I'm the one that added it 😂 ). It's a reflection of the fact that we need a Logger class that carries these properties internally. I almost went down the path of doing that redesign yesterday but opted for the quicker implementation for now.

Given that this is purely an internal, private method, I'm inclined to leave it pending the OO-redesign, but if you'd rather we invert it, I can do that, too. 👍

Copy link
Owner

Choose a reason for hiding this comment

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

Alright, good for me :)

But I think removing all other loggers would be a bit hard, sometimes people want file and syslog together? idk... but logfile(..) just adds the file logger, gues syslog(..) should behave the same?

Copy link
Author

Choose a reason for hiding this comment

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

This method is really only used when you're trying to setup a logger to work a specific way (e.g. with a log file or with syslog). I suppose someone may have a use case to do file and syslog together, but the current "flat" design doesn't readily support that. The problem is that there are usually default loggers added, but when I call the syslog method, I probably do not want those defaults (hence removing existing loggers first, just like the logfile method does).

If we refactored to an OO-design, then you will just define what loggers it should have via constructor args, and this method shouldn't generally be needed (except in the case where users are constantly changing around the default logger, but I don't know how common of a use case that is).

I think that trying to handle those types of multi-way logging scenarios with the current non-OO-design is going to make the code more complex, so my recommendation is we wait until the OO-design is in place and then we can support any arbitrary number of built-in loggers much more easily.

Thoughts?

Copy link
Owner

Choose a reason for hiding this comment

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

yeah, if we find the time we should move to a new design. hope we find the time, but there are so many priorities that i have the feeling it will be a while ^^

@metachris
Copy link
Owner

Thanks! Just a tiny thought, perhaps we leave it, but would like to hear your feedback on this.

@metachris metachris merged commit d261db6 into metachris:master Mar 7, 2018
@metachris
Copy link
Owner

new pypy build is on the way (v1.5.0)

@brianlenz brianlenz deleted the syslog-logger branch March 7, 2018 22:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants