aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorJordan Gong <jordan.gong@protonmail.com>2022-03-18 14:04:11 +0800
committerJordan Gong <jordan.gong@protonmail.com>2022-03-18 14:04:11 +0800
commitaab36ef9a62fa00e7b968de28d0a3e6a5698aebd (patch)
tree536d611e908f0fef926880d9fe160b474944a647 /libs
parent5bd0cba1084146c1afbde24cbdb665e88d139d35 (diff)
Prevent append CSV header when file pre-exists
Diffstat (limited to 'libs')
-rw-r--r--libs/utils.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/libs/utils.py b/libs/utils.py
index fde86eb..3df1574 100644
--- a/libs/utils.py
+++ b/libs/utils.py
@@ -7,12 +7,15 @@ BATCH_LOGGER = 'batch_logger'
class FileHandlerWithHeader(logging.FileHandler):
- def __init__(self, filename, header, mode='a', encoding=None, delay=0):
+ def __init__(self, filename, header, mode='a',
+ encoding=None, delay=False, errors=None):
self.header = header
self.file_pre_exists = os.path.exists(filename)
- logging.FileHandler.__init__(self, filename, mode, encoding, delay)
- if not delay and self.stream is not None:
+ super(FileHandlerWithHeader, self).__init__(
+ filename, mode, encoding, delay, errors
+ )
+ if not delay and self.stream is not None and not self.file_pre_exists:
self.stream.write(f'{header}\n')
def emit(self, record):