mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
86 lines
2.2 KiB
Markdown
86 lines
2.2 KiB
Markdown
![]() |
[Home](https://kellyjonbrazil.github.io/jc/)
|
||
|
<a id="jc.parsers.clf"></a>
|
||
|
|
||
|
# jc.parsers.clf
|
||
|
|
||
|
jc - JSON Convert Common Log Format file parser
|
||
|
|
||
|
This parser will handle the Common Log Format standard as specified at
|
||
|
https://www.w3.org/Daemon/User/Config/Logging.html#common-logfile-format.
|
||
|
Extra fields may be present and will be enclosed in the `extra` field as
|
||
|
a single string.
|
||
|
|
||
|
Usage (cli):
|
||
|
|
||
|
$ cat file.log | jc --clf
|
||
|
|
||
|
Usage (module):
|
||
|
|
||
|
import jc
|
||
|
result = jc.parse('clf', common_log_file_output)
|
||
|
|
||
|
Schema:
|
||
|
|
||
|
[
|
||
|
{
|
||
|
"host": string,
|
||
|
"ident": string,
|
||
|
"authuser": string,
|
||
|
"date": string,
|
||
|
"day": integer,
|
||
|
"month": string,
|
||
|
"year": integer,
|
||
|
"hour": integer,
|
||
|
"minute": integer,
|
||
|
"second": integer,
|
||
|
"tz": string,
|
||
|
"request": string,
|
||
|
"request_method": string,
|
||
|
"request_url": string,
|
||
|
"request_version": string,
|
||
|
"status": integer,
|
||
|
"bytes": integer,
|
||
|
"extra": string,
|
||
|
"epoch": integer, # [0]
|
||
|
"epoch_utc": integer # [1]
|
||
|
}
|
||
|
]
|
||
|
|
||
|
[0] naive timestamp
|
||
|
[1] timezone-aware timestamp. Only available if timezone field is UTC
|
||
|
|
||
|
Examples:
|
||
|
|
||
|
$ cat file.log | jc --clf -p
|
||
|
[]
|
||
|
|
||
|
$ cat file.log | jc --clf -p -r
|
||
|
[]
|
||
|
|
||
|
<a id="jc.parsers.clf.parse"></a>
|
||
|
|
||
|
### parse
|
||
|
|
||
|
```python
|
||
|
def parse(data: str,
|
||
|
raw: bool = False,
|
||
|
quiet: bool = False) -> List[JSONDictType]
|
||
|
```
|
||
|
|
||
|
Main text parsing function
|
||
|
|
||
|
Parameters:
|
||
|
|
||
|
data: (string) text data to parse
|
||
|
raw: (boolean) unprocessed output if True
|
||
|
quiet: (boolean) suppress warning messages if True
|
||
|
|
||
|
Returns:
|
||
|
|
||
|
List of Dictionaries. Raw or processed structured data.
|
||
|
|
||
|
### Parser Information
|
||
|
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
|
||
|
|
||
|
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)
|