risotto/src/risotto/logger.py

48 lines
1.5 KiB
Python
Raw Normal View History

2019-11-28 16:51:56 +01:00
from typing import Dict
from .context import Context
2019-11-28 14:50:53 +01:00
from .utils import _
class Logger:
2019-11-28 16:51:56 +01:00
""" An object to manager log
FIXME should add event to a database
"""
def _get_message_paths(self,
risotto_context: Context,
type: str):
2019-11-28 14:50:53 +01:00
paths = risotto_context.paths
if len(paths) == 1:
2019-11-28 16:51:56 +01:00
paths_msg = f'messages {type}ed: {paths[0]}'
2019-11-28 14:50:53 +01:00
else:
2019-11-28 16:51:56 +01:00
paths_msg = f'sub-messages {type}ed: '
2019-11-28 14:50:53 +01:00
paths_msg += ' > '.join(paths)
return paths_msg
2019-11-28 16:51:56 +01:00
def error_msg(self,
version: 'str',
message: 'str',
risotto_context: Context,
arguments,
type: str,
error: str,
msg: str=''):
""" send message when an error append
"""
paths_msg = self._get_message_paths(risotto_context, type)
print(_(f'{risotto_context.username}: ERROR: {error} ({paths_msg} with arguments "{arguments}" {msg})'))
2019-11-28 14:50:53 +01:00
2019-11-28 16:51:56 +01:00
def info_msg(self,
version: 'str',
message: 'str',
risotto_context: Context,
arguments: Dict,
type: str,
msg: str=''):
""" send message with common information
"""
paths_msg = self._get_message_paths(risotto_context, type)
print(_(f'{risotto_context.username}: INFO: {paths_msg} with arguments "{arguments}" {msg}'))
2019-11-28 14:50:53 +01:00
log = Logger()