summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Logger.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-25 11:49:15 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-25 11:58:48 -0400
commiteac71fc1109f2edc6b71e62a6cff38d762bebe63 (patch)
tree203cf372e31b92dfc0cf7ea57c451c44e5e1e54b /src/lib/Bcfg2/Logger.py
parent3f16355e18cdceb37828a00a8181d9cc60815cd0 (diff)
downloadbcfg2-eac71fc1109f2edc6b71e62a6cff38d762bebe63.tar.gz
bcfg2-eac71fc1109f2edc6b71e62a6cff38d762bebe63.tar.bz2
bcfg2-eac71fc1109f2edc6b71e62a6cff38d762bebe63.zip
expanded pylint coverage
Diffstat (limited to 'src/lib/Bcfg2/Logger.py')
-rw-r--r--src/lib/Bcfg2/Logger.py40
1 files changed, 24 insertions, 16 deletions
diff --git a/src/lib/Bcfg2/Logger.py b/src/lib/Bcfg2/Logger.py
index 1f4ba7dd0..06379ce7b 100644
--- a/src/lib/Bcfg2/Logger.py
+++ b/src/lib/Bcfg2/Logger.py
@@ -29,7 +29,7 @@ class TermiosFormatter(logging.Formatter):
"\000" * 8))[1]
if self.width == 0:
self.width = 80
- except:
+ except: # pylint: disable=W0702
self.width = 80
else:
# output to a pipe
@@ -44,22 +44,24 @@ class TermiosFormatter(logging.Formatter):
if len(line) <= line_len:
returns.append(line)
else:
- inner_lines = int(math.floor(float(len(line)) / line_len)) + 1
- for i in range(inner_lines):
- returns.append("%s" % (line[i * line_len:(i + 1) * line_len]))
+ inner_lines = \
+ int(math.floor(float(len(line)) / line_len)) + 1
+ for msgline in range(inner_lines):
+ returns.append(
+ line[msgline * line_len:(msgline + 1) * line_len])
elif isinstance(record.msg, list):
if not record.msg:
return ''
record.msg.sort()
msgwidth = self.width
- columnWidth = max([len(item) for item in record.msg])
- columns = int(math.floor(float(msgwidth) / (columnWidth + 2)))
+ col_width = max([len(item) for item in record.msg])
+ columns = int(math.floor(float(msgwidth) / (col_width + 2)))
lines = int(math.ceil(float(len(record.msg)) / columns))
- for lineNumber in range(lines):
- indices = [idx for idx in [(colNum * lines) + lineNumber
+ for lineno in range(lines):
+ indices = [idx for idx in [(colNum * lines) + lineno
for colNum in range(columns)]
if idx < len(record.msg)]
- retformat = (len(indices) * (" %%-%ds " % columnWidth))
+ retformat = (len(indices) * (" %%-%ds " % col_width))
returns.append(retformat % tuple([record.msg[idx]
for idx in indices]))
else:
@@ -99,13 +101,13 @@ class FragmentingSysLogHandler(logging.handlers.SysLogHandler):
else:
msgs = [record]
for newrec in msgs:
- msg = '<%d>%s\000' % (self.encodePriority(self.facility,
- newrec.levelname.lower()),
- self.format(newrec))
+ msg = '<%d>%s\000' % \
+ (self.encodePriority(self.facility, newrec.levelname.lower()),
+ self.format(newrec))
try:
self.socket.send(msg.encode('ascii'))
except socket.error:
- for i in range(10):
+ for i in range(10): # pylint: disable=W0612
try:
if isinstance(self.address, tuple):
self.socket = socket.socket(socket.AF_INET,
@@ -124,12 +126,13 @@ class FragmentingSysLogHandler(logging.handlers.SysLogHandler):
logging.WARNING),
self.format(reconn)))
self.socket.send(msg)
- except:
+ except: # pylint: disable=W0702
# If we still fail then drop it. Running
# bcfg2-server as non-root can trigger permission
# denied exceptions.
pass
+
def add_console_handler(level=logging.DEBUG):
"""Add a logging handler that logs at a level to sys.stdout."""
console = logging.StreamHandler(sys.stdout)
@@ -138,6 +141,7 @@ def add_console_handler(level=logging.DEBUG):
console.setFormatter(TermiosFormatter())
logging.root.addHandler(console)
+
def add_syslog_handler(procname, syslog_facility, level=logging.DEBUG):
"""Add a logging handler that logs as procname to syslog_facility."""
try:
@@ -150,20 +154,24 @@ def add_syslog_handler(procname, syslog_facility, level=logging.DEBUG):
('localhost', 514),
syslog_facility)
syslog.setLevel(level)
- syslog.setFormatter(logging.Formatter('%(name)s[%(process)d]: %(message)s'))
+ syslog.setFormatter(
+ logging.Formatter('%(name)s[%(process)d]: %(message)s'))
logging.root.addHandler(syslog)
except socket.error:
logging.root.error("failed to activate syslogging")
except:
print("Failed to activate syslogging")
+
def add_file_handler(to_file, level=logging.DEBUG):
"""Add a logging handler that logs to to_file."""
filelog = logging.FileHandler(to_file)
filelog.setLevel(level)
- filelog.setFormatter(logging.Formatter('%(asctime)s %(name)s[%(process)d]: %(message)s'))
+ filelog.setFormatter(
+ logging.Formatter('%(asctime)s %(name)s[%(process)d]: %(message)s'))
logging.root.addHandler(filelog)
+
def setup_logging(procname, to_console=True, to_syslog=True,
syslog_facility='daemon', level=0, to_file=None):
"""Setup logging for Bcfg2 software."""