Add logging provider
This commit is contained in:
parent
695e94ef3e
commit
ff1e73ce6d
@ -91,6 +91,12 @@ func (this *Document) Rel (name string) (string, error) {
|
|||||||
return name, nil
|
return name, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Name returns the document's name, which is a path relative to its
|
||||||
|
// environment.
|
||||||
|
func (this *Document) Name () string {
|
||||||
|
return this.name
|
||||||
|
}
|
||||||
|
|
||||||
func (this *Document) dir () string {
|
func (this *Document) dir () string {
|
||||||
directory := this.name
|
directory := this.name
|
||||||
ext := filepath.Ext(directory)
|
ext := filepath.Ext(directory)
|
||||||
|
@ -2,6 +2,7 @@ package providers
|
|||||||
|
|
||||||
import "git.tebibyte.media/sashakoshka/step"
|
import "git.tebibyte.media/sashakoshka/step"
|
||||||
import fpos "git.tebibyte.media/sashakoshka/step/providers/os"
|
import fpos "git.tebibyte.media/sashakoshka/step/providers/os"
|
||||||
|
import fplog "git.tebibyte.media/sashakoshka/step/providers/log"
|
||||||
import fphttp "git.tebibyte.media/sashakoshka/step/providers/http"
|
import fphttp "git.tebibyte.media/sashakoshka/step/providers/http"
|
||||||
import fppath "git.tebibyte.media/sashakoshka/step/providers/path"
|
import fppath "git.tebibyte.media/sashakoshka/step/providers/path"
|
||||||
import fpmime "git.tebibyte.media/sashakoshka/step/providers/mime"
|
import fpmime "git.tebibyte.media/sashakoshka/step/providers/mime"
|
||||||
@ -15,6 +16,7 @@ import fpmarkdown "git.tebibyte.media/sashakoshka/step/providers/markdown"
|
|||||||
func All () []step.Provider {
|
func All () []step.Provider {
|
||||||
return []step.Provider {
|
return []step.Provider {
|
||||||
new(fpos.Provider),
|
new(fpos.Provider),
|
||||||
|
new(fplog.Provider),
|
||||||
new(fphttp.Provider),
|
new(fphttp.Provider),
|
||||||
new(fppath.Provider),
|
new(fppath.Provider),
|
||||||
new(fpmime.Provider),
|
new(fpmime.Provider),
|
||||||
|
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 ""
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user