Skip to content

Commit 82809b7

Browse files
committed
cleanup + better image
1 parent 328b136 commit 82809b7

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed
159 KB
Loading

telegram_logger_client/_logging_handler.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,26 @@
99

1010

1111
class TelegramLoggerHandler(logging.Handler):
12-
def __init__(self, base_url: str, x_id: str, *args, **kwargs):
12+
def __init__(
13+
self,
14+
base_url: str,
15+
x_id: str,
16+
show_originating_file: bool = False,
17+
*args,
18+
**kwargs,
19+
):
1320
super(TelegramLoggerHandler, self).__init__(*args, **kwargs)
1421
self.client = TelegramLoggerClient(base_url, x_id)
22+
self.show_originating_file = show_originating_file
1523

1624
def emit(self, record):
1725
try:
1826
message = record.getMessage()
19-
data = {
20-
"file": f"{record.pathname}:{record.lineno}",
21-
}
27+
28+
data = {}
29+
if self.show_originating_file:
30+
data["file"] = f"{record.pathname}:{record.lineno}"
31+
2232
if record.exc_info:
2333
data["exception"] = self.formatter.formatException(record.exc_info)
2434

@@ -47,6 +57,7 @@ def attach_to_logger(
4757
base_url: Optional[str] = None,
4858
x_id: Optional[str] = None,
4959
level: Optional[int] = None,
60+
show_originating_file: bool = False,
5061
):
5162
"""
5263
Set up Telegram logging for an existing logger instance.
@@ -63,7 +74,7 @@ def attach_to_logger(
6374
"Both base_url and x_id must be provided either as arguments or through environment variables."
6475
)
6576

66-
telegram_handler = TelegramLoggerHandler(base_url, x_id)
77+
telegram_handler = TelegramLoggerHandler(base_url, x_id, show_originating_file)
6778
telegram_handler.setFormatter(TelegramLogFormatter())
6879

6980
if level is not None:

0 commit comments

Comments
 (0)