Events (v0.11.0+)#

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.

Trigger Example#

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.

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;

Reference#

The following tables describe the schema of the event JSON objects.

https://lnav.org/event-file-open-v1.schema.json#

Event fired when a file is opened.

https://lnav.org/event-file-open-v1.schema.json

properties

  • $schema

/$schema

type

string

examples

https://lnav.org/event-file-open-v1.schema.json

  • filename

/filename

The path of the file that was opened

type

string

additionalProperties

False

https://lnav.org/event-file-format-detected-v1.schema.json#

Event fired when a log format is detected for a file.

https://lnav.org/event-file-format-detected-v1.schema.json

properties

  • $schema

/$schema

type

string

examples

https://lnav.org/event-file-format-detected-v1.schema.json

  • filename

/filename

The path of the file for which a matching format was found

type

string

  • format

/format

The name of the format

type

string

additionalProperties

False

https://lnav.org/event-log-msg-detected-v1.schema.json#

Event fired when a log message is detected by a watch expression.

https://lnav.org/event-log-msg-detected-v1.schema.json

properties

  • $schema

/$schema

type

string

examples

https://lnav.org/event-log-msg-detected-v1.schema.json

  • watch-name

/watch-name

The name of the watch expression that matched this log message

type

string

  • filename

/filename

The path of the file containing the log message

type

string

  • line-number

/line-number

The line number in the file, starting from zero

type

integer

  • format

/format

The name of the log format that matched this log message

type

string

  • timestamp

/timestamp

The timestamp of the log message

type

string

  • values

/values

The log message values captured by the log format

type

object

patternProperties

  • ([\w\-]+)

/values/<name>

type

boolean / integer / string

additionalProperties

False

additionalProperties

False

https://lnav.org/event-session-loaded-v1.schema.json#

Event fired when a session is loaded.

https://lnav.org/event-session-loaded-v1.schema.json

properties

  • $schema

/$schema

type

string

examples

https://lnav.org/event-session-loaded-v1.schema.json

additionalProperties

False