Skip to content

Commit

Permalink
Timestamp header for the piped output logging fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
luav committed Aug 20, 2018
1 parent 07c0dc2 commit 864a7b1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mpepool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,11 +1145,11 @@ def complete(self, graceful=None):
os.makedirs(plog)
# Append to the file
flog = None
timestamp = None
try:
# Add a timestamp if the file is not empty to distinguish logs
timestamp = None
flog = plog if not isinstance(plog, str) else open(plog, 'a')
if os.fstat(flog.fileno()).st_size:
# Add a timestamp if the file is not empty to distinguish logs
if isinstance(plog, str) and os.fstat(flog.fileno()).st_size:
if timestamp is None:
timestamp = time.gmtime()
except IOError as err:
Expand All @@ -1160,7 +1160,8 @@ def complete(self, graceful=None):
if pout is self.pipedout:
flog = sys.stdout
try:
print(timeheader(timestamp), file=flog) # Note: prints also newline unlike flog.write()
if timestamp is not None:
print(timeheader(timestamp), file=flog) # Note: prints also newline unlike flog.write()
flog.write(pout) # Write the piped output
except IOError as err:
print('ERROR on logging piped data "{}" for "{}": {}'
Expand Down

0 comments on commit 864a7b1

Please sign in to comment.