Skip to content

Commit f1504ad

Browse files
author
Aleksander Błaszkiewicz
committed
fix: make logger non-blocking
1 parent 1efd872 commit f1504ad

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

logdash/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
from logdash.metrics import MetricOperation
44

55
__all__ = ["create_logdash", "Logger", "MetricOperation"]
6-
__version__ = "1.0.9"
6+
__version__ = "1.1.0"

logdash/core.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import threading
12
from datetime import datetime, timezone
23
from typing import Dict, Optional, Any
34

@@ -21,8 +22,12 @@ def __init__(self, api_key: Optional[str] = None, host: str = "https://api.logda
2122

2223
# Initialize logger
2324
def on_log(level: LogLevel, message: str) -> None:
24-
self._log_sync.send(message, level, datetime.now(timezone.utc).isoformat().replace('+00:00', 'Z')
25-
)
25+
# Send log in background thread to avoid blocking
26+
def send_log():
27+
self._log_sync.send(message, level, datetime.now(timezone.utc).isoformat().replace('+00:00', 'Z'))
28+
29+
thread = threading.Thread(target=send_log, daemon=True)
30+
thread.start()
2631

2732
self._logger_instance = Logger(log_method=print, on_log=on_log)
2833

0 commit comments

Comments
 (0)