From e9416626449bb9f4b28f587051d77745810c355c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Uhl=C3=AD=C5=99?= Date: Thu, 28 Mar 2024 16:36:38 +0100 Subject: [PATCH 1/2] docs: optional parameters documentation --- README.md | 17 +++++++++++++++++ cmd/cmd.go | 5 ++++- ui/modal_help.go | 4 ++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3b72ac5..a7be2d4 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,23 @@ Flags: -n, --pattern-name string use predefined pattern in config ``` +### Optional parameters + +It might be the case that your logs have different sections outputted for different type of events. For example for HTTP +requests you include HTTP code but for background processing logs you don't include the code. + +It is possible to write parsing pattern that includes optional parameters with using: + +- disabling the regex escaping with `-r/--disable-regex-escape` option +- using non-capturing groups as `(?:)` with trailing optional quantifier `?` + +Example: + +```regexp +time="" level=(?: code=)? + +``` + ## Contribute PRs are welcome! diff --git a/cmd/cmd.go b/cmd/cmd.go index 3095cd7..22f3a67 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -27,8 +27,11 @@ const ( DEFAULT_BUFFER_SIZE = 10000 ) -var LONG_DESCRIPTION = fmt.Sprintf(`By default loggy reads from STDIN or you can specify file path to read the logs from specific file. +var LONG_DESCRIPTION = fmt.Sprintf(` +Loggy is a swiss knife for working with logs. +It stores the logs in internal buffer which allows it to do all sort of operations on top of them without the need to rerun the log's producing program or store them in file. +By default loggy reads from STDIN or you can specify file path to read the logs from specific file. You quit the application by pressing Ctrl+C. Configuration diff --git a/ui/modal_help.go b/ui/modal_help.go index 1d380cb..95c9078 100644 --- a/ui/modal_help.go +++ b/ui/modal_help.go @@ -55,7 +55,7 @@ var HelpInputsText = `Input fields: - Ctrl-W: Delete the last word before the cursor. - Ctrl-U: Delete the entire line.` -var HelpParsingPatternText = fmt.Sprintf(`The logs are parsed using parsing pattern that you have to configure in order to use filters. The lines are tokenized using space character. Internally regex is used for parsing, but the input pattern is escaped by default for special characters so you don't have to worry about special characters. You define parameters using syntax "", where name is the name of parameter that you can refer to in filters and type is predefined type used to correctly find and parse the parameter. +var HelpParsingPatternText = fmt.Sprintf(`The logs are parsed using parsing pattern that you have to configure in order to use filters. Internally regex is used for parsing. By default the input pattern is escaped for special characters, but if you need to do some advance parsing then you can disable the escaping using -r/--disable-regex-escape flag. You define parameters using syntax "", where name is the name of parameter that you can refer to in filters and type is predefined type used to correctly find and parse the parameter. You can omit "type" in which case the "string" type will be used. Lines that were not possible to parsed are colored with red color. Moreover counter of how many lines were not possible to parse is displayed in the status bar on the right end of it. It is only present if there are some lines that were not possible to parse. @@ -87,7 +87,7 @@ loggy uses internally "expr" which has very rich set of arithmetic/string operat - ternary conditional: ? : - built in functions: len() all() none() any() one() filter() map() count() -For more details see: https://github.com/antonmedv/expr/blob/master/docs/Language-Definition.md +For more details see: https://expr-lang.org/docs/language-definition Example of filter for the parsing pattern log above: level == "DEBUG" - display only debug messages From fb24ef67d3d9c8722bf0f3baafe0ba14463f93fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Uhl=C3=AD=C5=99?= Date: Thu, 28 Mar 2024 17:13:38 +0100 Subject: [PATCH 2/2] docs: more docs tweaks --- cmd/cmd.go | 12 +++++++++--- ui/modal_help.go | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 22f3a67..8ac771b 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -27,8 +27,14 @@ const ( DEFAULT_BUFFER_SIZE = 10000 ) -var LONG_DESCRIPTION = fmt.Sprintf(` -Loggy is a swiss knife for working with logs. +var LONG_DESCRIPTION = fmt.Sprintf(` _ +| | ___ __ _ __ _ _ _ +| |/ _ \ / _`+"`"+` |/ _`+"`"+` | | | | +| | (_) | (_| | (_| | |_| | +|_|\___/ \__, |\__, |\__, | + |___/ |___/ |___/ + +Loggy v%s is a swiss knife for working with logs. It stores the logs in internal buffer which allows it to do all sort of operations on top of them without the need to rerun the log's producing program or store them in file. By default loggy reads from STDIN or you can specify file path to read the logs from specific file. @@ -60,7 +66,7 @@ Keyboard shortcuts %s %s -`, ui.HelpParsingPatternText, ui.HelpFilterText, ui.HelpHomeText, ui.HelpNavigationText, ui.HelpInputsText) +`, ui.Version, ui.HelpParsingPatternText, ui.HelpFilterText, ui.HelpHomeText, ui.HelpNavigationText, ui.HelpInputsText) var cfgFile string diff --git a/ui/modal_help.go b/ui/modal_help.go index 95c9078..9176568 100644 --- a/ui/modal_help.go +++ b/ui/modal_help.go @@ -26,7 +26,7 @@ Status bar on top displays several helpful information. Describing from left to - Input name - Optional "F" indicator that shows if loggy is following the end of the logs - Filter status that displays "/". If it has green background than filter is applied otherwise is turned off or not set. - - Optional number of lines that were not possible to match against the parsing pattern.s + - Optional number of lines that were not possible to match against the parsing pattern. Main key shortcuts: - "%s" for setting filter