Skip to content

New script weelog.py: search logs with ripgrep into a results buffer - #617

Open
Strykar wants to merge 1 commit into
weechat:mainfrom
Strykar:weelog
Open

Strykar wants to merge 1 commit into
weechat:mainfrom
Strykar:weelog

Conversation

@Strykar

@Strykar Strykar commented Oct 26, 2026

Copy link
Copy Markdown

Script info

  • Script name: weelog
  • Version: 0.1.0
  • Requirements: ripgrep (rg) on PATH
  • Min WeeChat version:
  • Script tags: log, search

Description

/weelog [options] TEXT searches the files under logger.file.path with
ripgrep and prints the hits into a weelog buffer, oldest first, with the
logged timestamp in the time column and the nick in WeeChat's own colour.
Options narrow the search by nick (-nick, fuzzy, nick column only),
network and buffer (-net, -chan, or -here for the current buffer),
date (-from, -to), and widen it to status lines (-events), rotated
.gz/.zst archives (-archives) and server/services/bouncer buffers
(-system). -context N shows dimmed lines around each hit. Matching
ignores case unless -case. Both logger layouts are understood (the flat
plugin.name.weechatlog files and the dated YYYY/network/ tree). The
results buffer is no_log, and typing in it repeats the search.

rg runs through hook_process_hashtable with arg1..argN, so nothing
goes through a shell; WeeChat is not blocked while it runs. Developed and
tested with WeeChat 5.0.0-dev and Python 3.14; the script uses
hook_process_hashtable, string_eval_path_home and the nick_color
info, nothing newer.

How this relates to grep.py: grep.py is a general regular-expression tool
over open buffers and log files with no dependencies, and it has features
this script does not (searching a buffer's lines, invert, count, only-match,
head/tail, pattern templates). weelog is a filter-driven search over the log
directory that needs ripgrep installed. On a 2.6 GiB tree of 84,580 log
files, grep.py's file loop and ripgrep found the same 1563 hits for the
same pattern in 27.8 s and 0.69 s respectively. That speed, together with
the nick/network/buffer/date filters and archive decompression, is the
reason for a separate script.

The script is a generated single file; the source, tests and a headless
WeeChat test harness live in the upstream repository.

Testing: /script load /path/to/weelog.py, then /weelog some words,
/weelog -nick NICK -from 2026-01-01 some words, /weelog -context 2 -here text.

Checklist (new script)

  • Single commit, single file added
  • Commit message: New script name.py: short description…
  • No similar script already exists (grep.py overlaps in purpose, see above)
  • Name: max 32 chars, only lower case letters, digits and underscores
  • Unique name, does not already exist in repository
  • No shebang on the first line
  • Comment in script with name/pseudo, e-mail and license using SPDX tags (see Contributing guide)
  • Only English in code/comments
  • Pure WeeChat API used, no extra API
  • Function hook_url, hook_process or hook_process_hashtable is used for any blocking call
  • For Python script: works with Python 3 (Python 2 support is optional)
  • Score 100 / 100 displayed by weechat-script-lint

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.

1 participant