diff options
-rw-r--r-- | tmp.go | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -2,7 +2,8 @@ package main import ( "fmt" - "log" // TODO: eventually change to slog and manage levels + "log" + "log/slog" "net/url" "os" "os/exec" @@ -50,6 +51,14 @@ func main() { os.Exit(1) } + opts := &slog.HandlerOptions{ + Level: slog.LevelInfo, + } + + handler := slog.NewTextHandler(os.Stderr, opts) + logger := slog.New(handler) + slog.SetDefault(logger) + cmdname := strings.ToLower(filepath.Base(os.Args[0])) config := URL_VARIANTS[cmdname] @@ -63,14 +72,14 @@ func main() { log.Fatal(err) } fileExt := filepath.Ext(processedFile) - log.Printf("size of %s is %d.", processedFile, st.Size()) - log.Printf("extension is %s", fileExt) + slog.Debug(fmt.Sprintf("size of %s is %d.", processedFile, st.Size())) + slog.Debug(fmt.Sprintf("extension is %s.", fileExt)) var fname string var COMPRESSED bool if st.Size() > 1000000 && !contains(COMPRESSED_EXTENSIONS, strings.ToLower(fileExt)) { - log.Printf("file %s should be compressed (%d b)", processedFile, st.Size()) + slog.Debug(fmt.Sprintf("file %s should be compressed (%d b)", processedFile, st.Size())) err := exec.Command("gzip", "--keep", "--best", processedFile).Run() if err != nil { log.Fatal("Compressing the file failed!") @@ -78,7 +87,7 @@ func main() { fname = processedFile + ".gz" COMPRESSED = true } else { - log.Printf("file %s should not be compressed (%d b)", processedFile, st.Size()) + slog.Debug(fmt.Sprintf("file %s should not be compressed (%d b)", processedFile, st.Size())) fname = processedFile COMPRESSED = false } @@ -93,7 +102,7 @@ func main() { if err != nil { log.Fatal(err) } - log.Printf("Unshorten fname = %s", modifiedFname) + slog.Debug(fmt.Sprintf("Unshorten fname = %s", modifiedFname)) _, err = exec.Command("scp", modifiedFname, config["base_url"]).Output() if err != nil { |