Private
Public Access
1
0

Switch to zerolog

This commit is contained in:
James Magahern
2023-06-22 11:03:00 -07:00
parent 3613aac4c1
commit 84dbb7f006
5 changed files with 54 additions and 19 deletions

28
main.go
View File

@@ -1,28 +1,46 @@
package main
import (
"log"
"os"
"flag"
"net/http"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"code.severnaya.net/kordophone-mock/v2/web"
)
func main() {
log.Println("Initializing")
debug := flag.Bool("debug", false, "enable debug logging")
flag.Parse()
// Pretty logging
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
// Default level for this example is info, unless debug flag is present
zerolog.SetGlobalLevel(zerolog.InfoLevel)
if *debug {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
log.Info().Msg("Initializing")
c := web.MockHTTPServerConfiguration{
AuthEnabled: false,
}
addr := ":5738"
s := web.NewMockHTTPServer(c)
httpServer := &http.Server{
Addr: ":5738",
Addr: addr,
Handler: s,
}
// Populate with test data
s.Server.PopulateWithTestData()
log.Printf("Generated test data. %d conversations", len(s.Server.Conversations()))
log.Info().Msgf("Generated test data. %d conversations", len(s.Server.Conversations()))
log.Fatal(httpServer.ListenAndServe())
log.Info().Msgf("Listening on %s", addr)
log.Fatal().Err(httpServer.ListenAndServe())
}