From a9d3aa02036e1734dc7595cad1fb18cb911736a5 Mon Sep 17 00:00:00 2001 From: "Gustavo L de Mello (Guz)" Date: Fri, 10 Jan 2025 11:36:40 -0300 Subject: [PATCH] feat(blogo): add process steps on logs --- blogo/blogo.go | 9 +++++---- blogo/plugins.go | 11 +++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/blogo/blogo.go b/blogo/blogo.go index 068e329..953a8e0 100644 --- a/blogo/blogo.go +++ b/blogo/blogo.go @@ -72,7 +72,7 @@ func (b *Blogo) Use(p Plugin) { } func (b *Blogo) ServeHTTP(w http.ResponseWriter, r *http.Request) { - log := b.log.With(slog.String("path", r.URL.Path)) + log := b.log.With(slog.String("step", "SERVE"), slog.String("path", r.URL.Path)) log.Debug("Serving endpoint") @@ -134,14 +134,15 @@ func (b *Blogo) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func (b *Blogo) Init() error { - b.log.Debug("Initializing blogo") + log := b.log.With(slog.String("step", "INITIALIZATION")) + log.Debug("Initializing blogo") if len(b.sources) == 0 { - b.log.Debug("No SourcerPlugin found, using default one") + log.Debug("No SourcerPlugin found, using default one") b.Use(&defaultSourcer{}) } if len(b.renderers) == 0 { - b.log.Debug("No RendererPlugin found, using default one") + log.Debug("No RendererPlugin found, using default one") b.Use(&defaultRenderer{}) } diff --git a/blogo/plugins.go b/blogo/plugins.go index b6ee416..9f01801 100644 --- a/blogo/plugins.go +++ b/blogo/plugins.go @@ -16,6 +16,7 @@ package blogo import ( + "errors" "io" "io/fs" ) @@ -24,12 +25,14 @@ type Plugin interface { Name() string } -type SourcerPlugin interface { - Plugin - Source() (fs.FS, error) -} +var ErrRendererNotSupportedFile = errors.New("this file is not supported by renderer") type RendererPlugin interface { Plugin Render(src fs.File, out io.Writer) error } + +type SourcerPlugin interface { + Plugin + Source() (fs.FS, error) +}