about summary refs log tree commit diff stats
path: root/cmd/build/main.go
diff options
context:
space:
mode:
authorAlan Pearce2024-05-19 15:42:36 +0200
committerAlan Pearce2024-05-19 15:53:32 +0200
commit09ee2de72936ea0b0edc5d3360ce1c72803a817b (patch)
tree427a590fba06e58554586aad8995fcb6e7a559f3 /cmd/build/main.go
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 'cmd/build/main.go')
-rw-r--r--cmd/build/main.go24
1 files changed, 7 insertions, 17 deletions
diff --git a/cmd/build/main.go b/cmd/build/main.go
index 069f9bd..0b1cc46 100644
--- a/cmd/build/main.go
+++ b/cmd/build/main.go
@@ -3,11 +3,10 @@ package main
 import (
 	"fmt"
 	"io/fs"
-	"log"
-	"log/slog"
 	"os"
 
 	"website/internal/builder"
+	"website/internal/log"
 
 	"github.com/BurntSushi/toml"
 	"github.com/ardanlabs/conf/v3"
@@ -15,22 +14,17 @@ import (
 )
 
 func main() {
-	if os.Getenv("DEBUG") != "" {
-		slog.SetLogLoggerLevel(slog.LevelDebug)
-	}
-	log.SetFlags(log.LstdFlags | log.Lmsgprefix)
-	log.SetPrefix("build: ")
-	slog.Debug("starting build process")
-
 	ioConfig := builder.IOConfig{}
 	if help, err := conf.Parse("", &ioConfig); err != nil {
 		if errors.Is(err, conf.ErrHelpWanted) {
 			fmt.Println(help)
 			os.Exit(1)
 		}
-		log.Panicf("parsing I/O configuration: %v", err)
+		panic("error parsing configuration: " + err.Error())
 	}
+	log.Configure(!ioConfig.Development)
 
+	log.Debug("starting build process")
 	if ioConfig.Source != "." {
 		err := os.Chdir(ioConfig.Source)
 		if err != nil {
@@ -41,15 +35,11 @@ func main() {
 	if err := builder.BuildSite(ioConfig); err != nil {
 		switch cause := errors.Cause(err).(type) {
 		case *fs.PathError:
-			slog.Info("pathError")
-			slog.Error(fmt.Sprintf("%s", err))
+			log.Error("path error", "error", err)
 		case toml.ParseError:
-			slog.Info("parseError")
-			slog.Error(fmt.Sprintf("%s", err))
+			log.Info("parse error", "error", err)
 		default:
-			slog.Info("other")
-			slog.Error(fmt.Sprintf("cause:%+v", errors.Cause(cause)))
-			slog.Error(fmt.Sprintf("%+v", cause))
+			log.Info("other error", "error", err, "cause", errors.Cause(cause))
 		}
 		os.Exit(1)
 	}