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.

Run Tests GitHub License GitHub Issues or Pull Requests GitHub commit activity GitHub Release luarocks

โœจ 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

functiondescription
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.

optiontypedefaultdescription
level0|1|2|31Logging level
filestring''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

LevelValueLogs
Debug0debug, info, warn, error
Info1info, warn, error
Warn2warn, error
Error3error

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.