Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion flogging/flogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,17 @@ def format_datetime(dt: datetime.datetime):
return dt.strftime("%Y-%m-%dT%k:%M:%S.%f000") + tzstr


_pid: int = os.getpid()


def _change_pid():
global _pid
_pid = os.getpid()


def reduce_thread_id(thread_id: int) -> str:
"""Make a shorter thread identifier by hashing the original."""
return xxhash.xxh32(thread_id.to_bytes(8, "little")).hexdigest()[:4]
return xxhash.xxh32((thread_id ^ _pid).to_bytes(8, "little")).hexdigest()[:4]


def repr_array(arr: ndarray) -> str:
Expand Down Expand Up @@ -324,6 +332,8 @@ def ensure_utf8_stream(stream):
if not allow_trailing_dot:
handler.emit = check_trailing_dot(handler.emit)

os.register_at_fork(after_in_child=_change_pid)


def set_context(context):
"""Assign the logging context - an abstract object - to the current thread."""
Expand Down
Loading