about summary refs log tree commit diff stats
path: root/internal/builder
diff options
context:
space:
mode:
authorAlan Pearce2024-05-19 15:42:36 +0200
committerAlan Pearce2024-05-19 15:53:32 +0200
commit09ee2de72936ea0b0edc5d3360ce1c72803a817b (patch)
tree427a590fba06e58554586aad8995fcb6e7a559f3 /internal/builder
parent4064f933a965f2fb2ce43d3c2d5bd54ccd33978c (diff)
downloadwebsite-09ee2de72936ea0b0edc5d3360ce1c72803a817b.tar.lz
website-09ee2de72936ea0b0edc5d3360ce1c72803a817b.tar.zst
website-09ee2de72936ea0b0edc5d3360ce1c72803a817b.zip
log in logfmt via zap, with nicer console output in dev
Diffstat (limited to 'internal/builder')
-rw-r--r--internal/builder/builder.go26
-rw-r--r--internal/builder/posts.go6
-rw-r--r--internal/builder/template.go6
3 files changed, 19 insertions, 19 deletions
diff --git a/internal/builder/builder.go b/internal/builder/builder.go
index cb3b670..a8205a3 100644
--- a/internal/builder/builder.go
+++ b/internal/builder/builder.go
@@ -3,13 +3,13 @@ package builder
 import (
 	"fmt"
 	"io"
-	"log/slog"
 	"net/url"
 	"os"
 	"path"
 	"slices"
 
 	"website/internal/config"
+	"website/internal/log"
 
 	cp "github.com/otiai10/copy"
 	"github.com/pkg/errors"
@@ -27,7 +27,7 @@ func mkdirp(dirs ...string) error {
 }
 
 func outputToFile(output io.Reader, filename ...string) error {
-	slog.Debug(fmt.Sprintf("outputting file %s", path.Join(filename...)))
+	log.Debug("outputting file", "filename", path.Join(filename...))
 	file, err := os.OpenFile(path.Join(filename...), os.O_WRONLY|os.O_CREATE, 0644)
 	if err != nil {
 		return errors.WithMessage(err, "could not open output file")
@@ -41,7 +41,7 @@ func outputToFile(output io.Reader, filename ...string) error {
 }
 
 func build(outDir string, config config.Config) error {
-	slog.Debug(fmt.Sprintf("output directory %s", outDir))
+	log.Debug("output", "dir", outDir)
 	privateDir := path.Join(outDir, "private")
 	if err := mkdirp(privateDir); err != nil {
 		return errors.WithMessage(err, "could not create private directory")
@@ -62,7 +62,7 @@ func build(outDir string, config config.Config) error {
 	if err := mkdirp(publicDir, "post"); err != nil {
 		return errors.WithMessage(err, "could not create post output directory")
 	}
-	slog.Debug("reading posts")
+	log.Debug("reading posts")
 	posts, tags, err := readPosts("content", "post", publicDir)
 	if err != nil {
 		return err
@@ -72,7 +72,7 @@ func build(outDir string, config config.Config) error {
 		if err := mkdirp(publicDir, "post", post.Basename); err != nil {
 			return errors.WithMessage(err, "could not create directory for post")
 		}
-		slog.Debug("rendering post", "post", post.Basename)
+		log.Debug("rendering post", "post", post.Basename)
 		output, err := renderPost(post, config)
 		if err != nil {
 			return errors.WithMessagef(err, "could not render post %s", post.Input)
@@ -85,7 +85,7 @@ func build(outDir string, config config.Config) error {
 	if err := mkdirp(publicDir, "tags"); err != nil {
 		return errors.WithMessage(err, "could not create directory for tags")
 	}
-	slog.Debug("rendering tags list")
+	log.Debug("rendering tags list")
 	output, err := renderTags(tags, config, "/tags")
 	if err != nil {
 		return errors.WithMessage(err, "could not render tags")
@@ -104,7 +104,7 @@ func build(outDir string, config config.Config) error {
 		if err := mkdirp(publicDir, "tags", tag); err != nil {
 			return errors.WithMessage(err, "could not create directory")
 		}
-		slog.Debug("rendering tags page", "tag", tag)
+		log.Debug("rendering tags page", "tag", tag)
 		output, err := renderListPage(tag, config, matchingPosts, "/tags/"+tag)
 		if err != nil {
 			return errors.WithMessage(err, "could not render tag page")
@@ -113,7 +113,7 @@ func build(outDir string, config config.Config) error {
 			return err
 		}
 
-		slog.Debug("rendering tags feed", "tag", tag)
+		log.Debug("rendering tags feed", "tag", tag)
 		output, err = renderFeed(
 			fmt.Sprintf("%s - %s", config.Title, tag),
 			config,
@@ -128,7 +128,7 @@ func build(outDir string, config config.Config) error {
 		}
 	}
 
-	slog.Debug("rendering list page")
+	log.Debug("rendering list page")
 	listPage, err := renderListPage("", config, posts, "/post")
 	if err != nil {
 		return errors.WithMessage(err, "could not render list page")
@@ -137,7 +137,7 @@ func build(outDir string, config config.Config) error {
 		return err
 	}
 
-	slog.Debug("rendering feed")
+	log.Debug("rendering feed")
 	feed, err := renderFeed(config.Title, config, posts, "feed")
 	if err != nil {
 		return errors.WithMessage(err, "could not render feed")
@@ -146,7 +146,7 @@ func build(outDir string, config config.Config) error {
 		return err
 	}
 
-	slog.Debug("rendering feed styles")
+	log.Debug("rendering feed styles")
 	feedStyles, err := renderFeedStyles()
 	if err != nil {
 		return errors.WithMessage(err, "could not render feed styles")
@@ -155,7 +155,7 @@ func build(outDir string, config config.Config) error {
 		return err
 	}
 
-	slog.Debug("rendering homepage")
+	log.Debug("rendering homepage")
 	homePage, err := renderHomepage(config, posts, "/")
 	if err != nil {
 		return errors.WithMessage(err, "could not render homepage")
@@ -164,7 +164,7 @@ func build(outDir string, config config.Config) error {
 		return err
 	}
 
-	slog.Debug("rendering 404 page")
+	log.Debug("rendering 404 page")
 	notFound, err := render404(config, "/404.html")
 	if err != nil {
 		return errors.WithMessage(err, "could not render 404 page")
diff --git a/internal/builder/posts.go b/internal/builder/posts.go
index a4526e4..954e259 100644
--- a/internal/builder/posts.go
+++ b/internal/builder/posts.go
@@ -2,13 +2,13 @@ package builder
 
 import (
 	"bytes"
-	"log/slog"
 	"os"
 	"path"
 	"path/filepath"
 	"slices"
 	"strings"
 	"time"
+	"website/internal/log"
 
 	"github.com/adrg/frontmatter"
 	mapset "github.com/deckarep/golang-set/v2"
@@ -91,7 +91,7 @@ func readPosts(root string, inputDir string, outputDir string) ([]Post, Tags, er
 		if !f.IsDir() && path.Ext(pathFromRoot) == ".md" {
 			output := outputReplacer.Replace(pathFromRoot)
 			url := urlReplacer.Replace(pathFromRoot)
-			slog.Debug("reading post", "post", pathFromRoot)
+			log.Debug("reading post", "post", pathFromRoot)
 			matter, content, err := getPost(pathFromRoot)
 			if err != nil {
 				return nil, nil, err
@@ -101,7 +101,7 @@ func readPosts(root string, inputDir string, outputDir string) ([]Post, Tags, er
 				tags.Add(strings.ToLower(tag))
 			}
 
-			slog.Debug("rendering markdown in post", "post", pathFromRoot)
+			log.Debug("rendering markdown in post", "post", pathFromRoot)
 			html, err := renderMarkdown(content)
 			if err != nil {
 				return nil, nil, err
diff --git a/internal/builder/template.go b/internal/builder/template.go
index 5bd990e..c63e1c2 100644
--- a/internal/builder/template.go
+++ b/internal/builder/template.go
@@ -4,7 +4,6 @@ import (
 	"encoding/xml"
 	"fmt"
 	"io"
-	"log/slog"
 	"net/url"
 	"os"
 	"strings"
@@ -12,6 +11,7 @@ import (
 	"time"
 	"website/internal/atom"
 	"website/internal/config"
+	"website/internal/log"
 
 	"github.com/PuerkitoBio/goquery"
 	"github.com/a-h/htmlformat"
@@ -391,12 +391,12 @@ func renderHTML(doc *goquery.Document) io.Reader {
 	go func() {
 		_, err := w.Write([]byte("<!doctype html>\n"))
 		if err != nil {
-			slog.Error("error writing doctype")
+			log.Error("error writing doctype", "error", err)
 			w.CloseWithError(err)
 		}
 		err = htmlformat.Nodes(w, []*html.Node{doc.Children().Get(0)})
 		if err != nil {
-			slog.Error("error rendering html", "error", err)
+			log.Error("error rendering html", "error", err)
 			w.CloseWithError(err)
 			return
 		}