@@ -5,7 +5,16 @@ local loop = vim.uv or vim.loop
5
5
--- @class Log
6
6
local log = {}
7
7
8
- --- @alias LogLevel " off" | " trace" | " debug" | " info" | " warn" | " error" | " log"
8
+ --- @alias LogLevel " off" | " trace" | " debug" | " info" | " warn" | " error"
9
+
10
+ local level_values = {
11
+ off = 0 ,
12
+ trace = 1 ,
13
+ debug = 2 ,
14
+ info = 3 ,
15
+ warn = 4 ,
16
+ error = 5 ,
17
+ }
9
18
10
19
local join_path = function (...)
11
20
local is_windows = loop .os_uname ().version :match (" Windows" ) -- could be "Windows" or "Windows_NT"
@@ -72,7 +81,7 @@ function log:add_entry(level, msg)
72
81
end
73
82
end
74
83
75
- if conf .log_level == " off" then
84
+ if conf .log_level == " off" or level_values [ conf . log_level ] == nil then
76
85
return
77
86
end
78
87
@@ -81,10 +90,8 @@ function log:add_entry(level, msg)
81
90
end
82
91
83
92
self :write_log_file (level , msg )
84
- if conf .log_level ~= " error" and conf .log_level ~= " warn" then
85
- if level ~= " error" and level ~= " warn" then
86
- print (self .__notify_fmt (msg ))
87
- end
93
+ if level_values [level ] >= level_values [conf .log_level ] then
94
+ print (self .__notify_fmt (msg ))
88
95
end
89
96
end
90
97
@@ -98,13 +105,6 @@ function log:get_log_path()
98
105
return log_path
99
106
end
100
107
101
- --- Logs a message to the log file
102
- --- @example log:log("Hello, world!")
103
- --- @param msg string : The log message
104
- function log :log (msg )
105
- self :add_entry (" log" , msg )
106
- end
107
-
108
108
--- Logs a warning message to the log file
109
109
--- @example log:warn("Something went wrong!")
110
110
--- @param msg string : The log message
0 commit comments