Loaders¶
Predefined Loaders¶
Bro/Zeek log loader.
-
class
zlogging.loader.JSONParser(model=None)¶ Bases:
zlogging.loader.BaseParserJSON log parser.
- Parameters
model (
Modelclass, optional) – Field declrations forJSONParser, as in JSON logs the field typing information are omitted by the Bro/Zeek logging framework.- Variables
model (
Modelclass, optional) – Field declrations forJSONParser, as in JSON logs the field typing information are omitted by the Bro/Zeek logging framework.- Warns
JSONParserWarning – If
modelis not specified.
-
property
format¶ str: Log file format.
-
parse_file(file)¶ Parse log file.
-
parse_line(line, lineno=0)¶ Parse log line as one-line record.
- Parameters
line (bytes) – A simple line of log.
lineno (Optional[int]) – Line number of current line.
- Returns
The parsed log as a plain
dict.- Raises
JSONParserError – If failed to serialise the
linefrom JSON.- Return type
Dict[str, Any]
-
class
zlogging.loader.ASCIIParser(type_hook=None, enum_namespaces=None, bare=False)¶ Bases:
zlogging.loader.BaseParserASCII log parser.
- Parameters
- Variables
__type__ (
dictmappingstrandBaseTypeclass) – Bro/Zeek type parser hooks.enum_namespaces (
List[str]) – Namespaces to be loaded.bare (bool) – If
True, do not loadzeeknamespace by default.
-
property
format¶ str: Log file format.
-
parse_file(file)¶ Parse log file.
- Parameters
file (_io.BufferedReader) – Log file object opened in binary mode.
- Returns
- The parsed log as a
Modelper line.
- Return type
- Warns
ASCIIParserWarning – If the ASCII log file exited with error, see
ASCIIInfo.exit_with_errorfor more information.
-
parse_line(line, lineno=0, separator=b'\t', parser=None)¶ Parse log line as one-line record.
- Parameters
line (bytes) – A simple line of log.
lineno (Optional[int]) – Line number of current line.
separator (Optional[bytes]) – Data separator.
parser (
ListofBaseType, required) – Field data type parsers.
- Returns
The parsed log as a plain
dict.- Raises
ASCIIPaserError – If
parseris not provided; or failed to serialiselineas ASCII.- Return type
Dict[str, Any]
-
zlogging.loader.parse_json(filename, parser=None, model=None, *args, **kwargs)¶ Parse JSON log file.
- Parameters
filename (os.PathLike) – Log file name.
parser (
JSONParser, optional) – Parser class.model (
Modelclass, optional) – Field declarations forJSONParser, as in JSON logs the field typing information are omitted by the Bro/Zeek logging framework.*args – Variable length argument list.
**kwargs – Arbitrary keyword arguments.
- Returns
The parsed JSON log data.
- Return type
-
zlogging.loader.load_json(file, parser=None, model=None, *args, **kwargs)¶ Parse JSON log file.
- Parameters
file (_io.BufferedReader) – Log file object opened in binary mode.
parser (
JSONParser, optional) – Parser class.model (
Modelclass, optional) – Field declarations forJSONParser, as in JSON logs the field typing information are omitted by the Bro/Zeek logging framework.*args – Variable length argument list.
**kwargs – Arbitrary keyword arguments.
- Returns
The parsed JSON log data.
- Return type
-
zlogging.loader.loads_json(data, parser=None, model=None, *args, **kwargs)¶ Parse JSON log string.
- Parameters
data (AnyStr) – Log string as binary or encoded string.
parser (
JSONParser, optional) – Parser class.model (
Modelclass, optional) – Field declarations forJSONParser, as in JSON logs the field typing information are omitted by the Bro/Zeek logging framework.*args – Variable length argument list.
**kwargs – Arbitrary keyword arguments.
- Returns
The parsed JSON log data.
- Return type
-
zlogging.loader.parse_ascii(filename, parser=None, type_hook=None, enum_namespaces=None, bare=False, *args, **kwargs)¶ Parse ASCII log file.
- Parameters
filename (os.PathLike) – Log file name.
parser (
ASCIIParser, optional) – Parser class.type_hook (
dictmappingstrandBaseTypeclass, optional) – Bro/Zeek type parser hooks. User may customise subclasses ofBaseTypeto modify parsing behaviours.enum_namespaces (
List[str], optional) – Namespaces to be loaded.bare (
bool, optional) – IfTrue, do not loadzeeknamespace by default.*args – Variable length argument list.
**kwargs – Arbitrary keyword arguments.
- Returns
The parsed ASCII log data.
- Return type
-
zlogging.loader.load_ascii(file, parser=None, type_hook=None, enum_namespaces=None, bare=False, *args, **kwargs)¶ Parse ASCII log file.
- Parameters
file (_io.BufferedReader) – Log file object opened in binary mode.
parser (
ASCIIParser, optional) – Parser class.type_hook (
dictmappingstrandBaseTypeclass, optional) – Bro/Zeek type parser hooks. User may customise subclasses ofBaseTypeto modify parsing behaviours.enum_namespaces (
List[str], optional) – Namespaces to be loaded.bare (
bool, optional) – IfTrue, do not loadzeeknamespace by default.*args – Variable length argument list.
**kwargs – Arbitrary keyword arguments.
- Returns
The parsed ASCII log data.
- Return type
-
zlogging.loader.loads_ascii(data, parser=None, type_hook=None, enum_namespaces=None, bare=False, *args, **kwargs)¶ Parse ASCII log string.
- Parameters
data (AnyStr) – Log string as binary or encoded string.
parser (
ASCIIParser, optional) – Parser class.type_hook (
dictmappingstrandBaseTypeclass, optional) – Bro/Zeek type parser hooks. User may customise subclasses ofBaseTypeto modify parsing behaviours.enum_namespaces (
List[str], optional) – Namespaces to be loaded.bare (
bool, optional) – IfTrue, do not loadzeeknamespace by default.*args – Variable length argument list.
**kwargs – Arbitrary keyword arguments.
- Returns
The parsed ASCII log data.
- Return type
-
zlogging.loader.parse(filename, *args, **kwargs)¶ Parse Bro/Zeek log file.
- Parameters
filename (os.PathLike) – Log file name.
*args – See
parse_json()andparse_ascii()for more information.**kwargs – See
parse_json()andparse_ascii()for more information.
- Returns
The parsed JSON log data.
- Raises
ParserError – If the format of the log file is unknown.
- Return type
-
zlogging.loader.load(file, *args, **kwargs)¶ Parse Bro/Zeek log file.
- Parameters
file (_io.BufferedReader) – Log file object opened in binary mode.
*args – See
load_json()andload_ascii()for more information.**kwargs – See
load_json()andload_ascii()for more information.
- Returns
The parsed JSON log data.
- Raises
ParserError – If the format of the log file is unknown.
- Return type
-
zlogging.loader.loads(data, *args, **kwargs)¶ Parse Bro/Zeek log string.
- Parameters
data (AnyStr) – Log string as binary or encoded string.
*args – See
loads_json()andloads_ascii()for more information.**kwargs – See
loads_json()andloads_ascii()for more information.
- Returns
The parsed JSON log data.
- Raises
ParserError – If the format of the log file is unknown.
- Return type
Abstract Base Loaders¶
-
class
zlogging.loader.BaseParser¶ Bases:
objectBasic log parser.
-
abstract property
format¶ str: Log file format.
-
parse(filename)¶ Parse log file.
- Parameters
filename (os.PathLike) – Log file name.
- Returns
- Return type
-
abstract
parse_file(file)¶ Parse log file.
-
abstract
parse_line(line, lineno=0)¶ Parse log line as one-line record.
- Parameters
line (bytes) – A simple line of log.
lineno (Optional[int]) – Line number of current line.
- Returns
The parsed log as a plain
dict.- Return type
Dict[str, Any]
-
load(file)¶ Parse log file.
-
loads(line, lineno=0)¶ Parse log line as one-line record.
- Parameters
line (bytes) – A simple line of log.
lineno (Optional[int]) – Line number of current line.
- Returns
The parsed log as a plain
dict.- Return type
Dict[str, Any]
-
abstract property