Skip to content

Commit

Permalink
Port sugar3.logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Pro-Panda committed Mar 2, 2018
1 parent 0d51c75 commit 743742d
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/sugar3/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@
STABLE.
"""

import six
import array
import collections
import errno
import logging
import sys
import os
import repr as repr_
import decorator
import time

if six.PY3:
import reprlib as repr_
else:
import repr as repr_
from sugar3 import env

# Let's keep this module self contained so that it can be easily
Expand Down Expand Up @@ -104,8 +108,8 @@ def cleanup():
for f in os.listdir(root):
os.remove(os.path.join(root, f))
os.rmdir(root)
except OSError, e:
print "Could not remove old logs files %s" % e
except OSError as e:
print("Could not remove old logs files %s" % e)

if len(backup_logs) > 0:
name = str(int(time.time()))
Expand All @@ -116,7 +120,7 @@ def cleanup():
source_path = os.path.join(logs_dir, log)
dest_path = os.path.join(backup_dir, log)
os.rename(source_path, dest_path)
except OSError, e:
except OSError as e:
# gracefully deal w/ disk full
if e.errno != errno.ENOSPC:
raise e
Expand Down Expand Up @@ -145,15 +149,15 @@ def __init__(self, stream):
def write(self, s):
try:
self._stream.write(s)
except IOError, e:
except IOError as e:
# gracefully deal w/ disk full
if e.errno != errno.ENOSPC:
raise e

def flush(self):
try:
self._stream.flush()
except IOError, e:
except IOError as e:
# gracefully deal w/ disk full
if e.errno != errno.ENOSPC:
raise e
Expand All @@ -177,7 +181,7 @@ def flush(self):

sys.stdout = SafeLogWrapper(sys.stdout)
sys.stderr = SafeLogWrapper(sys.stderr)
except OSError, e:
except OSError as e:
# if we're out of space, just continue
if e.errno != errno.ENOSPC:
raise e
Expand All @@ -188,8 +192,10 @@ def flush(self):
class TraceRepr(repr_.Repr):

# better handling of subclasses of basic types, e.g. for DBus
_TYPES = [int, long, bool, tuple, list, array.array, set, frozenset,
_TYPES = [int, bool, tuple, list, array.array, set, frozenset,
collections.deque, dict, str]
if six.PY2:
_TYPES.append(long)

def repr1(self, x, level):
for t in self._TYPES:
Expand Down

0 comments on commit 743742d

Please sign in to comment.