forked from Infra/risotto
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
from typing import Dict
|
|
from .context import Context
|
|
from .utils import _
|
|
|
|
|
|
class Logger:
|
|
""" An object to manager log
|
|
FIXME should add event to a database
|
|
"""
|
|
def _get_message_paths(self,
|
|
risotto_context: Context,
|
|
type: str):
|
|
paths = risotto_context.paths
|
|
if len(paths) == 1:
|
|
paths_msg = f'messages {type}ed: {paths[0]}'
|
|
else:
|
|
paths_msg = f'sub-messages {type}ed: '
|
|
paths_msg += ' > '.join(paths)
|
|
return paths_msg
|
|
|
|
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})'))
|
|
|
|
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}'))
|
|
|
|
|
|
log = Logger()
|