diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-10-09 08:58:31 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-10-09 08:58:31 -0600 |
commit | 20be557b7bc3d7ada78411b7b279c9f7580d0bc7 (patch) | |
tree | 2a7f6640b0b389ad79fe18a8906642be493aaf60 /examples | |
parent | cedcf58ea7d729acb6ed1a9ab7aec1ae38aed102 (diff) |
logging.Base()
Allow users to get access to the base logger *before* it is wrapped with the various levels.
This provides a single override point to filter or redirect all logging.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/cgi/main.go | 7 | ||||
-rw-r--r-- | examples/cowsay/main.go | 7 | ||||
-rw-r--r-- | examples/fileserver/main.go | 7 | ||||
-rw-r--r-- | examples/finger/main.go | 8 | ||||
-rw-r--r-- | examples/gopher_fileserver/main.go | 7 | ||||
-rw-r--r-- | examples/inspectls/main.go | 7 |
6 files changed, 24 insertions, 19 deletions
diff --git a/examples/cgi/main.go b/examples/cgi/main.go index 4d48422..587c874 100644 --- a/examples/cgi/main.go +++ b/examples/cgi/main.go @@ -7,6 +7,7 @@ import ( "os/signal" "syscall" + "github.com/go-kit/log/level" "tildegit.org/tjp/sliderule/contrib/cgi" "tildegit.org/tjp/sliderule/gemini" "tildegit.org/tjp/sliderule/logging" @@ -25,17 +26,17 @@ func main() { // make use of a CGI request handler cgiHandler := cgi.GeminiCGIDirectory("./cgi-bin", "/cgi-bin") - _, infoLog, _, errLog := logging.DefaultLoggers() + baseLog := logging.Base() // add stdout logging to the request handler - handler := logging.LogRequests(infoLog)(cgiHandler) + handler := logging.LogRequests(level.Info(baseLog))(cgiHandler) // set up signals to trigger graceful shutdown ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGHUP) defer stop() // run the server - server, err := gemini.NewServer(ctx, "localhost", "tcp4", ":1965", handler, errLog, tlsconf) + server, err := gemini.NewServer(ctx, "localhost", "tcp4", ":1965", handler, baseLog, tlsconf) if err != nil { log.Fatal(err) } diff --git a/examples/cowsay/main.go b/examples/cowsay/main.go index 32ba2ea..3ada714 100644 --- a/examples/cowsay/main.go +++ b/examples/cowsay/main.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" + "github.com/go-kit/log/level" sr "tildegit.org/tjp/sliderule" "tildegit.org/tjp/sliderule/gemini" "tildegit.org/tjp/sliderule/logging" @@ -23,13 +24,13 @@ func main() { log.Fatal(err) } - _, infoLog, _, errLog := logging.DefaultLoggers() + baseLog := logging.Base() // add request logging to the request handler - handler := logging.LogRequests(infoLog)(cowsayHandler) + handler := logging.LogRequests(level.Info(baseLog))(cowsayHandler) // run the server - server, err := gemini.NewServer(context.Background(), "localhost", "tcp4", ":1965", handler, errLog, tlsconf) + server, err := gemini.NewServer(context.Background(), "localhost", "tcp4", ":1965", handler, baseLog, tlsconf) if err != nil { log.Fatal(err) } diff --git a/examples/fileserver/main.go b/examples/fileserver/main.go index e90fdd9..2801858 100644 --- a/examples/fileserver/main.go +++ b/examples/fileserver/main.go @@ -5,6 +5,7 @@ import ( "log" "os" + "github.com/go-kit/log/level" sr "tildegit.org/tjp/sliderule" "tildegit.org/tjp/sliderule/contrib/fs" "tildegit.org/tjp/sliderule/gemini" @@ -35,13 +36,13 @@ func main() { router.Route("/*", handler) handler = router.Handler() - _, infoLog, _, errLog := logging.DefaultLoggers() + baseLog := logging.Base() // add request logging to stdout - handler = logging.LogRequests(infoLog)(handler) + handler = logging.LogRequests(level.Info(baseLog))(handler) // run the server - server, err := gemini.NewServer(context.Background(), "localhost", "tcp4", ":1965", handler, errLog, tlsconf) + server, err := gemini.NewServer(context.Background(), "localhost", "tcp4", ":1965", handler, baseLog, tlsconf) if err != nil { log.Fatal(err) } diff --git a/examples/finger/main.go b/examples/finger/main.go index 723e3e6..8cb6526 100644 --- a/examples/finger/main.go +++ b/examples/finger/main.go @@ -4,20 +4,20 @@ import ( "context" "log" + "github.com/go-kit/log/level" "tildegit.org/tjp/sliderule/finger" "tildegit.org/tjp/sliderule/logging" ) func main() { - _, infoLog, _, errLog := logging.DefaultLoggers() - + baselog := logging.Base() fs, err := finger.NewServer( context.Background(), "localhost", "tcp", ":79", - logging.LogRequests(infoLog)(finger.SystemFinger(false)), - errLog, + logging.LogRequests(level.Info(baselog))(finger.SystemFinger(false)), + logging.Base(), ) if err != nil { log.Fatal(err) diff --git a/examples/gopher_fileserver/main.go b/examples/gopher_fileserver/main.go index 1cb7495..9b8c33f 100644 --- a/examples/gopher_fileserver/main.go +++ b/examples/gopher_fileserver/main.go @@ -4,6 +4,7 @@ import ( "context" "log" + "github.com/go-kit/log/level" sr "tildegit.org/tjp/sliderule" "tildegit.org/tjp/sliderule/contrib/cgi" "tildegit.org/tjp/sliderule/contrib/fs" @@ -19,10 +20,10 @@ func main() { fs.GopherFileHandler(".", "", nil), ) - _, infoLog, _, errLog := logging.DefaultLoggers() - handler = logging.LogRequests(infoLog)(handler) + baseLog := logging.Base() + handler = logging.LogRequests(level.Info(baseLog))(handler) - server, err := gopher.NewServer(context.Background(), "localhost", "tcp4", ":70", handler, errLog) + server, err := gopher.NewServer(context.Background(), "localhost", "tcp4", ":70", handler, baseLog) if err != nil { log.Fatal(err) } diff --git a/examples/inspectls/main.go b/examples/inspectls/main.go index d400fe9..f12fd65 100644 --- a/examples/inspectls/main.go +++ b/examples/inspectls/main.go @@ -12,6 +12,7 @@ import ( "os" "strings" + "github.com/go-kit/log/level" sr "tildegit.org/tjp/sliderule" "tildegit.org/tjp/sliderule/gemini" "tildegit.org/tjp/sliderule/logging" @@ -27,13 +28,13 @@ func main() { log.Fatal(err) } - _, infoLog, _, errLog := logging.DefaultLoggers() + baseLog := logging.Base() // add stdout logging to the request handler - handler := logging.LogRequests(infoLog)(inspectHandler) + handler := logging.LogRequests(level.Info(baseLog))(inspectHandler) // run the server - server, err := gemini.NewServer(context.Background(), "localhost", "tcp4", ":1965", handler, errLog, tlsconf) + server, err := gemini.NewServer(context.Background(), "localhost", "tcp4", ":1965", handler, baseLog, tlsconf) if err != nil { log.Fatal(err) } |