Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion appext/appext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Godoc

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking, this is all a breaking change, can you explain a bit more why you need this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My use-case specifically is for rendering the report from our compiler. I'd like to pass on configurations from the CLI framework so that report.Renderer can respect color configs from the user.

}

// NewContainer returns a new Container.
func NewContainer(
nameContainer NameContainer,
logger *slog.Logger,
logLevel LogLevel,
logFormat LogFormat,
) Container {
return newContainer(
nameContainer,
logger,
logLevel,
logFormat,
)
}

Expand Down
2 changes: 1 addition & 1 deletion appext/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions appext/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
29 changes: 29 additions & 0 deletions appext/log_format_container.go
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 29 additions & 0 deletions appext/log_level_container.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading