Skip to content

Commit 194b939

Browse files
committed
If debug is enabled, also print logs to console
1 parent 4dd9854 commit 194b939

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

sentry_sdk/client.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import uuid
55
import random
66
import socket
7+
import logging
78
from collections.abc import Mapping
89
from datetime import datetime, timezone
910
from importlib import import_module
@@ -895,6 +896,21 @@ def capture_log(self, scope, severity_text, severity_number, template, **kwargs)
895896
"trace_id": None,
896897
} # type: Log
897898

899+
debug = self.options.get("debug", False)
900+
if debug:
901+
severity_text_to_logging_level = {
902+
"trace": logging.DEBUG,
903+
"debug": logging.DEBUG,
904+
"info": logging.INFO,
905+
"warn": logging.WARNING,
906+
"error": logging.ERROR,
907+
"fatal": logging.CRITICAL,
908+
}
909+
logger.log(
910+
severity_text_to_logging_level.get(severity_text, logging.DEBUG),
911+
f'[Sentry Logs] {log["body"]}',
912+
)
913+
898914
propagation_context = scope.get_active_propagation_context()
899915
if propagation_context is not None:
900916
headers["trace_id"] = propagation_context.trace_id

0 commit comments

Comments
 (0)