From 2d20f44d34704897fe8edf93895526b6ab100da2 Mon Sep 17 00:00:00 2001 From: Amogh Rathore Date: Fri, 18 Jul 2025 21:11:43 +0000 Subject: [PATCH] Register custom log formatter before using it --- ecs-init/logger/log.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ecs-init/logger/log.go b/ecs-init/logger/log.go index 73443fc19ca..90f92c0b1fd 100644 --- a/ecs-init/logger/log.go +++ b/ecs-init/logger/log.go @@ -62,12 +62,15 @@ func init() { // Setup sets the custom logging config func Setup() { + // Register the custom formatter first, before any logging configuration is loaded + if err := seelog.RegisterCustomFormatter("InitLogfmt", logfmtFormatter); err != nil { + // Use fmt.Printf for error logging since seelog might not be configured yet + fmt.Printf("Failed to register InitLogfmt formatter: %v\n", err) + } + if logLevel := os.Getenv(LOGLEVEL_ENV_VAR); logLevel != "" { SetLogLevel(logLevel) } - if err := seelog.RegisterCustomFormatter("InitLogfmt", logfmtFormatter); err != nil { - seelog.Error(err) - } reloadConfig() }