diff --git a/multiparser/parsing/tail.py b/multiparser/parsing/tail.py index a5b13d9..6fc88ef 100644 --- a/multiparser/parsing/tail.py +++ b/multiparser/parsing/tail.py @@ -54,10 +54,11 @@ def _wrapper(*args, file_content, **kwargs) -> TimeStampedData: raise RuntimeError("Failed to retrieve argument '__read_bytes'") if not (_input_file := kwargs.get("__input_file")): raise RuntimeError("Failed to retrieve argument '__input_file'") + _time_stamp = datetime.datetime.fromtimestamp( + timestamp=os.path.getmtime(_input_file), tz=datetime.timezone.utc + ) _meta_data: dict[str, str] = { - "timestamp": datetime.datetime.fromtimestamp( - os.path.getmtime(_input_file) - ).strftime("%Y-%m-%d %H:%M:%S.%f"), + "timestamp": f"{_time_stamp}", "hostname": platform.node(), "file_name": _input_file, "__read_bytes": kwargs["__read_bytes"], @@ -607,7 +608,7 @@ def record_log( __read_bytes=__read_bytes, tracked_values=tracked_values, convert=convert, - **parser_kwargs + **parser_kwargs, ) _data.append(_processed) # type: ignore _metadata = _metadata or _metadata_line diff --git a/multiparser/thread.py b/multiparser/thread.py index 5c867aa..6537bfb 100644 --- a/multiparser/thread.py +++ b/multiparser/thread.py @@ -315,7 +315,7 @@ def _append_thread( parser_func: typing.Callable | None = None, file_type: str | None = None, glob_expr: str | None = None, - **parser_kwargs + **parser_kwargs, ) -> None: """Create a new thread for a monitored file @@ -366,11 +366,11 @@ def _read_loop( _modified_time_stamp = os.path.getmtime(file_name) _modified_time = datetime.datetime.fromtimestamp( - _modified_time_stamp - ).strftime("%Y-%M-%d %H:%M:%S.%f") + timestamp=_modified_time_stamp, tz=datetime.timezone.utc + ) # If the file has not been modified then we do not need to parse it - if (_modified_time, file_name) in records: + if (f"{_modified_time}", file_name) in records: continue _cached_metadata = _reparse_action( file_type=file_type, @@ -382,11 +382,11 @@ def _read_loop( lock=self._lock, flatten_data=flatten_data, cached_metadata=_cached_metadata, - modified_time=_modified_time, + modified_time=f"{_modified_time}", **kwargs, ) - records.append((_modified_time, file_name)) + records.append((f"{_modified_time}", file_name)) # If only a single read is required terminate loop if static_read: