diff --git a/appext/appext.go b/appext/appext.go index 0362b41..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,20 +91,46 @@ 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() 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 + LogLevelContainer + LogFormatContainer } // NewContainer returns a new Container. 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 c0dd35e..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) + 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 88ec902..c3c0885 100644 --- a/appext/container.go +++ b/appext/container.go @@ -21,14 +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), + NameContainer: nameContainer, + LoggerContainer: newLoggerContainer(logger), + LogLevelContainer: newLogLevelContainer(logLevel), + 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 +} 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 +}