[cli] add -r flag for recursively loading files from a directory hierarchy

Fixes #431
pull/627/head
Timothy Stack 5 years ago
parent 8d3b83403c
commit 78d80fddd5

@ -42,6 +42,8 @@ lnav v0.8.5:
you can press TAB cycle through the options.
* Added CTRL+F to toggle the enabled/disabled state of all filters for the
current view.
* The '-r' flag is now for recursively loading files. The functionality
for loading rotated files is now under the '-R' flag.
* The current search term is now shown in the bottom status bar.
* Some initial help text is now shown for the search and SQL prompts to
refresh the memory.

@ -71,6 +71,9 @@ Print version information.
Load all of the most recent log file types.
.TP
\fB\-r\fR
Recursively load files from the given directories.
.TP
\fB\-R\fR
Load older rotated log files as well.
.TP
\fB\-t\fR

@ -16,7 +16,7 @@ PACKAGE_URLS = \
https://ftp.gnu.org/gnu/readline/readline-6.3.tar.gz \
http://www.zlib.net/zlib-1.2.11.tar.gz \
http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz \
https://sqlite.org/2018/sqlite-autoconf-3260000.tar.gz \
https://sqlite.org/2019/sqlite-autoconf-3270200.tar.gz \
https://www.openssl.org/source/openssl-1.0.2n.tar.gz \
https://www.libssh2.org/download/libssh2-1.8.0.tar.gz \
https://curl.haxx.se/download/curl-7.63.0.tar.gz

@ -36,7 +36,8 @@ arguments to load well-known log files, such as the syslog or apache
log files. The flag arguments are:
-a Load all of the most recent log file types.
-r Load older rotated log files as well.
-r Recursively load files from the given directory hierarchies.
-R Load older rotated log files as well.
When using the flag arguments, lnav will look for the files relative
to the current directory and its parent directories. In other words,

@ -825,7 +825,8 @@ static void usage()
" -V Print version information.\n"
"\n"
" -a Load all of the most recent log file types.\n"
" -r Load older rotated log files as well.\n"
" -r Recursively load files from the given directory hierarchies.\n"
" -R Load older rotated log files as well.\n"
" -t Prepend timestamps to the lines of data being read in\n"
" on the standard input.\n"
" -w file Write the contents of the standard input to this file.\n"
@ -915,6 +916,17 @@ static bool watch_logfile(string filename, logfile_open_options &loo, bool requi
}
if (rc == 0) {
if (S_ISDIR(st.st_mode) && lnav_data.ld_flags & LNF_RECURSIVE) {
string wilddir = filename + "/*";
if (lnav_data.ld_file_names.find(wilddir) ==
lnav_data.ld_file_names.end()) {
logfile_open_options default_loo;
lnav_data.ld_file_names[wilddir] = default_loo;
}
return retval;
}
if (!S_ISREG(st.st_mode)) {
if (required) {
rc = -1;
@ -1843,7 +1855,7 @@ int main(int argc, char *argv[])
#endif
lnav_data.ld_debug_log_name = "/dev/null";
while ((c = getopt(argc, argv, "hHarCc:I:iuf:d:nqtw:vVW")) != -1) {
while ((c = getopt(argc, argv, "hHarRCc:I:iuf:d:nqtw:vVW")) != -1) {
switch (c) {
case 'h':
usage();
@ -1924,10 +1936,14 @@ int main(int argc, char *argv[])
lnav_data.ld_flags |= LNF_QUIET;
break;
case 'r':
case 'R':
lnav_data.ld_flags |= LNF_ROTATED;
break;
case 'r':
lnav_data.ld_flags |= LNF_RECURSIVE;
break;
case 't':
lnav_data.ld_flags |= LNF_TIMESTAMP;
break;

@ -89,6 +89,7 @@ enum {
LNB_HEADLESS,
LNB_QUIET,
LNB_ROTATED,
LNB_RECURSIVE,
LNB_CHECK_CONFIG,
LNB_INSTALL,
LNB_UPDATE_FORMATS,
@ -101,6 +102,7 @@ typedef enum {
LNF_SYSLOG = (1L << LNB_SYSLOG),
LNF_ROTATED = (1L << LNB_ROTATED),
LNF_RECURSIVE = (1L << LNB_RECURSIVE),
LNF_TIMESTAMP = (1L << LNB_TIMESTAMP),
LNF_HELP = (1L << LNB_HELP),

@ -36,7 +36,8 @@ arguments to load well-known log files, such as the syslog or apache
log files. The flag arguments are:
-a Load all of the most recent log file types.
-r Load older rotated log files as well.
-r Recursively load files from the given directory hierarchies.
-R Load older rotated log files as well.
When using the flag arguments, lnav will look for the files relative
to the current directory and its parent directories. In other words,

Loading…
Cancel
Save