From 00651ec4495188a8b0d50842d216f2fb1fc09076 Mon Sep 17 00:00:00 2001 From: PhiBo Date: Mon, 9 Dec 2024 10:31:50 +0100 Subject: [PATCH] src - Add text format --- docs/config/output/format.md | 6 +++++ .../output/format/format_text.py | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 routeros_log_exporter/output/format/format_text.py diff --git a/docs/config/output/format.md b/docs/config/output/format.md index 7a60320..67ea3e8 100644 --- a/docs/config/output/format.md +++ b/docs/config/output/format.md @@ -1,5 +1,11 @@ # Output Format +## Text + +::: routeros_log_exporter.output.format.format_text + options: + show_root_toc_entry: false + ## JSON ::: routeros_log_exporter.output.format.format_json diff --git a/routeros_log_exporter/output/format/format_text.py b/routeros_log_exporter/output/format/format_text.py new file mode 100644 index 0000000..e1092e2 --- /dev/null +++ b/routeros_log_exporter/output/format/format_text.py @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: PhiBo DinoTools (2024) +# SPDX-License-Identifier: GPL-3.0-or-later +""" +This format plugin renders the plan log message as string. Every message is one line. + +```yaml +outputs: + log_file: + type: file + # Format of the log messages + format: text +``` +""" + +from . import Format + + +class TextFormat(Format): + def process(self, data): + return f"{data.get('message_time')} {','.join(data.get('message_topics', []))} {data.get('message')}\n" + + +Format.register("text", TextFormat)