Replaced log.Print with fmt.Printf to allow finer control of newlines

This commit is contained in:
Seednode 2022-09-10 18:03:04 -05:00
parent bbe919be3b
commit 35b46ed9e8
2 changed files with 12 additions and 4 deletions

View File

@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
)
var Version = "0.4.1"
var Version = "0.4.2"
func init() {
rootCmd.AddCommand(versionCmd)

View File

@ -6,6 +6,7 @@ package cmd
import (
"errors"
"fmt"
"io"
"log"
"net/http"
@ -13,8 +14,11 @@ import (
"os"
"strconv"
"strings"
"time"
)
const LOGDATE string = "2006-01-02T15:04:05.000000000-07:00"
func generatePageHtml(w http.ResponseWriter, r http.Request, paths []string) error {
fileList, err := getFileList(paths)
if err != nil {
@ -69,7 +73,7 @@ func serveStaticFile(w http.ResponseWriter, r http.Request, paths []string) erro
if matchesPrefix == false {
if Verbose {
log.Println("Failed to serve file outside specified path(s): " + filePath)
fmt.Printf("%v Failed to serve file outside specified path(s): %v", time.Now().Format(LOGDATE), filePath)
}
http.NotFound(w, &r)
@ -80,7 +84,7 @@ func serveStaticFile(w http.ResponseWriter, r http.Request, paths []string) erro
_, err = os.Stat(filePath)
if errors.Is(err, os.ErrNotExist) {
if Verbose {
log.Println("Failed to serve non-existent file: " + filePath)
fmt.Printf("%v Failed to serve non-existent file: %v", time.Now().Format(LOGDATE), filePath)
}
http.NotFound(w, &r)
@ -90,6 +94,10 @@ func serveStaticFile(w http.ResponseWriter, r http.Request, paths []string) erro
return err
}
if Verbose {
fmt.Printf("%v Serving file: %v", time.Now().Format(LOGDATE), filePath)
}
buf, err := os.ReadFile(filePath)
if err != nil {
return err
@ -98,7 +106,7 @@ func serveStaticFile(w http.ResponseWriter, r http.Request, paths []string) erro
w.Write(buf)
if Verbose {
log.Println("Served file: " + filePath)
fmt.Println(" - DONE")
}
return nil