-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 new SyslogHandler class #4
Conversation
usage example: $log = new Logger('application'); $syslog = new SyslogHandler('myfacility', 'local6'); $formatter = new LineFormatter("%channel%.%level_name%: %message% %extra%"); $syslog->setFormatter($formatter); $log->pushHandler($syslog);
throw new \UnexpectedValueException('unknown facility value "'.$facility.'" given'); | ||
} | ||
|
||
if (!openlog($ident, LOG_NDELAY|LOG_PID, $facility)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a good reason for adding LOG_NDELAY here? Sounds to me like you want to lazy-load that stuff in case nothing is worth logging.
You're probably right, using LOG_NDELAY doesn't bring any benefits. I initially suspected that I would be able to catch connection problems (missing unix domain socket of syslogd etc.) initially when setting up logging - but a look at the openlog(3) manpage reveals the profile of the real openlog() libc function: So - yes, you are right, LOG_NDELAY is really useless in this case. I'll update the pull request. |
to get a FALSE returned on connection problems isn't supported by the underlying POSIX API.
Thanks, I'll merge this later today then. |
Merged, just had to adjust some details for coding style & windows support, thanks again |
Since there is currently no syslog support in Monolog (and it even was on your todo list :-) ) here is a new SyslogHandler class.
A basic usage example:
The special formatter is needed since the timestamp is included automatically in all syslog messages.
The facility can be given using PHP constants (LOG_LOCAL5) or by string ('local5') to simplify setting the values from a configuration file.
I couldn't think of any unit test approaches for actually writing the message since mocking the syslog() function isn't possible and all tests using the real syslog() function would depend on a special syslogd configuration. So currently the unit tests only cover the constructor.