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
4 changes: 2 additions & 2 deletions airbyte_cdk/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from airbyte_cdk.connector import TConfig
from airbyte_cdk.exception_handler import init_uncaught_exception_handler
from airbyte_cdk.logger import PRINT_BUFFER, init_logger
from airbyte_cdk.logger import PRINT_BUFFER, init_logger, is_platform_debug_log_enabled
from airbyte_cdk.models import (
AirbyteConnectionStatus,
AirbyteMessage,
Expand Down Expand Up @@ -158,7 +158,7 @@ def run(self, parsed_args: argparse.Namespace) -> Iterable[str]:
if not cmd:
raise Exception("No command passed")

if hasattr(parsed_args, "debug") and parsed_args.debug:
if (hasattr(parsed_args, "debug") and parsed_args.debug) or is_platform_debug_log_enabled():
self.logger.setLevel(logging.DEBUG)
logger.setLevel(logging.DEBUG)
self.logger.debug("Debug logs enabled")
Expand Down
24 changes: 21 additions & 3 deletions airbyte_cdk/logger.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#

import json
import logging
import logging.config
import os
from typing import Any, Callable, Mapping, Optional, Tuple

import orjson
Expand Down Expand Up @@ -40,6 +40,10 @@
}


def is_platform_debug_log_enabled() -> bool:
return os.environ.get("LOG_LEVEL", "info").lower() == "debug"


def init_logger(name: Optional[str] = None) -> logging.Logger:
"""Initial set up of logger"""
logger = logging.getLogger(name)
Expand Down Expand Up @@ -73,8 +77,22 @@ def format(self, record: logging.LogRecord) -> str:
airbyte_level = self.level_mapping.get(record.levelno, "INFO")
if airbyte_level == Level.DEBUG:
extras = self.extract_extra_args_from_record(record)
debug_dict = {"type": "DEBUG", "message": record.getMessage(), "data": extras}
return filter_secrets(json.dumps(debug_dict))
if is_platform_debug_log_enabled():
# We have a different behavior between debug logs enabled through `--debug` argument and debug logs
# enabled through environment variable. The reason is that for platform logs, we need to have these
# printed as AirbyteMessage which is not the case with the current previous implementation.
# Why not migrate both to AirbyteMessages then? AirbyteMessages do not support having structured logs.
# which means that the DX would be degraded compared to the current solution (devs will need to identify
# the `log.message` field and figure out where in this field is the response while the current solution
# have a specific field that is structured for extras.
message = f"{filter_secrets(record.getMessage())} ///\nExtra logs: {filter_secrets(json.dumps(extras))}"
log_message = AirbyteMessage(
type=Type.LOG, log=AirbyteLogMessage(level=airbyte_level, message=message)
)
return orjson.dumps(AirbyteMessageSerializer.dump(log_message)).decode()
else:
debug_dict = {"type": "DEBUG", "message": record.getMessage(), "data": extras}
return filter_secrets(json.dumps(debug_dict))
else:
message = super().format(record)
message = filter_secrets(message)
Expand Down
Loading