diff --git a/core/logging/logger_utils.py b/core/logging/logger_utils.py index 6a023116..1b0fb7e4 100644 --- a/core/logging/logger_utils.py +++ b/core/logging/logger_utils.py @@ -83,6 +83,10 @@ def log(message, user=None, params=None, level="INFO", exc_info=None, log_store_ except AttributeError: message_maker = LoggerMessageCreator + log_store_for_map = getattr(logging,"log_store_for_map", None) + if log_store_for_map is not None and params is not None: + log_store_for = log_store_for_map.get(params.get(log_const.KEY_NAME), log_store_for) + if instance is not None: params = message_maker.make_message(user, params, instance.__class__.__name__, log_store_for) else: diff --git a/core/model/base_user.py b/core/model/base_user.py index 176abae1..838a5cff 100644 --- a/core/model/base_user.py +++ b/core/model/base_user.py @@ -57,14 +57,15 @@ def fields(self): @property def raw(self): - log("%(class_name)s.raw USER %(uid)s SAVE db_version = %(db_version)s.", self, - {"db_version": str(self.variables.get(self.USER_DB_VERSION)), - "uid": str(self.id)}) return super(BaseUser, self).raw @property def raw_str(self): - return json.dumps(self.raw) + raw = json.dumps(self.raw) + log("%(class_name)s.raw USER %(uid)s SAVE db_version = %(db_version)s.", self, + {"db_version": str(self.variables.get(self.USER_DB_VERSION)), + "uid": str(self.id), "user_length":len(raw)}) + return raw def expire(self): self.counters.expire() diff --git a/scenarios/user/user_model.py b/scenarios/user/user_model.py index 9cdd9939..75af4818 100644 --- a/scenarios/user/user_model.py +++ b/scenarios/user/user_model.py @@ -48,8 +48,8 @@ def _initialize(self): db_version = self.variables.get(self.USER_DB_VERSION, default=0) self.variables.set(self.USER_DB_VERSION, db_version + 1) log("%(class_name)s.__init__ USER %(uid)s LOAD db_version = %(db_version)s.", self, - {"db_version": str(db_version), - "uid": str(self.id)}) + params={"db_version": str(db_version), + "uid": str(self.id), log_const.KEY_NAME:"user_load"}) self.behaviors.initialize() @property diff --git a/smart_kit/handlers/handle_respond.py b/smart_kit/handlers/handle_respond.py index 35bb6988..d4d2cf9c 100644 --- a/smart_kit/handlers/handle_respond.py +++ b/smart_kit/handlers/handle_respond.py @@ -29,7 +29,7 @@ def run(self, payload, user): action_params = self.get_action_params(payload, user) action_name = self.get_action_name(payload, user) params = { - log_const.KEY_NAME: "handling_respond", + log_const.KEY_NAME: "process_time", "callback_id": str(callback_id), "process_time": self.get_processing_time(user), "action_name": action_name diff --git a/smart_kit/management/app_manager.py b/smart_kit/management/app_manager.py index c0af60e3..36ec01c4 100644 --- a/smart_kit/management/app_manager.py +++ b/smart_kit/management/app_manager.py @@ -15,6 +15,7 @@ def init_logger(app_config): logger_config = LoggerConfig(app_config.CONFIGS_PATH) logger_config.init() config = logger_config[LOGGING_CONFIG] + logging.log_store_for_map = config.get('log_store_for_map', None) logging.config.dictConfig(config) diff --git a/smart_kit/start_points/base_main_loop.py b/smart_kit/start_points/base_main_loop.py index a9e6ec66..1be19481 100644 --- a/smart_kit/start_points/base_main_loop.py +++ b/smart_kit/start_points/base_main_loop.py @@ -124,10 +124,6 @@ def save_user(self, db_uid, user, message): no_collisions = True try: str_data = user.raw_str - log("Saving User %(uid)s. Serialized utf8 json length is %(user_length)s symbols.", user=user, - params={"uid": user.id, - log_const.KEY_NAME: "user_save", - "user_length": len(str_data)}) if user.initial_db_data and self.user_save_check_for_collisions: no_collisions = self.db_adapter.replace_if_equals(db_uid, sample=user.initial_db_data, diff --git a/smart_kit/start_points/main_loop_async_http.py b/smart_kit/start_points/main_loop_async_http.py index e893b9ea..b4bbd5ce 100644 --- a/smart_kit/start_points/main_loop_async_http.py +++ b/smart_kit/start_points/main_loop_async_http.py @@ -70,10 +70,6 @@ async def save_user(self, db_uid, user, message): no_collisions = True try: str_data = user.raw_str - log("Saving User %(uid)s. Serialized utf8 json length is %(user_length)s symbols.", user=user, - params={"uid": user.id, - log_const.KEY_NAME: "user_save", - "user_length": len(str_data)}) if self.db_adapter.IS_ASYNC: if user.initial_db_data and self.user_save_check_for_collisions: diff --git a/smart_kit/template/static/configs/logging_config.yml b/smart_kit/template/static/configs/logging_config.yml index 58eba28d..9005efb6 100644 --- a/smart_kit/template/static/configs/logging_config.yml +++ b/smart_kit/template/static/configs/logging_config.yml @@ -46,4 +46,5 @@ formatters: format: "[{levelname}] {name} {asctime} {module} {args[uid]} {args[message_id]} {args[logging_uuid]} {args[class_name]}: {message}" console_simple_formatter: - format: "[%(levelname)s] %(name)s %(asctime)s %(module)s: %(message)s" \ No newline at end of file + format: "[%(levelname)s] %(name)s %(asctime)s %(module)s: %(message)s" +log_store_for_map: \ No newline at end of file