graphite-dev team mailing list archive
-
graphite-dev team
-
Mailing list archive
-
Message #01912
[Merge] lp:~sidnei/graphite/log-to-syslog into lp:graphite
Sidnei da Silva has proposed merging lp:~sidnei/graphite/log-to-syslog into lp:graphite.
Requested reviews:
graphite-dev (graphite-dev)
For more details, see:
https://code.launchpad.net/~sidnei/graphite/log-to-syslog/+merge/86276
If --syslog is passed to twistd, then log to syslog instead of logging to a directory or to stdout.
--
https://code.launchpad.net/~sidnei/graphite/log-to-syslog/+merge/86276
Your team graphite-dev is requested to review the proposed merge of lp:~sidnei/graphite/log-to-syslog into lp:graphite.
=== modified file 'carbon/lib/carbon/conf.py'
--- carbon/lib/carbon/conf.py 2011-12-03 08:12:58 +0000
+++ carbon/lib/carbon/conf.py 2011-12-19 18:05:27 +0000
@@ -206,12 +206,16 @@
self.handleAction()
# If we are not running in debug mode or non-daemon mode, then log to a
- # directory, otherwise log output will go to stdout.
- if not (self["debug"] or self.parent["nodaemon"]):
- logdir = settings.LOG_DIR
- if not isdir(logdir):
- os.makedirs(logdir)
- log.logToDir(logdir)
+ # directory, otherwise log output will go to stdout. If parent options
+ # are set to log to syslog, then use that instead.
+ if not self["debug"]:
+ if self.parent.get("syslog", None):
+ log.logToSyslog(self.parent["prefix"])
+ elif not self.parent["nodaemon"]:
+ logdir = settings.LOG_DIR
+ if not isdir(logdir):
+ os.makedirs(logdir)
+ log.logToDir(logdir)
def parseArgs(self, *action):
"""If an action was provided, store it for further processing."""
=== modified file 'carbon/lib/carbon/log.py'
--- carbon/lib/carbon/log.py 2011-10-05 05:15:51 +0000
+++ carbon/lib/carbon/log.py 2011-12-19 18:05:27 +0000
@@ -2,9 +2,9 @@
from sys import stdout, stderr
from zope.interface import implements
from twisted.python.log import startLoggingWithObserver, textFromEventDict, msg, err, ILogObserver
+from twisted.python.syslog import SyslogObserver
from twisted.python.logfile import DailyLogFile
-
class CarbonLogObserver(object):
implements(ILogObserver)
@@ -14,6 +14,13 @@
self.custom_logs = {}
self.observer = self.logdir_observer
+ def log_to_syslog(self, prefix):
+ observer = SyslogObserver(prefix).emit
+ def syslog_observer(event):
+ event["system"] = event.get("type", "console")
+ observer(event)
+ self.observer = syslog_observer
+
def __call__(self, event):
return self.observer(event)
@@ -43,18 +50,19 @@
event['isError'] = 'failure' in event
message = textFromEventDict(event)
- timestamp = time.strftime("%d/%m/%Y %H:%M:%S")
-
if includeType:
typeTag = '[%s] ' % event.get('type', 'console')
else:
typeTag = ''
+ timestamp = time.strftime("%d/%m/%Y %H:%M:%S")
return "%s :: %s%s" % (timestamp, typeTag, message)
logToDir = carbonLogObserver.log_to_dir
+logToSyslog = carbonLogObserver.log_to_syslog
+
def logToStdout():
startLoggingWithObserver(carbonLogObserver)