The events mechanism allows lnav to be automated based on events that occur during processing. For example, filters could be added only when a particular log file format is detected instead of always installing them. Events are published through the lnav_events SQLite table. Reacting to events can be done by creating a SQLite trigger on the table and inspecting the content of the event.
The following is an example of a trigger that adds an out filter when a
syslog file is loaded. You can copy the code into an
.sql file and
install it by running
lnav -i my_trigger.sql.
1CREATE TRIGGER IF NOT EXISTS add_format_specific_filters 2 AFTER INSERT ON lnav_events WHEN 3 -- Check the event type 4 jget(NEW.content, '/$schema') = 5 'https://lnav.org/event-file-format-detected-v1.schema.json' AND 6 -- Only create the filter when a given format is seen 7 jget(NEW.content, '/format') = 'syslog_log' AND 8 -- Don't create the filter if it's already there 9 NOT EXISTS ( 10 SELECT 1 FROM lnav_view_filters WHERE pattern = 'noisy message') 11BEGIN 12INSERT INTO lnav_view_filters (view_name, enabled, type, pattern) VALUES 13 ('log', 1, 'OUT', 'noisy message'); 14END;
The following tables describe the schema of the event JSON objects.