[docs] start to flesh out command and sql docs

pull/757/head
Timothy Stack 4 years ago
parent defb00303f
commit 9cbe4d73a9

@ -7,11 +7,16 @@
white-space: normal !important;
}
.wy-table-responsive {
overflow: visible !important;
}
}
th p {
margin-bottom: 0px;
}
.wy-nav-content {
max-width: 900px;
}
table.query-results p {
font-size: 0.9em !important;
}

@ -1,26 +1,74 @@
.. include:: kbd.rst
.. _commands:
Commands
========
This chapter covers the commands used to control **lnav**.
Commands provide access to some of the more advanced features in **lnav**, like
filtering and "search tables". You can activate the command prompt by
pressing the |ks| : |ke| key. At the prompt, you can start typing in the
desired command and/or double-tap |ks| TAB |ke| to activate auto-completion
and show the available commands. To guide you in the usage of the commands,
a help window will appear above the command prompt with an explanation of the
command and its parameters (if it has any). For example, the screenshot below
shows the help for the :code:`:open` command:
.. figure:: open-help.png
:align: center
Screenshot of the online help for the :code:`:open` command.
In addition to online help, many commands provide a preview of the effects that
the command will have. This preview will activate shortly after you have
finished typing, but before you have pressed |ks| Enter |ke| to execute the
command. For example, the :code:`:open` command will show a preview of the
first few lines of the file given as its argument:
.. figure:: open-preview.png
:align: center
Screenshot of the preview shown for the :code:`:open` command.
The :code:`:filter-out` command is another instance where the preview behavior
can help you craft the correct command-line. This command takes a PCRE regular
expression that specifies the log messages that should be filtered out of the
view. The preview for this command will highlight the portion of the log
messages that match the expression in red. Thus, you can be certain that the
regular expression is matching the log messages you are interested in before
committing the filter. The following screenshot shows an example of this
preview behavior for the string "launchd":
.. figure:: filter-out-preview.png
:align: center
Screenshot showing the preview for the :code:`:filter-out launchd` command.
Any errors detected during preview will be shown in the status bar right above
the command prompt. For example, an attempt to open an unknown file will show
an error message in the status bar, like so:
.. figure:: open-error.png
:align: center
Screenshot of the error shown when trying to open a non-existent file.
.. tip::
Note that almost all commands support TAB-completion for their arguments.
So, if you are in doubt as to what to type for an argument, you can double-
tap the TAB key to get suggestions. For example, the TAB-completion for the
:code:`filter-in` command will suggest words that are currently displayed in
the view.
tap the |ks| TAB |ke| key to get suggestions. For example, the
TAB-completion for the :code:`filter-in` command will suggest words that are
currently displayed in the view.
.. note:: The following commands can be disabled by setting the ``LNAVSECURE``
environment variable before executing the **lnav** binary:
- open
- pipe-to
- pipe-line-to
- write-\*-to
- :code:`:open`
- :code:`:pipe-to`
- :code:`:pipe-line-to`
- :code:`:write-*-to`
This makes it easier to run **lnav** in restricted environments without the
risk of privilege escalation.

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

@ -1,41 +1,11 @@
.. include:: kbd.rst
.. _hotkeys:
Hotkey Reference
================
.. |ks| raw:: html
<kbd>
.. |ke| raw:: html
</kbd>
.. raw:: html
<style>
kbd {
padding: 0.1em 0.6em;
border: 1px solid #ccc;
font-size: 11px;
font-family: Arial,Helvetica,sans-serif;
background-color: #f7f7f7;
color: #333;
-moz-box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2),0 0 0 2px #ffffff inset;
-webkit-box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2),0 0 0 2px #ffffff inset;
box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2),0 0 0 2px #ffffff inset;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
display: inline-block;
margin: 0 0.1em 0.1em 0.1em;
text-shadow: 0 1px 0 #fff;
line-height: 1.4;
white-space: nowrap;
}
</style>
This reference covers the keys used to control **lnav**. Consult the `built-in
help <https://github.com/tstack/lnav/blob/master/src/help.txt>`_ in **lnav** for
a more detailed explanation of each key.

@ -0,0 +1,32 @@
.. |ks| raw:: html
<kbd>
.. |ke| raw:: html
</kbd>
.. raw:: html
<style>
kbd {
padding: 0.1em 0.6em;
border: 1px solid #ccc;
font-size: 11px;
font-family: Arial,Helvetica,sans-serif;
background-color: #f7f7f7;
color: #333;
-moz-box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2),0 0 0 2px #ffffff inset;
-webkit-box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2),0 0 0 2px #ffffff inset;
box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2),0 0 0 2px #ffffff inset;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
display: inline-block;
margin: 0 0.1em 0.1em 0.1em;
text-shadow: 0 1px 0 #fff;
line-height: 1.4;
white-space: nowrap;
}
</style>

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

@ -1,9 +1,82 @@
.. include:: kbd.rst
.. _sql-ext:
SQLite Interface
================
Log analysis in **lnav** can be done using the SQLite interface. Log messages
can be accessed via `virtual tables <https://www.sqlite.org/vtab.html>`_ that
are created for each file format. The tables have the same name as the log
format and each message is its own row in the table. For example, given the
following log message from an Apache access log:
.. code-block::
127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326
These columns would be available for its row in the :code:`access_log` table:
.. csv-table::
:class: query-results
:header-rows: 1
log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,log_comment,log_tags,log_filters,c_ip,cs_method,cs_referer,cs_uri_query,cs_uri_stem,cs_user_agent,cs_username,cs_version,sc_bytes,sc_status
0,<NULL>,2000-10-10 13:55:36.000,0,info,1,<NULL>,<NULL>,<NULL>,127.0.0.1,GET,<NULL>,<NULL>,/apache_pb.gif,<NULL>,frank,HTTP/1.0,2326,200
.. note:: Some columns are hidden by default to reduce the amount of noise in
results, but they can still be accessed when explicitly used. The hidden
columns are: :code:`log_path`, :code:`log_text`, and :code:`log_body`.
You can activate the SQL prompt by pressing the |ks| ; |ke| key. At the
prompt, you can start typing in the desired SQL statement and/or double-tap
|ks| TAB |ke| to activate auto-completion. A help window will appear above
the prompt to guide you in the usage of SQL keywords and functions.
.. figure:: sql-help.png
:align: center
Screenshot of the online help for the SQL prompt.
.. figure:: group_concat-help.png
:align: center
Screenshot of the online help for the :code:`group_concat()` function.
A simple query to perform on an Apache access log might be to get the average
and maximum number of bytes returned by the server, grouped by IP address:
.. code-block:: sql
;SELECT c_ip, avg(sc_bytes), max(sc_bytes) FROM access_log GROUP BY c_ip
After pressing |ks| Enter |ke|, SQLite will execute the query using **lnav**'s
virtual table implementation to extract the data directly from the log files.
Once the query has finished, the main window will switch to the DB view to
show the results. Press |ks| q |ke| to return to the log view and press |ks|
v |ke| to return to the log view. If the SQL results contain a
:code:`log_line` column, you can press to |ks| Shift |ke| + |ks| V |ke| to
switch between the DB view and the log
.. figure:: query-results.png
:align: center
Screenshot of the SQL results view.
The DB view has the following display features:
* Column headers stick to the top of the view when scrolling.
* A stacked bar chart of the numeric column values is displayed underneath the
rows. Pressing |ks| TAB |ke| will cycle through displaying no columns, each
individual column, or all columns.
* JSON columns in the top row can be pretty-printed by pressing |ks| p |ke|.
The display will show the value and JSON-Pointer path that can be passed to
the `jget`_ function.
Extensions
----------
To make it easier to analyze log data from within **lnav**, there are several
built-in extensions that provide extra functions and collators beyond those
`provided by SQLite <http://www.sqlite.org/lang_corefunc.html>`_. The majority
@ -15,6 +88,20 @@ the `sqlite.org <http://sqlite.org>`_ web site.
**lnav**'s interface to perform queries. The database will be attached with
a name based on the database file name.
Taking Notes
------------
A few of the columns in the log tables can be updated on a row-by-row basis to
allow you to take notes. The majority of the columns in a log table are
read-only since they are backed by the log files themselves. However, the
following columns can be changed by an :code:`UPDATE` statement:
* **log_mark** - Indicates whether the line has been bookmarked.
* **log_comment** - A free-form text field for storing commentary. This
column can also be changed by the :ref:`:comment<comment>` command.
* **log_tags** - A JSON list of tags associated with the log message. This
column can also be changed by the :ref:`:tag<tag>` command.
Commands
--------
@ -22,6 +109,9 @@ A SQL command is an internal macro implemented by lnav.
* .schema - Open the schema view. This view contains a dump of the schema
for the internal tables and any tables in attached databases.
* .msgformats - Executes a canned query that groups and counts log messages by
the format of their message bodies. This command can be useful for quickly
finding out the types of messages that are most common in a log file.
Variables
---------
@ -35,8 +125,8 @@ Environment
-----------
Environment variables can be accessed in queries using the usual syntax of
"$VAR_NAME". For example, to read the value of the "USER" variable, you can
write:
:code:`$VAR_NAME`. For example, to read the value of the "USER" variable, you
can write:
.. code-block:: sql
@ -47,11 +137,11 @@ write:
Collators
---------
* naturalcase - Compare strings "naturally" so that number values in the string
are compared based on their numeric value and not their character values.
For example, "foo10" would be considered greater than "foo2".
* naturalnocase - The same as naturalcase, but case-insensitive.
* ipaddress - Compare IPv4/IPv6 addresses.
* **naturalcase** - Compare strings "naturally" so that number values in the
string are compared based on their numeric value and not their character
values. For example, "foo10" would be considered greater than "foo2".
* **naturalnocase** - The same as naturalcase, but case-insensitive.
* **ipaddress** - Compare IPv4/IPv6 addresses.
Reference
---------

@ -1950,8 +1950,8 @@ int common_extension_functions(struct FuncDef **basic_funcs,
.with_summary("Finds the first occurrence of the needle within the haystack and returns the number of prior characters plus 1, or 0 if Y is nowhere found within X")
.with_parameter({"needle", "The string to look for in the haystack"})
.with_parameter({"haystack", "The string to search within"})
.optional()
.with_parameter({"start", "The one-based index within the haystack to start the search"})
.with_parameter(help_text("start", "The one-based index within the haystack to start the search")
.optional())
.with_tags({"string"})
.with_example({
"To search for the string 'abc' within 'abcabc' and starting at position 2",

@ -138,7 +138,13 @@ void format_help_text_for_term(const help_text &ht, int width, attr_line_t &out,
} else if (needs_comma) {
out.append(", ");
}
if (param.ht_nargs == help_nargs_t::HN_OPTIONAL) {
out.append("[");
}
out.append(param.ht_name, &view_curses::VC_STYLE, A_UNDERLINE);
if (param.ht_nargs == help_nargs_t::HN_OPTIONAL) {
out.append("]");
}
if (param.ht_nargs == help_nargs_t::HN_ZERO_OR_MORE ||
param.ht_nargs == help_nargs_t::HN_ONE_OR_MORE) {
out.append(", ...");

@ -642,7 +642,7 @@ int register_sqlite_funcs(sqlite3 *db, sqlite_registration_func_t *reg_funcs)
}),
help_text("group_concat",
"Returns a string which is the concatenation of all non-NULL values of X.")
"Returns a string which is the concatenation of all non-NULL values of X separated by a comma or the given separator.")
.sql_function()
.with_parameter({"X", "The value to concatenate."})
.with_parameter(help_text("sep", "The separator to place between the values.")

@ -1228,7 +1228,7 @@ Example
Synopsis
charindex(needle, haystack, start) -- Finds the first occurrence of the
charindex(needle, haystack, [start]) -- Finds the first occurrence of the
needle within the haystack and returns the number of prior characters plus
1, or 0 if Y is nowhere found within X
Parameters
@ -1473,8 +1473,8 @@ Example
Synopsis
group_concat(X, sep) -- Returns a string which is the concatenation of all
non-NULL values of X.
group_concat(X, [sep]) -- Returns a string which is the concatenation of all
non-NULL values of X separated by a comma or the given separator.
Parameters
X The value to concatenate.
sep The separator to place between the values.
@ -1560,7 +1560,7 @@ Example
Synopsis
jget(json, ptr, default) -- Get the value from a JSON object using a JSON-
jget(json, ptr, [default]) -- Get the value from a JSON object using a JSON-
Pointer.
Parameters
json The JSON object to query.
@ -1727,7 +1727,7 @@ Example
Synopsis
like(pattern, str, escape) -- Match a string against a pattern
like(pattern, str, [escape]) -- Match a string against a pattern
Parameters
pattern The pattern to match. A percent symbol (%) will match zero or more
characters and an underscore (_) will match a single character.
@ -1760,8 +1760,8 @@ Parameter
Synopsis
load_extension(path, entry-point) -- Loads SQLite extensions out of the given
shared library file using the given entry point.
load_extension(path, [entry-point]) -- Loads SQLite extensions out of the
given shared library file using the given entry point.
Parameters
path The path to the shared library containing the extension.
entry-point
@ -1822,7 +1822,7 @@ Example
Synopsis
ltrim(str, chars) -- Returns a string formed by removing any and all
ltrim(str, [chars]) -- Returns a string formed by removing any and all
characters that appear in the second argument from the left side of the
first.
Parameters
@ -2265,7 +2265,7 @@ Examples
Synopsis
round(num, digits) -- Returns a floating-point value rounded to the given
round(num, [digits]) -- Returns a floating-point value rounded to the given
number of digits to the right of the decimal point.
Parameters
num The value to round.
@ -2289,7 +2289,7 @@ Examples
Synopsis
rtrim(str, chars) -- Returns a string formed by removing any and all
rtrim(str, [chars]) -- Returns a string formed by removing any and all
characters that appear in the second argument from the right side of the
first.
Parameters
@ -2468,8 +2468,8 @@ Examples
Synopsis
substr(str, start, size) -- Returns a substring of input string X that begins
with the Y-th character and which is Z characters long.
substr(str, start, [size]) -- Returns a substring of input string X that
begins with the Y-th character and which is Z characters long.
Parameters
str The string to extract a substring from.
start The index within 'str' that is the start of the substring. Indexes
@ -2595,7 +2595,7 @@ Synopsis
Synopsis
trim(str, chars) -- Returns a string formed by removing any and all
trim(str, [chars]) -- Returns a string formed by removing any and all
characters that appear in the second argument from the left and right sides
of the first.
Parameters

Loading…
Cancel
Save