Skip to content

Commit

Permalink
Merge branch 'main' into feature/DPNLPF-1536
Browse files Browse the repository at this point in the history
  • Loading branch information
intsynko authored Feb 28, 2022
2 parents 6f0c888 + 5c80567 commit fe55539
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 16 deletions.
4 changes: 4 additions & 0 deletions core/logging/logger_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions core/model/base_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions scenarios/user/user_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion smart_kit/handlers/handle_respond.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions smart_kit/management/app_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
4 changes: 0 additions & 4 deletions smart_kit/start_points/base_main_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions smart_kit/start_points/main_loop_async_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion smart_kit/template/static/configs/logging_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
format: "[%(levelname)s] %(name)s %(asctime)s %(module)s: %(message)s"
log_store_for_map:

0 comments on commit fe55539

Please sign in to comment.