mirror of
https://github.com/RetroDECK/RetroDECK.git
synced 2024-11-28 00:25:42 +00:00
restore godot logger, default is still bash
This commit is contained in:
parent
ebd061d26b
commit
bba70ed690
|
@ -100,6 +100,11 @@ func multi_state(section: String, state: String) -> String:
|
||||||
return state
|
return state
|
||||||
|
|
||||||
func logger(log_type: String, log_text: String) -> void:
|
func logger(log_type: String, log_text: String) -> void:
|
||||||
|
# Type of log messages:
|
||||||
|
# log d - debug message: maybe in the future we can decide to hide them in main builds or if an option is toggled
|
||||||
|
# log i - normal informational message
|
||||||
|
# log w - waring: something is not expected but it's not a big deal
|
||||||
|
# log e - error: something broke
|
||||||
var log_header_text = "gdc_"
|
var log_header_text = "gdc_"
|
||||||
log_header_text+=log_text
|
log_header_text+=log_text
|
||||||
log_parameters = ["log", log_type, log_header_text]
|
log_parameters = ["log", log_type, log_header_text]
|
||||||
|
@ -110,33 +115,50 @@ func logger_godot(log_type: String, log_text: String) -> void:
|
||||||
var log_path: String = '/var/config/retrodeck/logs/gd_logs.log'
|
var log_path: String = '/var/config/retrodeck/logs/gd_logs.log'
|
||||||
|
|
||||||
var log_dir: DirAccess = DirAccess.open(log_dir_path)
|
var log_dir: DirAccess = DirAccess.open(log_dir_path)
|
||||||
var log_file: FileAccess = FileAccess.open(log_path, FileAccess.READ_WRITE)
|
var log_file: FileAccess
|
||||||
|
|
||||||
|
var log_header: String = " GD "
|
||||||
|
|
||||||
|
var datetime = Time.get_datetime_dict_from_system()
|
||||||
|
var msec = Time.get_ticks_msec() #very very fake ms, TODO
|
||||||
|
|
||||||
|
var timestamp: String = "[%d-%02d-%02d %02d:%02d:%02d.%03d]" % [
|
||||||
|
datetime.year, datetime.month, datetime.day,
|
||||||
|
datetime.hour, datetime.minute, datetime.second, msec] # fake ms
|
||||||
|
|
||||||
|
var log_line: String = timestamp + log_header
|
||||||
|
|
||||||
var log_line: String = "GD "
|
|
||||||
match log_type:
|
match log_type:
|
||||||
'w':
|
'w':
|
||||||
log_line += "Warning "
|
log_line += "[Warning] "
|
||||||
# print("Warning, mate")
|
# print("Warning, mate")
|
||||||
'e':
|
'e':
|
||||||
log_line += "Error "
|
log_line += "[Error] "
|
||||||
# print("Error, mate")
|
# print("Error, mate")
|
||||||
'i':
|
'i':
|
||||||
log_line += "Info "
|
log_line += "[Info] "
|
||||||
# print("Info, mate")
|
# print("Info, mate")
|
||||||
'd':
|
'd':
|
||||||
log_line += "Debug "
|
log_line += "[Debug] "
|
||||||
# print("Debug, mate")
|
# print("Debug, mate")
|
||||||
#_:
|
_:
|
||||||
#print("No idea, mate")
|
log_line += " "
|
||||||
|
print("No idea, mate")
|
||||||
log_line += log_text
|
log_line += log_text
|
||||||
# print(log_line)
|
# print(log_line)
|
||||||
|
|
||||||
if not log_dir:
|
if not log_dir:
|
||||||
log_dir = DirAccess.open("res://") #open something valid to create an instance
|
log_dir = DirAccess.open("res://") #open something valid to create an instance
|
||||||
|
print(log_dir.make_dir_recursive(log_dir_path))
|
||||||
if log_dir.make_dir_recursive(log_dir_path) != OK:
|
if log_dir.make_dir_recursive(log_dir_path) != OK:
|
||||||
print("Something wrong with log directory")
|
print("Something wrong with log directory")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not FileAccess.open(log_path, FileAccess.READ):
|
||||||
|
log_file = FileAccess.open(log_path, FileAccess.WRITE_READ) # to create a file if not there
|
||||||
|
else:
|
||||||
|
log_file = FileAccess.open(log_path, FileAccess.READ_WRITE) # to not truncate
|
||||||
|
|
||||||
if log_file:
|
if log_file:
|
||||||
log_file.seek_end()
|
log_file.seek_end()
|
||||||
log_file.store_line(log_line)
|
log_file.store_line(log_line)
|
||||||
|
|
Loading…
Reference in a new issue