Skip to content

Commit

Permalink
Better defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
cybergrind committed Feb 9, 2018
1 parent 7f38aa6 commit 6dc54e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions safe_logger/__init__.py
Expand Up @@ -6,6 +6,8 @@


class TimedRotatingFileHandlerSafe(logging.handlers.TimedRotatingFileHandler):
def __init__(filename, when='midnight', backupCount=30, **kwargs):
super().__init__(filename, when=when, backupCount=backupCount, **kwargs)

def _open(self):
if getattr(self, '_lockf', None) and not self._lockf.closed:
Expand All @@ -20,8 +22,12 @@ def _open(self):
self._release_lock()

def _aquire_lock(self):
self._lockf = open(self.baseFilename + '_rotating_lock', 'a')
fcntl.flock(self._lockf,fcntl.LOCK_EX|fcntl.LOCK_NB)
try:
self._lockf = open(self.baseFilename + '_rotating_lock', 'a')
except PermissionError:
name = './{}_rotating_lock'.format(os.path.basename(self.baseFilename))
self._lockf = open(name, 'a')
fcntl.flock(self._lockf, fcntl.LOCK_EX | fcntl.LOCK_NB)

def _release_lock(self):
self._lockf.close()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
@@ -1,6 +1,6 @@
from setuptools import find_packages, setup

version = '1.1.0'
version = '1.2.0'

setup(name='safe_logger',
version=version,
Expand Down

0 comments on commit 6dc54e0

Please sign in to comment.