From 834953b6355cd5f24470afd8f5cd77a4d46c4e1d Mon Sep 17 00:00:00 2001 From: Fenris Wolf Date: Thu, 25 Sep 2025 16:35:22 +0200 Subject: [PATCH] [mod] logging --- source/conf.ts | 12 +++++++++- source/main.ts | 64 +++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/source/conf.ts b/source/conf.ts index 537d357..f984923 100644 --- a/source/conf.ts +++ b/source/conf.ts @@ -41,7 +41,17 @@ namespace _zeitbild.conf "error" ], "default": "info" - } + }, + "format": { + "nullable": false, + "type": "string", + "enum": [ + "human_readable", + "jsonl", + "jsonl_structured", + ], + "default": "human_readable", + }, }, "required": [ ] diff --git a/source/main.ts b/source/main.ts index 80f959a..85464ed 100644 --- a/source/main.ts +++ b/source/main.ts @@ -165,11 +165,17 @@ async function main( ) : Promise { // init1 - lib_plankton.log.conf_push( + /* + lib_plankton.log.set_main_logger( [ - lib_plankton.log.channel_make({"kind": "stdout", "data": {"threshold": "info"}}), + { + "kind": "std", + "data": { + } + } ] ); + */ // args const arg_handler : lib_plankton.args.class_handler = new lib_plankton.args.class_handler({ @@ -258,12 +264,54 @@ async function main( await _zeitbild.conf.init( args["conf_path"] ); - lib_plankton.log.conf_push( + lib_plankton.log.set_main_logger( _zeitbild.conf.get().log.map( - (log_output : any) => lib_plankton.log.channel_make( - { - "kind": log_output.kind, - "data": log_output.data + (log_output : any) => { + switch (log_output.kind) { + case "stdout": { + return { + "kind": "minlevel", + "data": { + "core": { + "kind": "std", + "data": { + "target": "stdout", + "format": lib_plankton.call.distinguish( + { + "kind": log_output.data.format, + "data": null, + }, + { + "jsonl": () => ({ + "kind": "jsonl", + "data": { + "structured": false, + } + }), + "jsonl_structured": () => ({ + "kind": "jsonl", + "data": { + "structured": true, + } + }), + "human_readable": () => ({ + "kind": "human_readable", + "data": { + } + }), + } + ), + } + }, + "threshold": log_output.data.threshold, + } + }; + break; + } + default: { + throw (new Error("unhandled")); + break; + } } ) ) @@ -327,7 +375,7 @@ async function main( break; } case "api-doc": { - lib_plankton.log.conf_push([]); + lib_plankton.log.set_main_logger([]); const rest_subject : lib_plankton.rest.type_rest = _zeitbild.api.make(); lib_plankton.log.conf_pop(); process.stdout.write(