mirror of
https://github.com/restic/rest-server.git
synced 2025-10-19 07:33:21 +00:00
feat: allow logging to stdout
The --log option accepts "-" as filename. This prevents rest-server from opening the log file, it simply writes to the STDOUT stream provided by the caller. **BREAKING** in case use really used "-" to specify a file named "-" you'll need to update your rest-server invocation to use "./-".
This commit is contained in:
parent
94d5861c50
commit
9f074d8b3a
3 changed files with 25 additions and 4 deletions
14
mux.go
14
mux.go
|
@ -2,6 +2,7 @@ package restserver
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -21,9 +22,16 @@ func (s *Server) debugHandler(next http.Handler) http.Handler {
|
|||
}
|
||||
|
||||
func (s *Server) logHandler(next http.Handler) http.Handler {
|
||||
accessLog, err := os.OpenFile(s.Log, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
||||
if err != nil {
|
||||
log.Fatalf("error: %v", err)
|
||||
var accessLog io.Writer
|
||||
|
||||
if s.Log == "-" {
|
||||
accessLog = os.Stdout
|
||||
} else {
|
||||
var err error
|
||||
accessLog, err = os.OpenFile(s.Log, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
||||
if err != nil {
|
||||
log.Fatalf("error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return handlers.CombinedLoggingHandler(accessLog, next)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue