mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-27 02:08:54 +00:00
Use logging instead of prints
This commit is contained in:
parent
c562f7750c
commit
8e1df7a364
1 changed files with 8 additions and 4 deletions
|
@ -6,11 +6,13 @@
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from .helpers import Error, ErrorWithTraceback
|
from .helpers import Error, ErrorWithTraceback
|
||||||
|
from .logger import create_logger
|
||||||
from .platform import process_alive, get_process_id
|
from .platform import process_alive, get_process_id
|
||||||
|
|
||||||
ADD, REMOVE = 'add', 'remove'
|
ADD, REMOVE = 'add', 'remove'
|
||||||
SHARED, EXCLUSIVE = 'shared', 'exclusive'
|
SHARED, EXCLUSIVE = 'shared', 'exclusive'
|
||||||
|
|
||||||
|
logger = create_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class TimeoutTimer:
|
class TimeoutTimer:
|
||||||
|
@ -173,16 +175,18 @@ def kill_stale_lock(self):
|
||||||
|
|
||||||
if not self.ok_to_kill_stale_locks:
|
if not self.ok_to_kill_stale_locks:
|
||||||
if not self.stale_warning_printed:
|
if not self.stale_warning_printed:
|
||||||
print(("Found stale lock %s, but not deleting because BORG_UNIQUE_HOSTNAME is not set." % name), file=sys.stderr)
|
# Log this at warning level to hint the user at the ability
|
||||||
|
logger.warning("Found stale lock %s, but not deleting because BORG_UNIQUE_HOSTNAME is not set.", name)
|
||||||
self.stale_warning_printed = True
|
self.stale_warning_printed = True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.unlink(os.path.join(self.path, name))
|
os.unlink(os.path.join(self.path, name))
|
||||||
print(("Killed stale lock %s." % name), file=sys.stderr)
|
logger.warning('Killed stale lock %s.', name)
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
if not self.stale_warning_printed:
|
if not self.stale_warning_printed:
|
||||||
print(("Found stale lock %s, but cannot delete due to %s" % (name, str(err))), file=sys.stderr)
|
# This error will bubble up and likely result in locking failure
|
||||||
|
logger.error('Found stale lock %s, but cannot delete due to %s', name, str(err))
|
||||||
self.stale_warning_printed = True
|
self.stale_warning_printed = True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -230,7 +234,7 @@ def load(self):
|
||||||
if not process_alive(host, pid, thread):
|
if not process_alive(host, pid, thread):
|
||||||
elements.add(tuple(e))
|
elements.add(tuple(e))
|
||||||
else:
|
else:
|
||||||
print(("Removed stale %s roster lock for pid %d." % (key, pid)), file=sys.stderr)
|
logger.warning('Removed stale %s roster lock for pid %d.', key, pid)
|
||||||
data[key] = list(list(e) for e in elements)
|
data[key] = list(list(e) for e in elements)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in a new issue