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
3 changes: 3 additions & 0 deletions cloudquery/sdk/plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def __init__(self, name: str, version: str) -> None:
def init(self, spec: bytes) -> None:
pass

def set_logger(self, logger) -> None:
pass

def name(self) -> str:
return self._name

Expand Down
2 changes: 2 additions & 0 deletions cloudquery/sdk/scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def __init__(
self._max_depth = max_depth
if logger is None:
self._logger = structlog.get_logger()
else:
self._logger = logger
if concurrency <= 0:
raise ValueError("concurrency must be greater than 0")
if max_depth <= 0:
Expand Down
47 changes: 46 additions & 1 deletion cloudquery/sdk/serve/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import grpc
import structlog
import sys
import os

from cloudquery.discovery_v1 import discovery_pb2_grpc
from cloudquery.plugin_v3 import plugin_pb2_grpc

Expand All @@ -15,8 +17,50 @@
DOC_FORMATS = ["json", "markdown"]


_IS_WINDOWS = sys.platform == "win32"

try:
import colorama
except ImportError:
colorama = None

if _IS_WINDOWS: # pragma: no cover
# On Windows, use colors by default only if Colorama is installed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add colorama to the dependencies?

_has_colors = colorama is not None
else:
# On other OSes, use colors by default.
_has_colors = True


def get_logger(args):
log = structlog.get_logger(processors=[structlog.processors.JSONRenderer()])
processors = [
structlog.contextvars.merge_contextvars,
structlog.processors.add_log_level,
structlog.processors.StackInfoRenderer(),
structlog.dev.set_exc_info,
structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S", utc=False),
]
if args.log_format == "text":
processors.append(
structlog.dev.ConsoleRenderer(
colors=os.environ.get("NO_COLOR", "") == ""
and (
os.environ.get("FORCE_COLOR", "") != ""
or (
_has_colors
and sys.stdout is not None
and hasattr(sys.stdout, "isatty")
and sys.stdout.isatty()
)
)
)
)
else:
processors.append(structlog.processors.JSONRenderer())

# if args.log_format == "json":
# processors.append(structlog.processors.JSONRenderer())
log = structlog.get_logger(processors=processors)
return log


Expand Down Expand Up @@ -87,6 +131,7 @@ def run(self, args):

def _serve(self, args):
logger = get_logger(args)
self._plugin.set_logger(logger)
self._server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
discovery_pb2_grpc.add_DiscoveryServicer_to_server(
DiscoveryServicer([3]), self._server
Expand Down