From eafa4aefbb589ca617817e24b188e5ee56b367a7 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 12 Jan 2025 18:51:27 +0100 Subject: [PATCH] Added log format --- RNS/__init__.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/RNS/__init__.py b/RNS/__init__.py index 5f5321b..68dfe32 100755 --- a/RNS/__init__.py +++ b/RNS/__init__.py @@ -24,6 +24,7 @@ import os import sys import glob import time +import datetime import random import threading @@ -68,6 +69,7 @@ logfile = None logdest = LOG_STDOUT logcall = None logtimefmt = "%Y-%m-%d %H:%M:%S" +logtimefmt_p = "%H:%M:%S.%f" compact_log_fmt = False instance_random = random.Random() @@ -108,14 +110,20 @@ def timestamp_str(time_s): timestamp = time.localtime(time_s) return time.strftime(logtimefmt, timestamp) -def log(msg, level=3, _override_destination = False): +def precise_timestamp_str(time_s): + return datetime.datetime.now().strftime(logtimefmt_p)[:-3] + +def log(msg, level=3, _override_destination = False, pt=False): global _always_override_destination, compact_log_fmt msg = str(msg) if loglevel >= level: - if not compact_log_fmt: - logstring = "["+timestamp_str(time.time())+"] ["+loglevelname(level)+"] "+msg + if pt: + logstring = "["+precise_timestamp_str(time.time())+"] ["+loglevelname(level)+"] "+msg else: - logstring = "["+timestamp_str(time.time())+"] "+msg + if not compact_log_fmt: + logstring = "["+timestamp_str(time.time())+"] ["+loglevelname(level)+"] "+msg + else: + logstring = "["+timestamp_str(time.time())+"] "+msg logging_lock.acquire()