Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ulsp: add method to logger to add log files, make singleton optional #483

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions uni/ulsp/launch-lsp.icn
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ procedure usage()
write("\t -c : run as a client")
write("\t --logfile <filename> : log file")
write("\t --loglevel <level> : log level from 0-17. log levels 8-17 are used for debugging")
write("\t --debug-class <class>: debug class to log")
write("\t --debug-kind <kind>: debug kind to log")
write("\t -h : show this help\n")
exit(-1)
end

procedure validate_args(args)
local opts
opts := options(args, "--socket+ --logfile: --loglevel+ --debug-class: -h! -c! -s!", usage)
opts := options(args, "--socket+ --logfile: --loglevel+ --debug-kind: -h! -c! -s!", usage)
if *opts = 0 then usage()
member(opts, "-socket") | usage()
return opts
Expand All @@ -59,8 +59,8 @@ procedure main(args)

Logger((opts["-loglevel"]), opts["-logfile"]) # # default to informational, stdout

if \opts["-debug-class"] then
Logger.add_debug_kind(opts["-debug-class"])
if \opts["-debug-kind"] then
Logger.add_debug_kind(opts["-debug-kind"])

# Allow passing full host:port as an arg
sock := opts["-socket"]
Expand Down
26 changes: 18 additions & 8 deletions uni/ulsp/logger.icn
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ link strings
class Logger(
log_destinations, # zero or more log destinations
current_log_level, # the current log level
debug_class_set,
debug_kind_set,
log_type_list, #
enable_stdout, # log to stdout
enable_stderr, # log to stderr
Expand Down Expand Up @@ -97,14 +97,14 @@ class Logger(

# every w := words(kind, ":") do {
# (/s:=w) | (s||:= ":" || w)
# if member(debug_class_set, s) then {
# if member(debug_kind_set, s) then {
# match_kind := 1
# break
# }
# }

current_log_level > 7 | fail
loglvl <= current_log_level | member(debug_class_set, kind) | fail
loglvl <= current_log_level | member(debug_kind_set, kind) | fail

if \enable_timestamp then
clock := &date || " " || &clock
Expand Down Expand Up @@ -159,11 +159,20 @@ class Logger(
# Config methods
#
method add_debug_kind(kind)
insert(debug_class_set, kind)
insert(debug_kind_set, kind)
end

method remove_debug_kind(kind)
delete(debug_class_set, kind)
delete(debug_kind_set, kind)
end

method add_log_file(log_file_path)
local f
if \log_file_path then
if f := open(log_file_path, "a") then {
put(log_destinations, f)
return
}
end

# move all output to stderr
Expand Down Expand Up @@ -313,7 +322,7 @@ class Logger(
self._debug(lvl+8, kind, msgs)
end

initially(init_log_level, log_file_path)
initially(init_log_level, log_file_path, no_singleton)
local f
log_type_list := [
#"none", # 0. Disable logging completely.
Expand Down Expand Up @@ -342,12 +351,13 @@ class Logger(
enable_timestamp := "file"
enable_loginfo := "all"
clock := ""
debug_class_set := set("")
debug_kind_set := set("")
current_log_level := \init_log_level | 7
log_destinations := []
if \log_file_path then
if f := open(log_file_path, "a") then
put(log_destinations, f)

Logger := self # make this a singleton class
if /no_singleton then
Logger := self # make this a singleton class
end
Loading