Add logging provider
This commit is contained in:
44
providers/log/log.go
Normal file
44
providers/log/log.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package log
|
||||
|
||||
import "fmt"
|
||||
import "log"
|
||||
import "html/template"
|
||||
import "git.tebibyte.media/sashakoshka/step"
|
||||
|
||||
var _ step.FuncProviderFor = new(Provider)
|
||||
|
||||
// Provider provides MIME functions.
|
||||
type Provider struct {
|
||||
|
||||
}
|
||||
|
||||
// Package fulfills the step.Provider interface.
|
||||
func (this *Provider) Package () string {
|
||||
return "mime"
|
||||
}
|
||||
|
||||
// FuncMapFor fulfills the step.FuncProviderFor interface.
|
||||
func (this *Provider) FuncMapFor (document *step.Document) template.FuncMap {
|
||||
stat := &state {
|
||||
document: document,
|
||||
}
|
||||
return template.FuncMap {
|
||||
"println": stat.funcPrintln,
|
||||
"errorln": stat.funcPrintln,
|
||||
"debugln": stat.funcDebugln,
|
||||
}
|
||||
}
|
||||
|
||||
type state struct {
|
||||
document *step.Document
|
||||
}
|
||||
|
||||
func (this *state) funcPrintln (v ...any) string {
|
||||
log.Printf("(i) %s: %s", this.document.Name, fmt.Sprintln(v))
|
||||
return ""
|
||||
}
|
||||
|
||||
func (this *state) funcDebugln (v ...any) string {
|
||||
log.Printf("DBG %s: %s", this.document.Name, fmt.Sprintln(v))
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user