about summary refs log tree commit diff stats
path: root/cmd/build
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/build')
-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)
 	}