Added access log to server and modified mock-fts to use it
This commit is contained in:
1 parent
2490519c2b
commit
02e3d910a2
10 files changed
+389
-29
No files matched your search
+10
-17
@@ -23,7 +23,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -286,23 +285,17 @@ func run(ctx context.Context, opts *options) (err error) {
|
||||
}()
|
||||
|
||||
// Serve the API.
|
||||
out := os.Stdout
|
||||
if opts.accessLogPath != "-" {
|
||||
var logFile *os.File
|
||||
logFile, err = os.OpenFile(
|
||||
opts.accessLogPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o600,
|
||||
)
|
||||
if err != nil {
|
||||
cancel()
|
||||
<-workerDone
|
||||
return fmt.Errorf("opening access log: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
err = errors.Join(err, logFile.Close())
|
||||
}()
|
||||
out = logFile
|
||||
accessLogger, closeAccessLog, err := logging.OpenAccessLog(
|
||||
opts.accessLogPath,
|
||||
)
|
||||
if err != nil {
|
||||
cancel()
|
||||
<-workerDone
|
||||
return err
|
||||
}
|
||||
accessLogger := log.New(out, "", 0)
|
||||
defer func() {
|
||||
err = errors.Join(err, closeAccessLog())
|
||||
}()
|
||||
|
||||
rateLimiter := mock.NewRateLimiter(opts.rateLimit, opts.rateWindow)
|
||||
mux := http.NewServeMux()
|
||||
|
||||
Reference in new issue
Block a user