Log Dumpers¶
Functional Interfaces¶
General APIs¶
- zlogging.dumper.write(data, filename, format, *args, **kwargs)[source]¶
Write Bro/Zeek log file.
- Parameters:
data (
Iterable
[Model
]) – Log records as anIterable
ofModel
per line.format (
str
) – Log format.*args (
Any
) – Seewrite_json()
andwrite_ascii()
for more information.**kwargs (
Any
) – Seewrite_json()
andwrite_ascii()
for more information.
- Raises:
WriterFormatError – If
format
is not supported.- Return type:
- zlogging.dumper.dumps(data, format, *args, **kwargs)[source]¶
Write Bro/Zeek log string.
- Parameters:
data (
Iterable
[Model
]) – Log records as anIterable
ofModel
per line.format (
str
) – Log format.*args (
Any
) – Seedumps_json()
anddumps_ascii()
for more information.**kwargs (
Any
) – Seedumps_json()
anddumps_ascii()
for more information.
- Raises:
WriterFormatError – If
format
is not supported.- Return type:
- zlogging.dumper.dump(data, file, format, *args, **kwargs)[source]¶
Write Bro/Zeek log file.
- Parameters:
data (
Iterable
[Model
]) – Log records as anIterable
ofModel
per line.format (
str
) – Log format.file (
TextIOWrapper
) – Log file object opened in text mode.*args (
Any
) – Seedump_json()
anddump_ascii()
for more information.**kwargs (
Any
) – Seedump_json()
anddump_ascii()
for more information.
- Raises:
WriterFormatError – If
format
is not supported.- Return type:
ASCII Format¶
- zlogging.dumper.write_ascii(data, filename, writer=None, separator=None, empty_field=None, unset_field=None, set_separator=None, *args, **kwargs)[source]¶
Write ASCII log file.
- Parameters:
data (
Iterable
[Model
]) – Log records as anIterable
ofModel
per line.writer (
Optional
[Type
[ASCIIWriter
]]) – Writer class.separator (
Union
[str
,bytes
,None
]) – Field separator when writing log lines.empty_field (
Union
[str
,bytes
,None
]) – Placeholder for empty field.unset_field (
Union
[str
,bytes
,None
]) – Placeholder for unset field.set_separator (
Union
[str
,bytes
,None
]) – Separator forset
/vector
fields.*args (
Any
) – Arbitrary positional arguments.**kwargs (
Any
) – Arbitrary keyword arguments.
- Return type:
- zlogging.dumper.dumps_ascii(data=None, writer=None, separator=None, empty_field=None, unset_field=None, set_separator=None, *args, **kwargs)[source]¶
Write ASCII log string.
- Parameters:
data (
Optional
[Iterable
[Model
]]) – Log records as anIterable
ofModel
per line.writer (
Optional
[Type
[ASCIIWriter
]]) – Writer class.separator (
Union
[str
,bytes
,None
]) – Field separator when writing log lines.empty_field (
Union
[str
,bytes
,None
]) – Placeholder for empty field.unset_field (
Union
[str
,bytes
,None
]) – Placeholder for unset field.set_separator (
Union
[str
,bytes
,None
]) – Separator forset
/vector
fields.*args (
Any
) – Arbitrary positional arguments.**kwargs (
Any
) – Arbitrary keyword arguments.
- Return type:
- Returns:
The JSON log string.
- zlogging.dumper.dump_ascii(data, file, writer=None, separator=None, empty_field=None, unset_field=None, set_separator=None, *args, **kwargs)[source]¶
Write ASCII log file.
- Parameters:
data (
Iterable
[Model
]) – Log records as anIterable
ofModel
per line.file (
TextIOWrapper
) – Log file object opened in text mode.writer (
Optional
[Type
[ASCIIWriter
]]) – Writer class.separator (
Union
[str
,bytes
,None
]) – Field separator when writing log lines.empty_field (
Union
[str
,bytes
,None
]) – Placeholder for empty field.unset_field (
Union
[str
,bytes
,None
]) – Placeholder for unset field.set_separator (
Union
[str
,bytes
,None
]) – Separator forset
/vector
fields.*args (
Any
) – Arbitrary positional arguments.**kwargs (
Any
) – Arbitrary keyword arguments.
- Return type:
JSON Format¶
- zlogging.dumper.write_json(data, filename, writer=None, encoder=None, *args, **kwargs)[source]¶
Write JSON log file.
- zlogging.dumper.dumps_json(data=None, writer=None, encoder=None, *args, **kwargs)[source]¶
Write JSON log string.
- Parameters:
- Return type:
- Returns:
The JSON log string.
- zlogging.dumper.dump_json(data, file, writer=None, encoder=None, *args, **kwargs)[source]¶
Write JSON log file.
- Parameters:
data (
Iterable
[Model
]) – Log records as anIterable
ofModel
per line.file (
TextIOWrapper
) – Log file object opened in text mode.writer (
Optional
[Type
[JSONWriter
]]) – Writer class.*args (
Any
) – Arbitrary positional arguments.**kwargs (
Any
) – Arbitrary keyword arguments.
- Return type:
Predefined Dumpers¶
- class zlogging.dumper.ASCIIWriter(separator=None, empty_field=None, unset_field=None, set_separator=None)[source]¶
Bases:
BaseWriter
ASCII log writer.
- Parameters:
- write_line(file, data, lineno=0)[source]¶
Write log line as one-line record.
- Parameters:
file (
TextIOWrapper
) – Log file object opened in text mode.data (
Model
) – Log record.
- Return type:
- Returns:
The file offset after writing.
- Raises:
ASCIIWriterError – If failed to serialise
data
as ASCII.
- write_head(file, data=None)[source]¶
Write header fields of ASCII log file.
- Parameters:
file (
TextIOWrapper
) – Log file object opened in text mode.
- Return type:
- Returns:
The file offset after writing.
- write_tail(file)[source]¶
Write trailing fields of ASCII log file.
- Parameters:
file (
TextIOWrapper
) – Log file object opened in text mode.- Return type:
- Returns:
The file offset after writing.
- dump_line(data, lineno=0)[source]¶
Serialise one-line record to a log line.
- Parameters:
- Return type:
- Returns:
The converted log string.
- Raises:
ASCIIWriterError – If failed to serialise
data
as ASCII.
- class zlogging.dumper.JSONWriter(encoder=None)[source]¶
Bases:
BaseWriter
JSON log writer.
- write_line(file, data, lineno=0)[source]¶
Write log line as one-line record.
- Parameters:
file (
TextIOWrapper
) – Log file object opened in text mode.data (
Model
) – Log record.
- Return type:
- Returns:
The file offset after writing.
- Raises:
JSONWriterError – If failed to serialise
data
as JSON.
Abstract Base Dumper¶
- class zlogging.dumper.BaseWriter[source]¶
Bases:
object
Basic log writer.
- abstract write_line(file, data, lineno=0)[source]¶
Write log line as one-line record.
- Parameters:
file (
TextIOWrapper
) – Log file object opened in text mode.data (
Model
) – Log record.
- Return type:
- Returns:
The file offset after writing.