Skip to content

Commit

Permalink
Add config for setting log level
Browse files Browse the repository at this point in the history
Closes #461

Signed-off-by: Tomas Slusny <[email protected]>
  • Loading branch information
deathbeam committed Nov 13, 2024
1 parent 2048c22 commit 1e7141e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -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
```
Expand All @@ -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
}
```

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 3 additions & 1 deletion lua/CopilotChat/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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

Expand Down
18 changes: 12 additions & 6 deletions lua/CopilotChat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) })
Expand Down

0 comments on commit 1e7141e

Please sign in to comment.