Skip to content

Commit 66d8c23

Browse files
authored
cwlprov: always add UTC timestamps (#920)
1 parent 8a6c493 commit 66d8c23

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

cwltool/main.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os
1212
import signal
1313
import sys
14+
import time
1415
from codecs import StreamWriter, getwriter # pylint: disable=unused-import
1516
from typing import (IO, Any, Callable, Dict, Iterable, List, Mapping,
1617
MutableMapping, MutableSequence, Optional, TextIO, Tuple,
@@ -551,8 +552,19 @@ def main(argsl=None, # type: List[str]
551552
runtimeContext.research_obj.folder, "log")
552553
prov_log_handler = logging.FileHandler(
553554
str(prov_log_handler_filename))
554-
if formatter:
555-
prov_log_handler.setFormatter(formatter)
555+
class ProvLogFormatter(logging.Formatter):
556+
"""Enforce ISO8601 with both T and Z."""
557+
def __init__(self): # type: () -> None
558+
super(ProvLogFormatter, self).__init__(
559+
"[%(asctime)sZ] %(message)s")
560+
561+
def formatTime(self, record, datefmt=None):
562+
# type: (logging.LogRecord, str) -> str
563+
record_time = time.gmtime(record.created)
564+
formatted_time = time.strftime("%Y-%m-%dT%H:%M:%S", record_time)
565+
with_msecs = "%s,%03d" % (formatted_time, record.msecs)
566+
return with_msecs
567+
prov_log_handler.setFormatter(ProvLogFormatter())
556568
_logger.addHandler(prov_log_handler)
557569

558570
if loadingContext is None:

0 commit comments

Comments
 (0)