Skip to content
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

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 15 additions & 5 deletions beaver/utils.py
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Copy link
Member

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?

syslog_formatter = logging.Formatter('%(name).24s[%(process)d]: %(message)s')
Copy link
Member

Choose a reason for hiding this comment

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

Why aren't we respecting the formatter here?

Copy link
Author

Choose a reason for hiding this comment

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

    if formatter is None:
        formatter = logging.Formatter('[%(asctime)s] %(levelname)-7s %(message)s')

this format kinda sucks for syslog

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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,
this functions does too much magic (overriding handlers for instance in ex. ) even without my patches

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)
Expand All @@ -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')
Expand Down