Skip to content

Commit

Permalink
feat: add daemon logfile support
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Apr 13, 2023
1 parent 26d6969 commit fb07b08
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions api/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ package server
import (
"context"
"fmt"
"io"
"net"
"net/http"
"os"
"os/signal"
"path/filepath"
"runtime"
Expand All @@ -34,10 +36,11 @@ import (

// Config is the server config
type Config struct {
Host string
Port int
Socket string
Debug bool
Host string
Port int
Socket string
Debug bool
LogFile string
}

// Server is the main server struct
Expand All @@ -60,6 +63,14 @@ func (s *Server) Start() error {
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()

if len(s.conf.LogFile) > 0 {
f, err := os.Create(s.conf.LogFile)
if err != nil {
return fmt.Errorf("server: failed to create log file: %v\n", err)
}
gin.DefaultWriter = io.MultiWriter(f, os.Stdout)
}

s.router.GET("/version", func(c *gin.Context) {
c.JSON(http.StatusOK, types.Version{
ApiVersion: api.DefaultVersion,
Expand Down

0 comments on commit fb07b08

Please sign in to comment.