@@ -3,7 +3,7 @@ local uv = vim.uv or vim.loop
33--- @class eca.Logger
44local M = {}
55
6- local config = nil
6+ M . config = nil
77
88local LEVEL_NAMES = {
99 [vim .log .levels .TRACE ] = " TRACE" ,
7777--- Initialize logger with configuration
7878--- @param user_config table
7979function M .setup (user_config )
80- config = user_config
80+ -- Extract log config and set defaults
81+ local log_config = user_config and user_config .log or {}
82+
83+ M .config = {
84+ level = log_config .level or " info" ,
85+ notify = log_config .notify ~= nil and log_config .notify or false ,
86+ file = log_config .file ~= nil and log_config .file or true ,
87+ }
8188
8289 -- Check log file size on startup and notify if too large
8390 if M .is_file_logging_enabled () then
9198--- Check if file logging is enabled
9299--- @return boolean
93100function M .is_file_logging_enabled ()
94- return config and config .log and config .log .file and resolve_log_path (config .log .file ) ~= nil
101+ if not M .config then
102+ return false
103+ end
104+
105+ -- If file is true, we use default path, if it's a string, we use custom path
106+ -- If file is false, file logging is disabled
107+ return M .config .file == true or type (M .config .file ) == " string"
95108end
96109
97110--- Check if notifications are enabled
98111--- @return boolean
99112function M .is_notify_enabled ()
100- return config and config . log and config . log .notify or false
113+ return M . config and M . config .notify or false
101114end
102115
103116--- Get current log file path
104117--- @return string | nil
105118function M .get_log_path ()
106- if not config or not config . log then
119+ if not M . config then
107120 return nil
108121 end
109- return resolve_log_path (config . log .file )
122+ return resolve_log_path (M . config .file )
110123end
111124
112125--- Main logging function
@@ -116,25 +129,29 @@ end
116129function M .log (message , level , opts )
117130 opts = opts or {}
118131
119- -- Early return if no config or logging disabled
120- if not config or not config . log then
132+ -- Early return if no config
133+ if not M . config then
121134 return
122135 end
123136
124- local min_level = get_log_level (config . log .level )
137+ local min_level = get_log_level (M . config .level )
125138 if level < min_level then
126139 return
127140 end
128141
129- if opts .notify then
142+ -- Determine if we should notify
143+ local should_notify = opts .notify == true or (opts .notify == nil and opts .file == nil and M .config .notify )
144+ if should_notify then
130145 vim .notify (message , level , {
131146 title = opts .title or " ECA" ,
132147 once = opts .once ,
133148 })
134149 end
135150
136- if opts .file then
137- local log_path = resolve_log_path (config .log .file )
151+ -- Determine if we should log to file
152+ local should_log_to_file = opts .file == true or (opts .file == nil and opts .notify == nil and M .config .file )
153+ if should_log_to_file then
154+ local log_path = resolve_log_path (M .config .file )
138155 if log_path then
139156 -- Ensure parent directory exists
140157 vim .fn .mkdir (vim .fn .fnamemodify (log_path , " :h" ), " p" )
0 commit comments