Skip to content

Commit

Permalink
refactor: improve a bit logging
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Mar 23, 2024
1 parent 2919b1c commit 741686e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion darkstat/settings/logus/logus.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import (
"github.com/darklab8/go-typelog/typelog"
)

var Log *typelog.Logger = typelog.NewLogger("darkstat", typelog.WithLogLevel(typelog.LEVEL_INFO))
var Log *typelog.Logger = typelog.NewLogger("darkstat",
typelog.WithLogLevel(typelog.LEVEL_INFO),
)
2 changes: 1 addition & 1 deletion darkstat/web/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (w *Web) Serve() {

ip := "0.0.0.0"
port := 8000
fmt.Printf("launching web server, visit http://localhost:%d to check it!", port)
fmt.Printf("launching web server, visit http://localhost:%d to check it!\n", port)
if err := http.ListenAndServe(fmt.Sprintf("%s:%d", ip, port), nil); err != nil {
log.Fatal(err)
}
Expand Down
18 changes: 14 additions & 4 deletions darkstat/web/route_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"net/http"

"github.com/darklab8/fl-darkstat/darkstat/common/types"
"github.com/darklab8/fl-darkstat/darkstat/settings/logus"
"github.com/darklab8/fl-darkstat/darkstat/web/registry"
"github.com/darklab8/go-typelog/typelog"
"github.com/darklab8/go-utils/goutils/utils/utils_types"
)

Expand All @@ -19,15 +21,23 @@ func (w *Web) NewEndpointStatic() *registry.Endpoint {
switch req.Method {
case http.MethodGet:

for path, _ := range w.filesystem.Files {
fmt.Println("path=", path.ToString())
}
// var log_files []typelog.LogType = make([]typelog.LogType, len(w.filesystem.Files))

// i := 0
// for path, _ := range w.filesystem.Files {
// log_files[i] = typelog.String(strconv.Itoa(i), path.ToString())
// i++
// }
// logus.Log.Info("acquired files", log_files...)

requested := req.URL.Path[1:]
if requested == "" {
requested = "index.html"
}
fmt.Println("requested=", requested)
logus.Log.Info("having get request",
typelog.String("requested_path", requested),
typelog.Int("files_count", len(w.filesystem.Files)),
)

content, ok := w.filesystem.Files[utils_types.FilePath(requested)]
if ok {
Expand Down

0 comments on commit 741686e

Please sign in to comment.