Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Draw logging config from a dict. #102.

  • Loading branch information...
commit 9d55a79509a130e0ffe13a0f0a6786990232a422 1 parent c953b18
@ralphbean authored
View
27 fedmsg.d/logging.py
@@ -0,0 +1,27 @@
+# Setup fedmsg logging.
+# See the following for constraints on this format http://bit.ly/Xn1WDn
+config = dict(
+ logging=dict(
+ version=1,
+ formatters=dict(
+ bare={
+ "format": "%(message)s",
+ },
+ ),
+ handlers=dict(
+ console={
+ "class": "logging.StreamHandler",
+ "formatter": "bare",
+ "level": "INFO",
+ "stream": "ext://sys.stdout",
+ }
+ ),
+ loggers=dict(
+ fedmsg={
+ "level": "INFO",
+ "propagate": False,
+ "handlers": ["console"],
+ },
+ ),
+ ),
+)
View
20 fedmsg/commands/__init__.py
@@ -20,18 +20,14 @@
import fedmsg
import fedmsg.config
import warnings
-import logging
+import logging.config
import sys
+
class BaseCommand(object):
daemonizable = False
extra_args = None
- # TODO, move this to /etc/fedmsg.d/
- # Specifically, use dictConfig()
- log_level = logging.DEBUG
- log_format = "%(message)s"
-
def __init__(self):
if not self.extra_args:
self.extra_args = []
@@ -47,14 +43,8 @@ def __init__(self):
)
self.config = self.get_config()
-
- self.logger = logging.getLogger('fedmsg')
- self.logger.setLevel(self.log_level)
- formatter = logging.Formatter(self.log_format)
- console_log = logging.StreamHandler(sys.stdout)
- console_log.setLevel(self.log_level)
- console_log.setFormatter(formatter)
- self.logger.addHandler(console_log)
+ logging.config.dictConfig(self.config.get('logging', {}))
+ self.log = logging.getLogger("fedmsg")
def get_config(self):
return fedmsg.config.load_config(
@@ -173,7 +163,7 @@ def wrapper():
if self.daemonizable and config['daemon'] is True:
return self._daemonize(func, config)
else:
- logging.basicConfig()
+ logging.config.dictConfig(config.get('logging', {}))
try:
return func(**config)
except KeyboardInterrupt:
View
2  fedmsg/commands/tail.py
@@ -125,7 +125,7 @@ def formatter(d):
if not inclusive_regexp.search(topic):
continue
- self.logger.info("%s, %s, %s, %s" % (name, ep, topic, formatter(message)))
+ self.log.info("%s, %s, %s, %s" % (name, ep, topic, formatter(message)))
def tail():
command = TailCommand()
View
6 fedmsg/commands/tweet.py
@@ -83,7 +83,7 @@ def _post_to_api(api, message):
except Exception as e:
if 'Too many notices too fast;' in str(e):
# Cool our heels then try again.
- self.logger.info("Sleeping for %i", hibernate_duration)
+ self.log.info("Sleeping for %i", hibernate_duration)
time.sleep(hibernate_duration)
_post_to_api(api, message)
elif 'json decoding' in str(e):
@@ -106,10 +106,10 @@ def _post_to_api(api, message):
message = message[:140]
if not message:
- self.logger.info("Not tweeting blank message.")
+ self.log.info("Not tweeting blank message.")
continue
- self.logger.info("Tweeting %r" % message)
+ self.log.info("Tweeting %r" % message)
for api in apis:
_post_to_api(api, message)
Please sign in to comment.
Something went wrong with that request. Please try again.