logger.nvim
July 18, 2026 ยท View on GitHub
logger.nvim is a simple runtime logger plugin for Neovim.
It provides four log levels, in-memory runtime log storage,
optional file logging, and per-plugin derived loggers.
- โจ Features
- ๐ฆ Installation
- ๐ง Configuration
- โ๏ธ Basic Usage
- ๐ Derived Logger
- ๐ File Logging
- ๐๏ธ View Runtime Log
- ๐ API
- ๐ Logging Levels
- ๐ฃ Self-Promotion
- ๐ License
โจ Features
- Four log levels: Debug, Info, Warn, Error
- Runtime log stored in memory, viewable in a buffer
- Optional file logging with append mode
- Per-plugin derived loggers with independent level control
- Minimal dependencies โ uses only Neovim's built-in Lua
๐ฆ Installation
logger.nvim works with all major Neovim plugin managers.
-
Using nvim-plug
require('plug').add({ { 'wsdjeg/logger.nvim', config = function() require('logger').setup() end, }, }) -
Using lazy.nvim
{ 'wsdjeg/logger.nvim', config = function() require('logger').setup() end, } -
Using packer.nvim
use({ 'wsdjeg/logger.nvim', config = function() require('logger').setup() end, }) -
Using luarocks
luarocks install logger.nvim
๐ง Configuration
require('logger').setup({
level = 1, -- 0:debug 1:info 2:warn 3:error (default: 1)
file = '', -- log file path, empty = runtime only (default: '')
})
โ๏ธ Basic Usage
local logger = require('logger')
logger.info('plugin initialized')
logger.warn('deprecated API called')
logger.error('failed to load config')
logger.debug('internal state: ' .. tostring(state))
Output format:
[ 22:30:45:123 ] [ Info ] [ logger ] plugin initialized
[ 22:30:45:124 ] [ Warn ] [ logger ] deprecated API called
[ 22:30:45:125 ] [ Error ] [ logger ] failed to load config
[ 22:30:45:126 ] [ Debug ] [ logger ] internal state: nil
๐ Derived Logger
Create a named logger for your plugin with derive():
local logger = require('logger').derive('myplugin')
logger.info('starting up')
logger.set_level(0) -- debug level for this plugin only
The derived logger name is right-aligned to 12 characters:
[ 22:30:45:123 ] [ Info ] [ myplugin ] starting up
Each derived logger has its own set_level, independent of the global level.
๐ File Logging
When file is set in setup(), every log message is appended to the file:
require('logger').setup({
level = 1,
file = vim.fn.stdpath('cache') .. '/myplugin.log',
})
require('logger').info('this will be written to the file')
Each line in the file has the same format as the runtime log. Messages are appended on each write, so the file persists across sessions.
๐๏ธ View Runtime Log
All log messages are stored in memory. View them at any time:
require('logger').viewRuntimeLog()
Opens a new tab showing all accumulated logs. Press q to close.
To clear the runtime log:
require('logger').clearRuntimeLog()
๐ API
| function | description |
|---|---|
setup(opts) | Initialize with level and file options |
info(msg) | Log info-level message |
warn(msg) | Log warning-level message |
error(msg) | Log error-level message |
debug(msg) | Log debug-level message |
derive(name) | Create plugin-specific logger |
viewRuntimeLog() | View runtime log in a new tab |
clearRuntimeLog() | Clear in-memory runtime log |
setup(opts)
Initialize the logger with custom configuration.
| option | type | default | description |
|---|---|---|---|
level | 0|1|2|3 | 1 | Logging level |
file | string | '' | Log file path, empty for runtime only |
require('logger').setup({
level = 1,
file = vim.fn.stdpath('cache') .. '/myapp.log',
})
info(msg)
Log info-level message (visible when level โค 1).
logger.info('Plugin initialized successfully')
warn(msg)
Log warning-level message (visible when level โค 2).
logger.warn('Deprecated function called')
error(msg)
Log error-level message. Always logged regardless of level.
logger.error('Failed to load configuration')
debug(msg)
Log debug-level message (visible when level = 0).
logger.debug('Variable value: ' .. tostring(value))
derive(name)
Create a named logger instance for your plugin.
Returns a table with info, warn, error, debug, and set_level methods.
local myLogger = require('logger').derive('treesitter')
myLogger.set_level(0) -- debug level for this logger only
myLogger.debug('Parsing AST')
viewRuntimeLog()
Display the runtime log in a new tab. Press q to close the buffer.
require('logger').viewRuntimeLog()
clearRuntimeLog()
Clear all entries from the in-memory runtime log.
require('logger').clearRuntimeLog()
๐ Logging Levels
| Level | Value | Logs |
|---|---|---|
| Debug | 0 | debug, info, warn, error |
| Info | 1 | info, warn, error |
| Warn | 2 | warn, error |
| Error | 3 | error |
error messages are always logged regardless of the level setting.
๐ฃ Self-Promotion
Like this plugin? Star the repository on GitHub.
Love this plugin? Follow me on GitHub.
๐ License
This project is licensed under the GPL-3.0 License.