diff --git a/lua/eca/logger.lua b/lua/eca/logger.lua index 8ccf9d5..7340ebd 100644 --- a/lua/eca/logger.lua +++ b/lua/eca/logger.lua @@ -88,10 +88,7 @@ end --- Log a message to the log file ---@param message string ---@param level integer ----@param opts? {title?: string} -function M.log(message, level, opts) - opts = opts or {} - +function M.log(message, level) if not M.config then return end @@ -105,8 +102,7 @@ function M.log(message, level, opts) local timestamp = os.date("%Y-%m-%d %H:%M:%S") local level_name = get_level_name(level) - local prefix = opts.title == "SERVER" and "SERVER" or "CLIENT" - local formatted = string.format("[%s] %-5s [%s] %s\n", timestamp, level_name, prefix, message) + local formatted = string.format("[%s] %-5s %s\n", timestamp, level_name, message) uv.fs_open(log_path, "a", 420, function(err, fd) if err or not fd then @@ -120,45 +116,40 @@ end --- Log debug message ---@param message string ----@param opts? {title?: string} -function M.debug(message, opts) - M.log(message, vim.log.levels.DEBUG, opts) +function M.debug(message) + M.log(message, vim.log.levels.DEBUG) end --- Log info message ---@param message string ----@param opts? {title?: string} -function M.info(message, opts) - M.log(message, vim.log.levels.INFO, opts) +function M.info(message) + M.log(message, vim.log.levels.INFO) end --- Log warn message ---@param message string ----@param opts? {title?: string} -function M.warn(message, opts) - M.log(message, vim.log.levels.WARN, opts) +function M.warn(message) + M.log(message, vim.log.levels.WARN) end --- Log error message ---@param message string ----@param opts? {title?: string} -function M.error(message, opts) - M.log(message, vim.log.levels.ERROR, opts) +function M.error(message) + M.log(message, vim.log.levels.ERROR) end --- Send notification to user via vim.notify ---@param message string ---@param level? integer vim.log.levels (default: INFO) ----@param opts? {title?: string, once?: boolean} +---@param opts? {title?: string} function M.notify(message, level, opts) level = level or vim.log.levels.INFO opts = opts or {} - M.log(message, level, opts) + M.log(message, level) vim.notify(message, level, { title = opts.title or "ECA", - once = opts.once, }) end diff --git a/lua/eca/server.lua b/lua/eca/server.lua index bfa7b80..11ec5c5 100644 --- a/lua/eca/server.lua +++ b/lua/eca/server.lua @@ -100,11 +100,10 @@ function M:start() -- Use vim.fn.jobstart for interactive processes local job_opts = { on_stdout = function(_, data, _) - Logger.debug("Server stdout received: " .. vim.inspect(data)) if data and self._rpc then local output = table.concat(data, "\n") if output and output ~= "" and output ~= "\n" then - Logger.debug("Processing stdout: " .. output) + Logger.log(output, vim.log.levels.INFO) self._rpc:_handle_stdout(output) end end @@ -122,8 +121,7 @@ function M:start() if #meaningful_lines > 0 then local error_output = table.concat(meaningful_lines, "\n") - Logger.debug("ECA server stderr: " .. error_output) - -- Capture logs for the logs buffer + Logger.log(error_output, vim.log.levels.WARN) end end end, diff --git a/tests/test_logging.lua b/tests/test_logging.lua index bb9a93f..189d78a 100644 --- a/tests/test_logging.lua +++ b/tests/test_logging.lua @@ -228,7 +228,6 @@ T["file_logging"]["writes to file with correct format"] = function() expect_match(contents, "%[%d%d%d%d%-%d%d%-%d%d %d%d:%d%d:%d%d%]") expect_match(contents, "INFO") - expect_match(contents, "%[CLIENT%]") expect_match(contents, "test message") end @@ -303,7 +302,6 @@ T["notifications"]["Logger.notify writes to log file"] = function() expect_match(contents, "WARN") expect_match(contents, "test notification message") - expect_match(contents, "%[CLIENT%]") local notifications = child.lua_get("_G.captured_notifications") eq(#notifications, 1) @@ -380,24 +378,6 @@ T["integration"]["logger functions work correctly"] = function() expect_match(contents, "error message") end -T["integration"]["server logging with SERVER prefix"] = function() - local contents = log_and_read( - "server_integration.log", - [[ - Logger.info('server message 1', { title = 'SERVER' }) - Logger.warn('server warning', { title = 'SERVER' }) - Logger.error('server error', { title = 'SERVER' }) - - Logger.info('client message') - ]] - ) - - expect_match(contents, "%[SERVER%] server message 1") - expect_match(contents, "%[SERVER%] server warning") - expect_match(contents, "%[SERVER%] server error") - expect_match(contents, "%[CLIENT%] client message") -end - T["integration"]["EcaLogs command behavior"] = function() setup_logger_with_file("eca_logs_test.log")