From c4296a17a1e498c9905f21f59010522cb378db0e Mon Sep 17 00:00:00 2001 From: monsieur xx Date: Thu, 21 Apr 2022 09:55:55 +0200 Subject: [PATCH] fix: fixes incorrect date formatting (#577) * fixed incorrect date formatting * de-aligned assignments, as per PR review comment Co-authored-by: Mathieu Bergounioux --- .../game/core-scripts/log/esc_logger.gd | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/addons/escoria-core/game/core-scripts/log/esc_logger.gd b/addons/escoria-core/game/core-scripts/log/esc_logger.gd index c1b21f934..cd213ad4b 100644 --- a/addons/escoria-core/game/core-scripts/log/esc_logger.gd +++ b/addons/escoria-core/game/core-scripts/log/esc_logger.gd @@ -262,10 +262,8 @@ func report_errors(p_path: String, errors: Array) -> void: # * message: Message to log # * err: if true, write in stderr func _log(message:String, err: bool = false): - var info = OS.get_datetime() - info["message"] = message - message = "{year}-{month}-{day}T{hour}{minute}{second} {message}" \ - .format(info) + message = "{0} {1}".format([_formatted_date(), message]) + if err: printerr(message) else: @@ -273,6 +271,20 @@ func _log(message:String, err: bool = false): _write_logfile(message) +# Returns the current date/time, as a string +# formatted for logging. E.g. 2022-04-19T16:10:39 +func _formatted_date() -> String: + var info = OS.get_datetime() + info["year"] = "%04d" % info["year"] + info["month"] = "%02d" % info["month"] + info["day"] = "%02d" % info["day"] + info["hour"] = "%02d" % info["hour"] + info["minute"] = "%02d" % info["minute"] + info["second"] = "%02d" % info["second"] + + return "{year}-{month}-{day}T{hour}:{minute}:{second}".format(info) + + # Returns the currently set log level # **Returns** Log level as set in the configuration func _get_log_level() -> int: