mirror of
https://github.com/tstack/lnav.git
synced 2024-09-11 13:05:51 +03:00
[cli] add -r flag for recursively loading files from a directory hierarchy
Fixes #431
This commit is contained in:
parent
8d3b83403c
commit
78d80fddd5
2
NEWS
2
NEWS
@ -42,6 +42,8 @@ lnav v0.8.5:
|
|||||||
you can press TAB cycle through the options.
|
you can press TAB cycle through the options.
|
||||||
* Added CTRL+F to toggle the enabled/disabled state of all filters for the
|
* Added CTRL+F to toggle the enabled/disabled state of all filters for the
|
||||||
current view.
|
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.
|
* 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
|
* Some initial help text is now shown for the search and SQL prompts to
|
||||||
refresh the memory.
|
refresh the memory.
|
||||||
|
3
lnav.1
3
lnav.1
@ -71,6 +71,9 @@ Print version information.
|
|||||||
Load all of the most recent log file types.
|
Load all of the most recent log file types.
|
||||||
.TP
|
.TP
|
||||||
\fB\-r\fR
|
\fB\-r\fR
|
||||||
|
Recursively load files from the given directories.
|
||||||
|
.TP
|
||||||
|
\fB\-R\fR
|
||||||
Load older rotated log files as well.
|
Load older rotated log files as well.
|
||||||
.TP
|
.TP
|
||||||
\fB\-t\fR
|
\fB\-t\fR
|
||||||
|
@ -16,7 +16,7 @@ PACKAGE_URLS = \
|
|||||||
https://ftp.gnu.org/gnu/readline/readline-6.3.tar.gz \
|
https://ftp.gnu.org/gnu/readline/readline-6.3.tar.gz \
|
||||||
http://www.zlib.net/zlib-1.2.11.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 \
|
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.openssl.org/source/openssl-1.0.2n.tar.gz \
|
||||||
https://www.libssh2.org/download/libssh2-1.8.0.tar.gz \
|
https://www.libssh2.org/download/libssh2-1.8.0.tar.gz \
|
||||||
https://curl.haxx.se/download/curl-7.63.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:
|
log files. The flag arguments are:
|
||||||
|
|
||||||
-a Load all of the most recent log file types.
|
-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
|
When using the flag arguments, lnav will look for the files relative
|
||||||
to the current directory and its parent directories. In other words,
|
to the current directory and its parent directories. In other words,
|
||||||
|
22
src/lnav.cc
22
src/lnav.cc
@ -825,7 +825,8 @@ static void usage()
|
|||||||
" -V Print version information.\n"
|
" -V Print version information.\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -a Load all of the most recent log file types.\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"
|
" -t Prepend timestamps to the lines of data being read in\n"
|
||||||
" on the standard input.\n"
|
" on the standard input.\n"
|
||||||
" -w file Write the contents of the standard input to this file.\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 (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 (!S_ISREG(st.st_mode)) {
|
||||||
if (required) {
|
if (required) {
|
||||||
rc = -1;
|
rc = -1;
|
||||||
@ -1843,7 +1855,7 @@ int main(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
lnav_data.ld_debug_log_name = "/dev/null";
|
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) {
|
switch (c) {
|
||||||
case 'h':
|
case 'h':
|
||||||
usage();
|
usage();
|
||||||
@ -1924,10 +1936,14 @@ int main(int argc, char *argv[])
|
|||||||
lnav_data.ld_flags |= LNF_QUIET;
|
lnav_data.ld_flags |= LNF_QUIET;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'R':
|
||||||
lnav_data.ld_flags |= LNF_ROTATED;
|
lnav_data.ld_flags |= LNF_ROTATED;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'r':
|
||||||
|
lnav_data.ld_flags |= LNF_RECURSIVE;
|
||||||
|
break;
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
lnav_data.ld_flags |= LNF_TIMESTAMP;
|
lnav_data.ld_flags |= LNF_TIMESTAMP;
|
||||||
break;
|
break;
|
||||||
|
@ -89,6 +89,7 @@ enum {
|
|||||||
LNB_HEADLESS,
|
LNB_HEADLESS,
|
||||||
LNB_QUIET,
|
LNB_QUIET,
|
||||||
LNB_ROTATED,
|
LNB_ROTATED,
|
||||||
|
LNB_RECURSIVE,
|
||||||
LNB_CHECK_CONFIG,
|
LNB_CHECK_CONFIG,
|
||||||
LNB_INSTALL,
|
LNB_INSTALL,
|
||||||
LNB_UPDATE_FORMATS,
|
LNB_UPDATE_FORMATS,
|
||||||
@ -101,6 +102,7 @@ typedef enum {
|
|||||||
LNF_SYSLOG = (1L << LNB_SYSLOG),
|
LNF_SYSLOG = (1L << LNB_SYSLOG),
|
||||||
|
|
||||||
LNF_ROTATED = (1L << LNB_ROTATED),
|
LNF_ROTATED = (1L << LNB_ROTATED),
|
||||||
|
LNF_RECURSIVE = (1L << LNB_RECURSIVE),
|
||||||
|
|
||||||
LNF_TIMESTAMP = (1L << LNB_TIMESTAMP),
|
LNF_TIMESTAMP = (1L << LNB_TIMESTAMP),
|
||||||
LNF_HELP = (1L << LNB_HELP),
|
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:
|
log files. The flag arguments are:
|
||||||
|
|
||||||
-a Load all of the most recent log file types.
|
-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
|
When using the flag arguments, lnav will look for the files relative
|
||||||
to the current directory and its parent directories. In other words,
|
to the current directory and its parent directories. In other words,
|
||||||
|
Loading…
Reference in New Issue
Block a user