summaryrefslogtreecommitdiffstats
path: root/src/lib/Logger.py
diff options
context:
space:
mode:
authorSol Jerome <solj@ices.utexas.edu>2009-04-23 16:33:20 +0000
committerSol Jerome <solj@ices.utexas.edu>2009-04-23 16:33:20 +0000
commit1a90ceb3e02e50a54bc0267571e0f4554201b579 (patch)
treeedd3944fe64408295901fc8b7c340d0c659fc627 /src/lib/Logger.py
parent4869aaf3a4cbf1034ff3c457c546aa82999fda65 (diff)
downloadbcfg2-1a90ceb3e02e50a54bc0267571e0f4554201b579.tar.gz
bcfg2-1a90ceb3e02e50a54bc0267571e0f4554201b579.tar.bz2
bcfg2-1a90ceb3e02e50a54bc0267571e0f4554201b579.zip
More python 2to3 updates along with pylint/code cleanups
Signed-off-by: Sol Jerome <solj@ices.utexas.edu> git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5173 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Logger.py')
-rw-r--r--src/lib/Logger.py31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/lib/Logger.py b/src/lib/Logger.py
index bb3c703a6..129d10314 100644
--- a/src/lib/Logger.py
+++ b/src/lib/Logger.py
@@ -1,13 +1,21 @@
'''Bcfg2 logging support'''
__revision__ = '$Revision$'
-import copy, fcntl, logging, logging.handlers, math, socket, struct, sys, termios, types
+import copy
+import fcntl
+import logging
+import logging.handlers
+import math
+import socket
+import struct
+import sys
+import termios
-logging.raiseExceptions=0
+logging.raiseExceptions = 0
def print_attributes(attrib):
''' Add the attributes for an element'''
- return ' '.join(['%s="%s"' % data for data in attrib.iteritems()])
+ return ' '.join(['%s="%s"' % data for data in list(attrib.items())])
def print_text(text):
''' Add text to the output (which will need normalising '''
@@ -54,15 +62,15 @@ class TermiosFormatter(logging.Formatter):
'''format a record for display'''
returns = []
line_len = self.width
- if type(record.msg) in types.StringTypes:
+ if isinstance(record.msg, str):
for line in record.msg.split('\n'):
if len(line) <= line_len:
returns.append(line)
else:
inner_lines = int(math.floor(float(len(line)) / line_len))+1
- for i in xrange(inner_lines):
+ for i in range(inner_lines):
returns.append("%s" % (line[i*line_len:(i+1)*line_len]))
- elif type(record.msg) == types.ListType:
+ elif isinstance(record.msg, list):
if not record.msg:
return ''
record.msg.sort()
@@ -70,7 +78,7 @@ class TermiosFormatter(logging.Formatter):
columnWidth = max([len(item) for item in record.msg])
columns = int(math.floor(float(msgwidth) / (columnWidth+2)))
lines = int(math.ceil(float(len(record.msg)) / columns))
- for lineNumber in xrange(lines):
+ for lineNumber in range(lines):
indices = [idx for idx in [(colNum * lines) + lineNumber
for colNum in range(columns)] if idx < len(record.msg)]
format = (len(indices) * (" %%-%ds " % columnWidth))
@@ -84,7 +92,10 @@ class TermiosFormatter(logging.Formatter):
return '\n'.join(returns)
class FragmentingSysLogHandler(logging.handlers.SysLogHandler):
- '''This handler fragments messages into chunks smaller than 250 characters'''
+ '''
+ This handler fragments messages into
+ chunks smaller than 250 characters
+ '''
def __init__(self, procname, path, facility):
self.procname = procname
@@ -116,7 +127,7 @@ class FragmentingSysLogHandler(logging.handlers.SysLogHandler):
except socket.error:
while True:
try:
- if isinstance(self.address, types.TupleType):
+ if isinstance(self.address, tuple):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
else:
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
@@ -150,7 +161,7 @@ def setup_logging(procname, to_console=True, to_syslog=True, syslog_facility='da
except socket.error:
logging.root.error("failed to activate syslogging")
except:
- print "Failed to activate syslogging"
+ print("Failed to activate syslogging")
if not to_file == None:
filelog = logging.FileHandler(to_file)
filelog.setLevel(logging.DEBUG)