Skip to content
Merged
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
29 changes: 29 additions & 0 deletions openrelik_worker_common/logging.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
# WARNNING: This Logger class is deprecated, please use the Logger class in
# https://github.com/openrelik/openrelik-common/
import logging
import structlog
import os
import warnings

OPENRELIK_LOG_TYPE = "OPENRELIK_LOG_TYPE"

DEPRECATED = """WARNING: This Logger class is deprecated and will be removed, please use the Logger class in
https://github.com/openrelik/openrelik-common/"""

warnings.warn(
DEPRECATED,
DeprecationWarning,
stacklevel=2,
)


class Logger:
def __init__(self):
warnings.warn(
DEPRECATED,
DeprecationWarning,
stacklevel=2,
)

if os.environ.get(OPENRELIK_LOG_TYPE, "").startswith("structlog"):
base_processors = [
# Merge bind context variables
Expand Down Expand Up @@ -65,6 +83,12 @@ def get_logger(self, name="", wrap_logger=None, **kwargs):
"""
Returns a wrapper, structlog or plain python logger and binds key-value kwargs.
"""
warnings.warn(
DEPRECATED,
DeprecationWarning,
stacklevel=2,
)

if wrap_logger:
# This can be used to wrap e.g. the Celery logger in a structlog
self.logger = structlog.wrap_logger(wrap_logger)
Expand All @@ -81,5 +105,10 @@ def get_logger(self, name="", wrap_logger=None, **kwargs):
return self.logger

def bind(self, **kwargs):
warnings.warn(
DEPRECATED,
DeprecationWarning,
stacklevel=2,
)
if os.environ.get(OPENRELIK_LOG_TYPE, "").startswith("structlog"):
structlog.contextvars.bind_contextvars(**kwargs)