From 1e7141e914cc26a3d191f869e52719b902138f6b Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Wed, 13 Nov 2024 17:16:12 +0100 Subject: [PATCH] Add config for setting log level Closes #461 Signed-off-by: Tomas Slusny --- README.md | 15 ++++++++------- lua/CopilotChat/config.lua | 4 +++- lua/CopilotChat/init.lua | 18 ++++++++++++------ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9291d95c..1f1be5f6 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,7 @@ return { }, build = "make tiktoken", -- Only on MacOS or Linux opts = { - debug = true, -- Enable debugging - -- See Configuration section for rest + -- See Configuration section for options }, -- See Commands section for default commands if you want to lazy load on them }, @@ -64,8 +63,7 @@ call plug#end() lua << EOF require("CopilotChat").setup { - debug = true, -- Enable debugging - -- See Configuration section for rest + -- See Configuration section for options } EOF ``` @@ -88,8 +86,7 @@ git clone -b canary https://github.com/CopilotC-Nvim/CopilotChat.nvim ```lua require("CopilotChat").setup { - debug = true, -- Enable debugging - -- See Configuration section for rest + -- See Configuration section for options } ``` @@ -191,6 +188,9 @@ actions.pick(actions.help_actions()) actions.pick(actions.prompt_actions({ selection = require("CopilotChat.select").visual, })) + +-- Programatically set log level +chat.log_level("debug") ``` ## Configuration @@ -201,7 +201,8 @@ Also see [here](/lua/CopilotChat/config.lua): ```lua { - debug = false, -- Enable debug logging + debug = false, -- Enable debug logging (same as 'log_level = 'debug') + log_level = 'info', -- Log level to use, 'trace', 'debug', 'info', 'warn', 'error', 'fatal' proxy = nil, -- [protocol://]host[:port] Use this proxy allow_insecure = false, -- Allow insecure server connections diff --git a/lua/CopilotChat/config.lua b/lua/CopilotChat/config.lua index 556f1e61..a6e1ac02 100644 --- a/lua/CopilotChat/config.lua +++ b/lua/CopilotChat/config.lua @@ -56,6 +56,7 @@ local select = require('CopilotChat.select') --- CopilotChat default configuration ---@class CopilotChat.config ---@field debug boolean? +---@field log_level string? ---@field proxy string? ---@field allow_insecure boolean? ---@field system_prompt string? @@ -79,7 +80,8 @@ local select = require('CopilotChat.select') ---@field window CopilotChat.config.window? ---@field mappings CopilotChat.config.mappings? return { - debug = false, -- Enable debug logging + debug = false, -- Enable debug logging (same as 'log_level = 'debug') + log_level = 'info', -- Log level to use, 'trace', 'debug', 'info', 'warn', 'error', 'fatal' proxy = nil, -- [protocol://]host[:port] Use this proxy allow_insecure = false, -- Allow insecure server connections diff --git a/lua/CopilotChat/init.lua b/lua/CopilotChat/init.lua index c085a566..0ff35c49 100644 --- a/lua/CopilotChat/init.lua +++ b/lua/CopilotChat/init.lua @@ -586,14 +586,15 @@ function M.load(name, history_path) M.open() end ---- Enables/disables debug ----@param debug boolean -function M.debug(debug) - M.config.debug = debug +--- Set the log level +---@param level string +function M.log_level(level) + M.config.log_level = level + M.config.debug = level == 'debug' local logfile = string.format('%s/%s.log', vim.fn.stdpath('state'), plugin_name) log.new({ plugin = plugin_name, - level = debug and 'debug' or 'info', + level = level, outfile = logfile, }, true) log.logfile = logfile @@ -643,7 +644,12 @@ function M.setup(config) end state.copilot = Copilot(M.config.proxy, M.config.allow_insecure) - M.debug(M.config.debug) + + if M.config.debug then + M.log_level('debug') + else + M.log_level(M.config.log_level) + end local hl_ns = vim.api.nvim_create_namespace('copilot-chat-highlights') vim.api.nvim_set_hl(hl_ns, '@diff.plus', { bg = blend_color_with_neovim_bg('DiffAdd', 20) })