From d45d6faca494bbeee995c6ac484051483f648165 Mon Sep 17 00:00:00 2001 From: Doria Keung Date: Mon, 23 Mar 2026 16:13:26 -0400 Subject: [PATCH 1/3] Add `LogFormatContainer` for exposing the configured `LogFormat` --- appext/appext.go | 13 +++++++++++++ appext/builder.go | 2 +- appext/container.go | 7 +++++-- appext/log_format_container.go | 29 +++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 appext/log_format_container.go diff --git a/appext/appext.go b/appext/appext.go index 0362b41..e75a6d7 100644 --- a/appext/appext.go +++ b/appext/appext.go @@ -91,20 +91,33 @@ func NewLoggerContainer(logger *slog.Logger) LoggerContainer { return newLoggerContainer(logger) } +// LogFormatContainer provides the [LogFormat] set for the [Container]. +type LogFormatContainer interface { + LogFormat() LogFormat +} + +// NewLogFormatContainer returns a new LogFormatContainer. +func NewLogFormatContainer(logFormat LogFormat) LogFormatContainer { + return newLogFormatContainer(logFormat) +} + // Container contains not just the base app container, but all extended containers. type Container interface { NameContainer LoggerContainer + LogFormatContainer } // NewContainer returns a new Container. func NewContainer( nameContainer NameContainer, logger *slog.Logger, + logFormat LogFormat, ) Container { return newContainer( nameContainer, logger, + logFormat, ) } diff --git a/appext/builder.go b/appext/builder.go index c0dd35e..60af0d8 100644 --- a/appext/builder.go +++ b/appext/builder.go @@ -102,7 +102,7 @@ func (b *builder) run( if err != nil { return err } - container := newContainer(nameContainer, logger) + container := newContainer(nameContainer, logger, logFormat) var cancel context.CancelFunc if b.timeout != 0 { diff --git a/appext/container.go b/appext/container.go index 88ec902..83b0c41 100644 --- a/appext/container.go +++ b/appext/container.go @@ -21,14 +21,17 @@ import ( type container struct { NameContainer LoggerContainer + LogFormatContainer } func newContainer( nameContainer NameContainer, logger *slog.Logger, + logFormat LogFormat, ) *container { return &container{ - NameContainer: nameContainer, - LoggerContainer: newLoggerContainer(logger), + NameContainer: nameContainer, + LoggerContainer: newLoggerContainer(logger), + LogFormatContainer: newLogFormatContainer(logFormat), } } diff --git a/appext/log_format_container.go b/appext/log_format_container.go new file mode 100644 index 0000000..035ffd2 --- /dev/null +++ b/appext/log_format_container.go @@ -0,0 +1,29 @@ +// Copyright 2025 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package appext + +type logFormatContainer struct { + logFormat LogFormat +} + +func newLogFormatContainer(logFormat LogFormat) *logFormatContainer { + return &logFormatContainer{ + logFormat: logFormat, + } +} + +func (c *logFormatContainer) LogFormat() LogFormat { + return c.logFormat +} From 23f0ad109fd0fd9f379d0a680e0aaac79dbfbc88 Mon Sep 17 00:00:00 2001 From: Doria Keung Date: Tue, 24 Mar 2026 14:14:40 -0400 Subject: [PATCH 2/3] Address comments --- appext/appext.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/appext/appext.go b/appext/appext.go index e75a6d7..e8dc551 100644 --- a/appext/appext.go +++ b/appext/appext.go @@ -91,8 +91,9 @@ func NewLoggerContainer(logger *slog.Logger) LoggerContainer { return newLoggerContainer(logger) } -// LogFormatContainer provides the [LogFormat] set for the [Container]. +// LogFormatContainer provides the LogFormat set for the Container. type LogFormatContainer interface { + // LogFormat returns the LogFormat configured for the Container. LogFormat() LogFormat } From b634ee766ce9490b9d34c090639cc35bbe00c7a2 Mon Sep 17 00:00:00 2001 From: Doria Keung Date: Tue, 24 Mar 2026 14:57:18 -0400 Subject: [PATCH 3/3] Add LogLevelContainer for exposing the configured LogLevel --- appext/appext.go | 16 ++++++++++++++-- appext/builder.go | 2 +- appext/container.go | 3 +++ appext/log_level_container.go | 29 +++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 appext/log_level_container.go diff --git a/appext/appext.go b/appext/appext.go index e8dc551..6217953 100644 --- a/appext/appext.go +++ b/appext/appext.go @@ -81,7 +81,7 @@ func NewNameContainer(baseContainer app.Container, appName string) (NameContaine return newNameContainer(baseContainer, appName) } -// LoggerContainer provides a *slog.Logger. +// LoggerContainer provides the *slog.Logger set for the Container. type LoggerContainer interface { Logger() *slog.Logger } @@ -91,9 +91,18 @@ func NewLoggerContainer(logger *slog.Logger) LoggerContainer { return newLoggerContainer(logger) } +// LogLevelContainer provides the LogLevel set for the Container. +type LogLevelContainer interface { + LogLevel() LogLevel +} + +// NewLogLevelContainer returns a new LogLevelContainer. +func NewLogLevelContainer(logLevel LogLevel) LogLevelContainer { + return newLogLevelContainer(logLevel) +} + // LogFormatContainer provides the LogFormat set for the Container. type LogFormatContainer interface { - // LogFormat returns the LogFormat configured for the Container. LogFormat() LogFormat } @@ -106,6 +115,7 @@ func NewLogFormatContainer(logFormat LogFormat) LogFormatContainer { type Container interface { NameContainer LoggerContainer + LogLevelContainer LogFormatContainer } @@ -113,11 +123,13 @@ type Container interface { func NewContainer( nameContainer NameContainer, logger *slog.Logger, + logLevel LogLevel, logFormat LogFormat, ) Container { return newContainer( nameContainer, logger, + logLevel, logFormat, ) } diff --git a/appext/builder.go b/appext/builder.go index 60af0d8..3de0efd 100644 --- a/appext/builder.go +++ b/appext/builder.go @@ -102,7 +102,7 @@ func (b *builder) run( if err != nil { return err } - container := newContainer(nameContainer, logger, logFormat) + container := newContainer(nameContainer, logger, logLevel, logFormat) var cancel context.CancelFunc if b.timeout != 0 { diff --git a/appext/container.go b/appext/container.go index 83b0c41..c3c0885 100644 --- a/appext/container.go +++ b/appext/container.go @@ -21,17 +21,20 @@ import ( type container struct { NameContainer LoggerContainer + LogLevelContainer LogFormatContainer } func newContainer( nameContainer NameContainer, logger *slog.Logger, + logLevel LogLevel, logFormat LogFormat, ) *container { return &container{ NameContainer: nameContainer, LoggerContainer: newLoggerContainer(logger), + LogLevelContainer: newLogLevelContainer(logLevel), LogFormatContainer: newLogFormatContainer(logFormat), } } diff --git a/appext/log_level_container.go b/appext/log_level_container.go new file mode 100644 index 0000000..f4e9db1 --- /dev/null +++ b/appext/log_level_container.go @@ -0,0 +1,29 @@ +// Copyright 2025 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package appext + +type logLevelContainer struct { + logLevel LogLevel +} + +func newLogLevelContainer(logLevel LogLevel) *logLevelContainer { + return &logLevelContainer{ + logLevel: logLevel, + } +} + +func (c *logLevelContainer) LogLevel() LogLevel { + return c.logLevel +}