Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use vim.notify as default console log #578

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lettertwo
Copy link

@lettertwo lettertwo commented May 8, 2024

vim.notify is arguably a more ergonomic way of showing level-filtered messages to the user, and it also allows for custom providers and handling, like nvim-notify or noice , to integrate messages from plenary.log.

I'm not sure if it's a bad idea to make this the new default; it could certainly be a breaking change, but i think that the intention of an author who has not overridden the default config probably aligns with the behavior of vim.notify.

Fixes #540

[vim.notify](https://neovim.io/doc/user/lua.html#vim.notify()) is arguably a more ergonomic way of showing level-filtered messages to the user, and it also allows for custom providers and handling, like [nvim-notify](https://github.com/rcarriga/nvim-notify) or [noice](https://github.com/folke/noice.nvim) , to integrate messages from  `plenary.log`.

I'm not sure if it's a bad idea to make this the new default; it could certainly be a breaking change, but i think that the _intention_ of an author who has not overridden the default config probably aligns with the behavior of `nvim.notify`.

Fixes nvim-lua#540
local level = vim.log.levels[level_config.name:upper()]
if level == nil then
level = vim.log.levels.ERROR
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ERROR by default? When can level be nil?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plenary's log config defines levels like:

  modes = {
    { name = "trace", hl = "Comment" },
    { name = "debug", hl = "Comment" },
    { name = "info", hl = "None" },
    { name = "warn", hl = "WarningMsg" },
    { name = "error", hl = "ErrorMsg" },
    { name = "fatal", hl = "ErrorMsg" },
  },

while vim.log.levels is defined as:

    vim.log.levels.DEBUG
    vim.log.levels.ERROR
    vim.log.levels.INFO
    vim.log.levels.TRACE
    vim.log.levels.WARN
    vim.log.levels.OFF

These almost match, but plenary defines a level "fatal" that vim.log.levels does not. I figured vim.log.levels.ERROR was the closest analogue to it, but maybe it's not sensible to just assume any unknown level should be treated as such. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware of "fatal" in plenary. Makes sense, thanks for the explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use vim.notify(msg, vim.log.Level) for logger
2 participants