mirror of
https://github.com/mudler/luet.git
synced 2025-09-05 01:00:44 +00:00
Define context for scoped operation across core types
It holds necessary state plus additional information relative to the context which we are being run to (e.g. if we are in a terminal or not). Besides in the future we can use it also as a contextual logger to provide more smart logging capabilities. This also replace the general global configuration instance that previously was share between the core components.
This commit is contained in:
@@ -19,18 +19,20 @@ package backend
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
. "github.com/mudler/luet/pkg/logger"
|
||||
"github.com/mudler/luet/pkg/api/core/types"
|
||||
)
|
||||
|
||||
type BackendWriter struct {
|
||||
BufferedOutput bool
|
||||
Buffer *bytes.Buffer
|
||||
ctx *types.Context
|
||||
}
|
||||
|
||||
func NewBackendWriter(buffered bool) *BackendWriter {
|
||||
func NewBackendWriter(buffered bool, ctx *types.Context) *BackendWriter {
|
||||
return &BackendWriter{
|
||||
BufferedOutput: buffered,
|
||||
Buffer: &bytes.Buffer{},
|
||||
ctx: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +41,7 @@ func (b *BackendWriter) Write(p []byte) (int, error) {
|
||||
return b.Buffer.Write(p)
|
||||
}
|
||||
|
||||
Msg("info", false, false, (string(p)))
|
||||
b.ctx.Msg("info", false, (string(p)))
|
||||
|
||||
return len(p), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user