Skip to content

Commit 1aec6fc

Browse files
committed
fix: display appropriate log messages
1 parent a828927 commit 1aec6fc

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lua/supermaven-nvim/logger.lua

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ local loop = vim.uv or vim.loop
55
---@class Log
66
local log = {}
77

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+
}
918

1019
local join_path = function(...)
1120
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)
7281
end
7382
end
7483

75-
if conf.log_level == "off" then
84+
if conf.log_level == "off" or level_values[conf.log_level] == nil then
7685
return
7786
end
7887

@@ -81,10 +90,8 @@ function log:add_entry(level, msg)
8190
end
8291

8392
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))
8895
end
8996
end
9097

@@ -98,13 +105,6 @@ function log:get_log_path()
98105
return log_path
99106
end
100107

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-
108108
--- Logs a warning message to the log file
109109
---@example log:warn("Something went wrong!")
110110
---@param msg string: The log message

0 commit comments

Comments
 (0)