Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions logging_loki/emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import threading
import time
from logging.config import ConvertingDict
from typing import Any, Callable, Dict, Optional, Tuple
from typing import Any, Callable, Dict, Optional, Tuple, Union

import requests

Expand Down Expand Up @@ -45,7 +45,8 @@ def __init__(self,
as_json: bool = False,
props_to_labels: Optional[list[str]] = None,
level_tag: Optional[str] = const.level_tag,
logger_tag: Optional[str] = const.logger_tag
logger_tag: Optional[str] = const.logger_tag,
verify: Union[bool, str] = True
):
"""
Create new Loki emitter.
Expand All @@ -72,6 +73,8 @@ def __init__(self,
self.level_tag: str = level_tag
#: Label name indicating logger name.
self.logger_tag: str = logger_tag
# verify param to be past to requests, can be a bool (to enable/disable SSL verification) or a path to a CA bundle
self.verify = verify

self._session: Optional[requests.Session] = None
self._lock = threading.Lock()
Expand All @@ -95,6 +98,7 @@ def session(self) -> requests.Session:
if self._session is None:
self._session = self.session_class()
self._session.auth = self.auth or None
self._session.verify = self.verify
return self._session

def close(self):
Expand Down
6 changes: 4 additions & 2 deletions logging_loki/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def __init__(
as_json: Optional[bool] = False,
props_to_labels: Optional[list[str]] = None,
level_tag: Optional[str] = const.level_tag,
logger_tag: Optional[str] = const.logger_tag
logger_tag: Optional[str] = const.logger_tag,
verify: Union[bool, str] = True
):
"""
Create new Loki logging handler.
Expand All @@ -84,10 +85,11 @@ def __init__(
props_to_labels: List of properties that should be converted to loki labels.
level_tag: Label name indicating logging level.
logger_tag: Label name indicating logger name.
verify: Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use.

"""
super().__init__()
self.emitter = LokiEmitter(url, tags, headers, auth, as_json, props_to_labels, level_tag, logger_tag)
self.emitter = LokiEmitter(url, tags, headers, auth, as_json, props_to_labels, level_tag, logger_tag, verify)

def handleError(self, exc: Exception): # noqa: N802
"""Close emitter and let default handler take actions on error."""
Expand Down