Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support json print in loginfo #1693

Merged
merged 1 commit into from
Jan 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions jina/drivers/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import time

from google.protobuf.json_format import MessageToJson

from . import BaseDriver
from .querylang.queryset.dunderkey import dunder_get
from ..excepts import UnknownControlCommand, RuntimeTerminated, NoExplicitMessage
Expand All @@ -22,17 +24,24 @@ def envelope(self) -> 'jina_pb2.EnvelopeProto':
class LogInfoDriver(BaseControlDriver):
"""Log output the request info"""

def __init__(self, key: str = 'request', *args, **kwargs):
def __init__(self, key: str = 'request', json: bool = True, *args, **kwargs):
"""
:param key: (str) that represents a first level or nested key in the dict
:param args:
:param kwargs:
"""
super().__init__(*args, **kwargs)
self.key = key
self.json = json

def __call__(self, *args, **kwargs):
self.logger.info(dunder_get(self.msg.as_pb_object, self.key))
data = dunder_get(self.msg.as_pb_object, self.key)
if self.json:
self.logger.info(
MessageToJson(data)
)
else:
self.logger.info(data)


class WaitDriver(BaseControlDriver):
Expand Down