-
Notifications
You must be signed in to change notification settings - Fork 172
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
ability to log to syslog not just files #221
Changes from 1 commit
7aac375
e8d7373
c313d00
550bea3
3ab2831
90a41e8
d8f2849
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,12 @@ | |
import glob2 | ||
import itertools | ||
import logging | ||
import logging.handlers | ||
import platform | ||
import re | ||
import os | ||
import sys | ||
from syslog import LOG_DAEMON | ||
|
||
import beaver | ||
|
||
|
@@ -70,14 +72,21 @@ def setup_custom_logger(name, args=None, output=None, formatter=None, debug=None | |
if output is None and has_args: | ||
output = args.output | ||
|
||
if output: | ||
if output and output != 'syslog': | ||
output = os.path.realpath(output) | ||
|
||
if output is not None: | ||
file_handler = logging.FileHandler(output) | ||
if formatter is not False: | ||
file_handler.setFormatter(formatter) | ||
logger.addHandler(file_handler) | ||
if output == 'syslog': | ||
syslog = logging.handlers.SysLogHandler('/dev/log', facility=LOG_DAEMON) | ||
syslog.setLevel(logging.INFO) | ||
syslog_formatter = logging.Formatter('%(name).24s[%(process)d]: %(message)s') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why aren't we respecting the formatter here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
this format kinda sucks for syslog There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's nonstandard behavior for beaver. If we want to change the defaults, fine, but this change makes it more difficult to reason about how it runs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok then all logging should be done in some stadart way by means ob logging.{conf/yml} whatever, |
||
syslog.setFormatter(syslog_formatter) | ||
logger.addHandler(syslog) | ||
else: | ||
file_handler = logging.FileHandler(output) | ||
if formatter is not False: | ||
file_handler.setFormatter(formatter) | ||
logger.addHandler(file_handler) | ||
|
||
if formatter is not False: | ||
handler.setFormatter(formatter) | ||
|
@@ -98,6 +107,7 @@ def setup_custom_logger(name, args=None, output=None, formatter=None, debug=None | |
return logger | ||
|
||
|
||
|
||
def version(args): | ||
if args.version: | ||
formatter = logging.Formatter('%(message)s') | ||
|
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.
what is this, indentation for ants?