Doehnert/laravel-log-watcher.nvim

github github
utility
stars 1
issues 0
subscribers 0
forks 0
CREATED

UPDATED


laravel-log-watcher.nvim

License Lua Neovim CI

A Neovim plugin that watches your Laravel application's laravel.log file and notifies you as errors are written, so you never have to leave the editor to check why something broke.

When you open Neovim inside a Laravel project (detected by the presence of an artisan file at the project root), the plugin:

  • Monitors storage/logs/laravel.log for new writes using a native file watcher.
  • Shows each newly appended entry as a vim.notify notification.
  • Re-detects when you change directories (DirChanged).

Features

  • Automatic Laravel detection — watches storage/logs/laravel.log when an artisan file is present in the current working directory.
  • Native file watching — uses libuv fs_event (inotify / FSEvents / ReadDirectoryChangesW) with a built-in polling fallback.
  • Append-only notifications — only newly appended bytes are shown; existing log content is not replayed on startup.
  • Safe async handling — notifications are scheduled on the main loop so they are safe to emit from filesystem event callbacks.
  • Commands & keymaps — jump straight to the log, or toggle the watcher.

Requirements

  • Neovim 0.9+ (uses vim.uv/vim.loop, vim.schedule, and vim.notify).

Installation

lazy.nvim

{
  "Doehnert/laravel-log-watcher.nvim",
  event = "VeryLazy", -- optional; default loads lazily
  opts = {}, -- calls require("laravel-log-watcher").setup(opts)
}

packer.nvim

use({
  "Doehnert/laravel-log-watcher.nvim",
  config = function()
    require("laravel-log-watcher").setup({})
  end,
})

paq

require("paq")({ "Doehnert/laravel-log-watcher.nvim" })
-- then:
require("laravel-log-watcher").setup({})

For all non-lazy plugin managers, call setup() yourself. The plugin registers its commands, keymaps, and autocmds inside setup().

Usage

There is nothing to configure to get started — open Neovim inside a Laravel app and the watcher starts automatically. New entries in laravel.log will appear as notifications.

Full in-editor documentation is available with :h laravel-log-watcher.

Commands

Command Description
:LaravelLogTail Open (and jump to the end of) laravel.log
:LaravelLogWatchToggle Toggle the file watcher on/off

Keymaps

Key Action
<leader>kt Tail laravel.log (:LaravelLogTail)
<leader>kw Toggle the watcher (:LaravelLogWatchToggle)

The default prefix is <leader>k. You can change it via the keymap_prefix option (see below). To disable the keymaps entirely, set keymap_prefix = false.

Configuration

setup() accepts a table of options, all optional:

require("laravel-log-watcher").setup({
  enabled = true,            -- start watching on startup (VimEnter)
  notify = true,             -- show a vim.notify for new log entries
  max_len = 500,             -- max characters shown per notification
  group = "LaravelLogWatcher", -- notify / autocmd group name
  log_rel = "storage/logs/laravel.log", -- path relative to the project root
  poll_interval = 1000,      -- fallback polling interval (milliseconds)
  keymap_prefix = "<leader>k", -- prefix for the plugin keymaps
})
Option Type Default Description
enabled boolean true Auto-start the watcher on startup
notify boolean true Emit notifications for new log entries
max_len number 500 Truncate notification text to this many chars
group string "LaravelLogWatcher" Notification / augroup name
log_rel string "storage/logs/laravel.log" Log path relative to the Laravel root
poll_interval number 1000 Fallback polling interval in ms
keymap_prefix string|false "<leader>k" Keymap prefix; set to false to disable

API

The module exposes a small API in case you want to wire it up yourself:

  • setup(opts) — configure and register commands/keymaps/autocmds.
  • enable() — start watching the current directory (returns true if it is a Laravel app).
  • disable() — stop the watcher and release handles.
  • toggle() — toggle the watcher on/off.
  • jump_to_log() — open (and tail) laravel.log.

How it works

  1. On VimEnter (and DirChanged), enable() checks whether the current working directory contains an artisan file.
  2. If so, it opens a libuv fs_event watcher on storage/logs/laravel.log (falling back to a poll_interval-based timer where fs_event is unavailable).
  3. The plugin tracks the last-read byte offset. When the file grows, only the newly appended bytes are read and shown via vim.notify on WARN level.

License

MIT