Skip to content

Commit

Permalink
feat: logger timestamp
Browse files Browse the repository at this point in the history
refers to: #163
  • Loading branch information
Ark2000 committed Feb 19, 2024
1 parent ef133ba commit 477c949
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 42 deletions.
29 changes: 0 additions & 29 deletions addons/panku_console/modules/native_logger/log_overlay.gd

This file was deleted.

5 changes: 1 addition & 4 deletions addons/panku_console/modules/native_logger/log_overlay.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
[gd_scene load_steps=3 format=3 uid="uid://clwb00tc8ogtr"]

[ext_resource type="Script" path="res://addons/panku_console/modules/native_logger/log_overlay.gd" id="1_638j8"]
[gd_scene load_steps=2 format=3 uid="uid://clwb00tc8ogtr"]

[sub_resource type="Theme" id="Theme_dksur"]
default_font_size = 16
Expand All @@ -22,4 +20,3 @@ scroll_active = false
scroll_following = true
autowrap_mode = 0
shortcut_keys_enabled = false
script = ExtResource("1_638j8")
7 changes: 6 additions & 1 deletion addons/panku_console/modules/native_logger/logger_view.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extends Control
signal content_updated(bbcode:String)

var console:PankuConsole
var _module:PankuModule

const MAX_LOGS = 128

Expand Down Expand Up @@ -105,7 +106,11 @@ func update_view():
elif log["level"] == 3:
s = "[color=#dd7085]%s[/color]" % log["message"]
if log["count"] > 1:
s = "[b](%d)[/b]%s" % [log["count"], s]
s = "[b](%d)[/b] %s" % [log["count"], s]
# add timestamp prefix
if _module.show_timestamp:
var time_str := Time.get_time_string_from_unix_time(log["timestamp"])
s = "[color=#a0a0a0][%s][/color] %s" % [time_str, s]
result.append(s)

var content:String = "\n".join(result)
Expand Down
21 changes: 13 additions & 8 deletions addons/panku_console/modules/native_logger/module.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var native_logs_monitor:Node
var window:PankuLynxWindow
var logger_ui:Node
var output_overlay_display_mode:ScreenOverlayDisplayMode
var show_timestamp:bool

enum ScreenOverlayDisplayMode {
AlwaysShow,
Expand All @@ -19,12 +20,12 @@ func init_module():

# add output overlay
output_overlay = preload("./log_overlay.tscn").instantiate()
output_overlay._module = self
output_overlay.clear()
core.add_child(output_overlay)

# add logger window
logger_ui = preload("./logger_view.tscn").instantiate()
logger_ui._module = self
logger_ui.console = core

window = core.windows_manager.create_window(logger_ui)
Expand Down Expand Up @@ -62,9 +63,9 @@ func init_module():
get_module_opt().screen_overlay_alpha = load_module_data("screen_overlay_alpha", 0.3)
get_module_opt().screen_overlay_font_size = load_module_data("screen_overlay_font_size", 13)
get_module_opt().screen_overlay_font_shadow = load_module_data("screen_overlay_font_shadow", false)
get_module_opt().show_timestamp = load_module_data("show_timestamp", true)
logger_ui.load_data(load_module_data("logger_tags", ["[error]", "[warning]"]))


func quit_module():
super.quit_module()
# properties defined in opt.gd will be automatically saved as soon as the value is changed
Expand All @@ -76,12 +77,12 @@ func open_window():
window.show_window()

func toggle_overlay():
if output_overlay_display_mode == ScreenOverlayDisplayMode.AlwaysShow:
output_overlay_display_mode = ScreenOverlayDisplayMode.NeverShow
elif output_overlay_display_mode == ScreenOverlayDisplayMode.ShowIfShellVisible:
output_overlay_display_mode = ScreenOverlayDisplayMode.NeverShow
elif output_overlay_display_mode == ScreenOverlayDisplayMode.NeverShow:
output_overlay_display_mode = ScreenOverlayDisplayMode.AlwaysShow
var next = {
ScreenOverlayDisplayMode.AlwaysShow: ScreenOverlayDisplayMode.NeverShow,
ScreenOverlayDisplayMode.ShowIfShellVisible: ScreenOverlayDisplayMode.NeverShow,
ScreenOverlayDisplayMode.NeverShow: ScreenOverlayDisplayMode.AlwaysShow
}
output_overlay_display_mode = next[output_overlay_display_mode]
set_overlay_display_mode(output_overlay_display_mode)

func set_overlay_display_mode(mode:ScreenOverlayDisplayMode):
Expand All @@ -92,3 +93,7 @@ func set_overlay_display_mode(mode:ScreenOverlayDisplayMode):
output_overlay.visible = core.get_shell_visibility()
elif output_overlay_display_mode == ScreenOverlayDisplayMode.NeverShow:
output_overlay.visible = false

func set_show_timestamp(v:bool):
show_timestamp = v
logger_ui.update_view()
5 changes: 5 additions & 0 deletions addons/panku_console/modules/native_logger/opt.gd
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func open_window():
get:
return _module.output_overlay_display_mode

@export var show_timestamp:bool = true:
set(v):
_module.set_show_timestamp(v)
get:
return _module.show_timestamp

@export_range(0.0, 1.0, 0.01) var screen_overlay_alpha:float = 0.5:
set(v):
Expand Down

0 comments on commit 477c949

Please sign in to comment.