mirror of
https://github.com/mudler/luet.git
synced 2025-08-11 04:02:08 +00:00
🔧 Add contextual logging accessors
This commit is contained in:
parent
e11521ddce
commit
78307eef57
@ -48,6 +48,7 @@ type Context struct {
|
|||||||
Config *LuetConfig
|
Config *LuetConfig
|
||||||
IsTerminal bool
|
IsTerminal bool
|
||||||
NoSpinner bool
|
NoSpinner bool
|
||||||
|
name string
|
||||||
|
|
||||||
s *pterm.SpinnerPrinter
|
s *pterm.SpinnerPrinter
|
||||||
spinnerLock *sync.Mutex
|
spinnerLock *sync.Mutex
|
||||||
@ -72,6 +73,12 @@ func NewContext() *Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Context) WithName(name string) *Context {
|
||||||
|
newc := c.Copy()
|
||||||
|
newc.name = name
|
||||||
|
return newc
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Context) Copy() *Context {
|
func (c *Context) Copy() *Context {
|
||||||
|
|
||||||
configCopy := *c.Config
|
configCopy := *c.Config
|
||||||
@ -311,6 +318,10 @@ func (c *Context) Msg(level LogLevel, ln bool, msg ...interface{}) {
|
|||||||
levelMsg = re.ReplaceAllString(levelMsg, "")
|
levelMsg = re.ReplaceAllString(levelMsg, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.name != "" {
|
||||||
|
levelMsg = fmt.Sprintf("[%s] %s", c.name, levelMsg)
|
||||||
|
}
|
||||||
|
|
||||||
if c.z != nil {
|
if c.z != nil {
|
||||||
c.log2File(level, message)
|
c.log2File(level, message)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user