Skip to content

Commit 185677e

Browse files
authored
readme
1 parent f66ff2d commit 185677e

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

README.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Rust log parser
2+
3+
A CLI tool to parse log files and convert every line to a json, output certain values from logs
4+
5+
## Config file
6+
7+
Config file defines the pattern to look for and what all are the matches.
8+
9+
Sample config file:
10+
11+
```
12+
{
13+
"regex": "^(\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}) \\[(\\S+ \\+\\d{4})\\] \"(GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH) (\\S+) (\\S+)\" (\\d{3}) \"rt=(\\S+)\" \"(\\S+)\" \"(.*)\"$",
14+
"matches": {
15+
"1": "ip",
16+
"2": "date",
17+
"3": "method",
18+
"4": "path",
19+
"5": "version",
20+
"6": "code",
21+
"7": "rt",
22+
"8": "referer",
23+
"9": "ua"
24+
}
25+
}
26+
27+
```
28+
`matches` key provides names to the regex matches, this name can be used for filtering the output.
29+
30+
### Building
31+
32+
33+
### Usage
34+
35+
#### Arguments
36+
`-i: Log file to read, default is stdin`
37+
38+
`-f: output format,default is json. It should be one of the value from the matches hash in config file.`
39+
40+
`-c: config file`
41+
42+
`-s: exit program upon receiving a line which cannot be parsed with the regex provided.`
43+
44+
45+
### Example
46+
47+
access.log
48+
```
49+
34.193.53.146 [11/Feb/2019:10:35:02 +0000] "GET /index.html HTTP/1.1" 200 "rt=0.016" "https://google.com/" "Google UA"
50+
182.72.211.138 [11/Feb/2019:10:35:06 +0000] "GET /stats.json HTTP/2.0" 200 "rt=0.047" "https://amagi.com/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36"
51+
```
52+
53+
```
54+
> parser -i access.log -c config.json
55+
56+
{"code":"200","date":"11/Feb/2019:10:35:02 +0000","ip":"34.193.53.146","method":"GET","path":"/index.html","referer":"https://google.com/","rt":"0.016","ua":"Google UA","version":"HTTP/1.1"}
57+
{"code":"200","date":"11/Feb/2019:10:35:06 +0000","ip":"182.72.211.138","method":"GET","path":"/stats.json","referer":"https://amagi.com/index.html","rt":"0.047","ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36","version":"HTTP/2.0"}
58+
```
59+
60+
61+
```
62+
> parser -i access.log -c config.json -f ua
63+
Google UA
64+
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36
65+
```

0 commit comments

Comments
 (0)