🔧 Add contextual logging accessors

This commit is contained in:
Ettore Di Giacinto 2021-12-04 21:40:18 +01:00
parent e11521ddce
commit 78307eef57

View File

@ -48,6 +48,7 @@ type Context struct {
Config *LuetConfig
IsTerminal bool
NoSpinner bool
name string
s *pterm.SpinnerPrinter
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 {
configCopy := *c.Config
@ -311,6 +318,10 @@ func (c *Context) Msg(level LogLevel, ln bool, msg ...interface{}) {
levelMsg = re.ReplaceAllString(levelMsg, "")
}
if c.name != "" {
levelMsg = fmt.Sprintf("[%s] %s", c.name, levelMsg)
}
if c.z != nil {
c.log2File(level, message)
}