Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: optional parameters documentation #36

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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="<alwaysPressentTime>" level=<alwaysPresentLevel>(?: code=<optionalCode>)?

```

## Contribute

PRs are welcome!
Expand Down
13 changes: 11 additions & 2 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@ 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 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.
You quit the application by pressing Ctrl+C.

Configuration
Expand Down Expand Up @@ -57,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

Expand Down
6 changes: 3 additions & 3 deletions ui/modal_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<number of filter matching lines>/<number of total lines>". 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:
- "%<filter>s" for setting filter
Expand Down Expand Up @@ -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 "<name:type>", 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 "<name:type>", 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.

Expand Down Expand Up @@ -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
Expand Down
Loading