Moved full dump of requests+responses+events to log debug level.

Messages can be quite big and verbose, and they can anyway be subscribed
over Websockets.

Full dumps are anyway enabled when Platypush is started in verbose mode.

This commit replaces the dumps on INFO level with a quick summary
containing the message ID, request/event type and response time.
This commit is contained in:
Fabio Manganiello 2024-08-31 21:47:44 +02:00
parent 457333929f
commit 740e35bd5e
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
4 changed files with 36 additions and 11 deletions

View file

@ -365,7 +365,13 @@ class Application:
elif isinstance(msg, Response): elif isinstance(msg, Response):
msg.log() msg.log()
elif isinstance(msg, Event): elif isinstance(msg, Event):
msg.log() log.info(
'Received event: %s.%s[id=%s]',
msg.__class__.__module__,
msg.__class__.__name__,
msg.id,
)
msg.log(level=logging.DEBUG)
self.event_processor.process_event(msg) self.event_processor.process_event(msg)
return _f return _f

View file

@ -8,7 +8,7 @@ import logging
import inspect import inspect
import json import json
import time import time
from typing import Union from typing import Optional, Union
from uuid import UUID from uuid import UUID
_logger = logging.getLogger('platypush') _logger = logging.getLogger('platypush')
@ -114,18 +114,19 @@ class Message:
self._logger = _logger self._logger = _logger
self._default_log_prefix = '' self._default_log_prefix = ''
def log(self, prefix=''): def log(self, level: Optional[int] = None, prefix=''):
if self.logging_level is None: if self.logging_level is None:
return # Skip logging return # Skip logging
log_func = self._logger.info log_func = self._logger.info
if self.logging_level == logging.DEBUG: level = level if level is not None else self.logging_level
if level == logging.DEBUG:
log_func = self._logger.debug log_func = self._logger.debug
elif self.logging_level == logging.WARNING: elif level == logging.WARNING:
log_func = self._logger.warning log_func = self._logger.warning
elif self.logging_level == logging.ERROR: elif level == logging.ERROR:
log_func = self._logger.error log_func = self._logger.error
elif self.logging_level == logging.FATAL: elif level == logging.FATAL:
log_func = self._logger.fatal log_func = self._logger.fatal
if not prefix: if not prefix:

View file

@ -165,6 +165,11 @@ class Request(Message):
context_value = [*context_value] context_value = [*context_value]
if isinstance(context_value, datetime.date): if isinstance(context_value, datetime.date):
context_value = context_value.isoformat() context_value = context_value.isoformat()
except NameError as e:
logger.warning(
'Could not expand expression "%s": %s', inner_expr, e
)
context_value = expr
except Exception as e: except Exception as e:
logger.exception(e) logger.exception(e)
context_value = expr context_value = expr
@ -188,7 +193,13 @@ class Request(Message):
response.id = self.id response.id = self.id
response.target = self.origin response.target = self.origin
response.origin = Config.get('device_id') response.origin = Config.get('device_id')
response.log() self._logger.info(
'Sending response to request[id=%s, action=%s], response_time=%.02fs',
self.id,
self.action,
response.timestamp - self.timestamp,
)
response.log(level=logging.DEBUG)
if self.backend and self.origin: if self.backend and self.origin:
self.backend.send_response(response=response, request=self) self.backend.send_response(response=response, request=self)
@ -221,7 +232,10 @@ class Request(Message):
from platypush.plugins import RunnablePlugin from platypush.plugins import RunnablePlugin
response = None response = None
self.log() self._logger.info(
'Executing request[id=%s, action=%s]', self.id, self.action
)
self.log(level=logging.DEBUG)
try: try:
if self.action.startswith('procedure.'): if self.action.startswith('procedure.'):

View file

@ -1,6 +1,7 @@
import json import json
import logging import logging
import time import time
from typing import Optional
from platypush.message import Message from platypush.message import Message
@ -99,8 +100,11 @@ class Response(Message):
return json.dumps(response_dict, cls=self.Encoder) return json.dumps(response_dict, cls=self.Encoder)
def log(self, *args, **kwargs): def log(self, *args, level: Optional[int] = None, **kwargs):
self.logging_level = logging.WARNING if self.is_error() else logging.INFO if level is None:
level = logging.WARNING if self.is_error() else logging.INFO
kwargs['level'] = level
super().log(*args, **kwargs) super().log(*args, **kwargs)