You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Download on to your `$PATH` loggy binary for your operating system and architecture
48
+
from [latest release](https://github.com/auhau/loggy/releases/latest) page.
49
+
50
+
## Usage
51
+
52
+
See `loggy --help` for this usage:
53
+
54
+
```
55
+
By default loggy reads from STDIN or you can specify file path to read the logs from specific file.
56
+
57
+
Configuration
58
+
-------------
59
+
All options that can be passed using CLI flags can be configured using config file or environment variables.
60
+
loggy looks for a config file ".loggy.toml" in current working directory and in $HOME folder.
61
+
Moreover you can use environment variables with "LOGGY_" prefix, where for example flag "--pattern" would be "LOGGY_PATTERN" env. variable.
62
+
The order of precedence is: $HOME config > CWD config > --config config > Env. variables > CLI flags.
63
+
64
+
Parsing pattern
65
+
---------------
66
+
The logs are parsed using parsing pattern that you have to configure in order to use filters. The lines are tokenized using space character so you have to define section of the line. 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 that. 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.
In your config file you can create a [patterns] section where you can predefine your patterns using <name>="<pattern>" syntax and then use --pattern-name/-n flag to use it.
80
+
81
+
Filter
82
+
------
83
+
In order to use filter for the logs you have to define parsing pattern in which you define parameters that are extracted from the log lines. Then you can write filter expressions that will be applied on the logs. Filter has to return bool otherwise error will be shown.
84
+
85
+
loggy uses internally "govaluate" which has very rich set ofC-like artithmetic/string expressions that you can use for your filters. Brief overview:
86
+
- modifiers: + - / * & | ^ ** % >> <<
87
+
- comparators: > >= < <= == != =~ !~
88
+
- logical ops: || &&
89
+
- numeric constants, as 64-bit floating point (12345.678)
90
+
- string constants (single quotes: 'foobar')
91
+
- date constants (single quotes, using any permutation of RFC3339, ISO8601, ruby date, or unix date; date parsing is automatically tried with any string constant)
92
+
- boolean constants: true false
93
+
- parenthesis to control order of evaluation ( )
94
+
- arrays (anything separated by , within parenthesis: (1, 2, 'foo'))
95
+
- prefixes: ! - ~
96
+
- ternary conditional: ? :
97
+
- null coalescence: ??
98
+
99
+
For more details see: https://github.com/Knetic/govaluate/blob/master/MANUAL.md
100
+
101
+
Example of filter for the parsing pattern log above:
102
+
level == "DEBUG" - display only debug messages
103
+
code > 400 - display logs with code higher then 400
104
+
105
+
Keyboard shortcuts
106
+
------------------
107
+
Following keys are supported:
108
+
- "/" for setting filter
109
+
- "f" for toggling filter
110
+
- "p" for setting parsing pattern input
111
+
- "b" for scroll to bottom and follow new data
112
+
- "h" for displaying help
113
+
114
+
Navigation:
115
+
- "j", "k" or arrow keys for scrolling by one line
116
+
- "g", "G" to move to top / bottom
117
+
- "Ctrl-F", "page down" to move down by one page
118
+
- "Ctrl-B", "page up" to move up by one page
119
+
- "Ctrl-C" to exit loggy
120
+
121
+
Usage:
122
+
loggy [path to log file] [flags]
123
+
124
+
Flags:
125
+
-b, --buffer-size int number of lines that will be buffered (default 10000)
126
+
--config string config file (default is $HOME/.loggy.yaml)
127
+
-h, --help help for loggy
128
+
-p, --pattern string parsing pattern see above for details
129
+
-n, --pattern-name string use predefined pattern in config
130
+
```
131
+
132
+
## Contribute
133
+
134
+
PRs are welcome!
135
+
If you plan to make some bigger change then please discuss it previously in Issue so there would not be any
Copy file name to clipboardExpand all lines: cmd/cmd.go
+84-21Lines changed: 84 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,7 @@ import (
4
4
"fmt"
5
5
"github.com/auhau/loggy/store"
6
6
"github.com/auhau/loggy/ui"
7
+
"github.com/chonla/format"
7
8
"io"
8
9
"os"
9
10
@@ -24,6 +25,73 @@ const (
24
25
DEFAULT_BUFFER_SIZE=10000
25
26
)
26
27
28
+
varLONG_DESCRIPTION=format.Sprintf(`By default loggy reads from STDIN or you can specify file path to read the logs from specific file.
29
+
30
+
Configuration
31
+
-------------
32
+
All options that can be passed using CLI flags can be configured using config file or environment variables.
33
+
loggy looks for a config file ".loggy.toml" in current working directory and in $HOME folder.
34
+
Moreover you can use environment variables with "LOGGY_" prefix, where for example flag "--pattern" would be "LOGGY_PATTERN" env. variable.
35
+
The order of precedence is: $HOME config > CWD config > --config config > Env. variables > CLI flags.
36
+
37
+
Parsing pattern
38
+
---------------
39
+
The logs are parsed using parsing pattern that you have to configure in order to use filters. The lines are tokenized using space character so you have to define section of the line. 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 that. 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.
In your config file you can create a [patterns] section where you can predefine your patterns using <name>="<pattern>" syntax and then use --pattern-name/-n flag to use it.
53
+
54
+
Filter
55
+
------
56
+
In order to use filter for the logs you have to define parsing pattern in which you define parameters that are extracted from the log lines. Then you can write filter expressions that will be applied on the logs. Filter has to return bool otherwise error will be shown.
57
+
58
+
loggy uses internally "govaluate" which has very rich set ofC-like artithmetic/string expressions that you can use for your filters. Brief overview:
59
+
- modifiers: + - / * & | ^ ** %% >> <<
60
+
- comparators: > >= < <= == != =~ !~
61
+
- logical ops: || &&
62
+
- numeric constants, as 64-bit floating point (12345.678)
63
+
- string constants (single quotes: 'foobar')
64
+
- date constants (single quotes, using any permutation of RFC3339, ISO8601, ruby date, or unix date; date parsing is automatically tried with any string constant)
65
+
- boolean constants: true false
66
+
- parenthesis to control order of evaluation ( )
67
+
- arrays (anything separated by , within parenthesis: (1, 2, 'foo'))
68
+
- prefixes: ! - ~
69
+
- ternary conditional: ? :
70
+
- null coalescence: ??
71
+
72
+
For more details see: https://github.com/Knetic/govaluate/blob/master/MANUAL.md
73
+
74
+
Example of filter for the parsing pattern log above:
75
+
level == "DEBUG" - display only debug messages
76
+
code > 400 - display logs with code higher then 400
77
+
78
+
Keyboard shortcuts
79
+
------------------
80
+
Following keys are supported:
81
+
- "%<filter>s" for setting filter
82
+
- "%<toggleFilter>s" for toggling filter
83
+
- "%<pattern>s" for setting parsing pattern input
84
+
- "%<follow>s" for scroll to bottom and follow new data
85
+
- "%<help>s" for displaying help
86
+
87
+
Navigation:
88
+
- "j", "k" or arrow keys for scrolling by one line
89
+
- "g", "G" to move to top / bottom
90
+
- "Ctrl-F", "page down" to move down by one page
91
+
- "Ctrl-B", "page up" to move up by one page
92
+
- "Ctrl-C" to exit loggy
93
+
`, ui.KEY_MAP)
94
+
27
95
varcfgFilestring
28
96
29
97
// TODO: Add option to turn off Regex escaping
@@ -35,7 +103,7 @@ var cfgFile string
35
103
varcmd=&cobra.Command{
36
104
Use: "loggy [path to log file]",
37
105
Short: "Swiss knife for logs",
38
-
Long: `By default reads from STDIN or you can specify file path to read logs from`,
106
+
Long: LONG_DESCRIPTION,
39
107
Args: cobra.MaximumNArgs(1),
40
108
Version: ui.Version,
41
109
Run: func(cmd*cobra.Command, args []string) {
@@ -95,33 +163,28 @@ func init() {
95
163
96
164
// initConfig reads in config file and ENV variables if set.
97
165
funcinitConfig() {
98
-
ifcfgFile!="" {
99
-
// Use config file from the flag.
100
-
viper.SetConfigFile(cfgFile)
101
-
} else {
102
-
// Find home directory.
103
-
home, err:=os.UserHomeDir()
104
-
cobra.CheckErr(err)
166
+
viper.SetConfigType("toml")
167
+
viper.SetConfigName(".loggy")
105
168
106
-
// Get current directory.
107
-
currentDirectory, err:=os.Getwd()
108
-
cobra.CheckErr(err)
169
+
// Home directory config
170
+
home, err:=os.UserHomeDir()
171
+
cobra.CheckErr(err)
172
+
viper.AddConfigPath(home)
173
+
_=viper.ReadInConfig() // if no config is found we don't care
109
174
110
-
// Search config in home directory and CWD with name ".loggy.toml"
111
-
viper.AddConfigPath(home)
112
-
viper.AddConfigPath(currentDirectory)
113
-
viper.SetConfigType("toml")
114
-
viper.SetConfigName(".loggy")
175
+
// Get current directory config
176
+
viper.AddConfigPath(".")
177
+
cobra.CheckErr(viper.MergeInConfig())
178
+
179
+
// Config file from the flag.
180
+
ifcfgFile!="" {
181
+
viper.SetConfigFile(cfgFile)
182
+
cobra.CheckErr(viper.MergeInConfig())
115
183
}
116
184
117
185
viper.SetEnvPrefix("loggy")
118
186
viper.AutomaticEnv() // read in environment variables that match
0 commit comments