Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect STDERR to error log #709

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions fileserver/fileserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (
"github.com/haiwen/seafile-server/fileserver/repomgr"
"github.com/haiwen/seafile-server/fileserver/searpc"
"github.com/haiwen/seafile-server/fileserver/share"
"github.com/haiwen/seafile-server/fileserver/utils"
_ "github.com/mattn/go-sqlite3"
log "github.com/sirupsen/logrus"
"gopkg.in/ini.v1"
stdlog "log"

"net/http/pprof"
)
Expand Down Expand Up @@ -365,6 +365,10 @@ func main() {
logFp = fp
log.SetOutput(fp)
}

if absLogFile != "" && !logToStdout {
utils.Dup(int(logFp.Fd()), int(os.Stderr.Fd()))
}
// When logFile is "-", use default output (StdOut)

level, err := log.ParseLevel(option.LogLevel)
Expand Down Expand Up @@ -412,9 +416,6 @@ func main() {
server.Addr = fmt.Sprintf("%s:%d", option.Host, option.Port)
server.Handler = router

errorLog := stdlog.New(log.StandardLogger().Writer(), "", 0)
server.ErrorLog = errorLog

err = server.ListenAndServe()
if err != nil {
log.Printf("File server exiting: %v", err)
Expand Down Expand Up @@ -453,6 +454,8 @@ func logRotate() {
logFp.Close()
logFp = fp
}

utils.Dup(int(logFp.Fd()), int(os.Stderr.Fd()))
}

var rpcclient *searpc.Client
Expand Down
11 changes: 11 additions & 0 deletions fileserver/utils/dup2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build !(linux && arm64)

package utils

import (
"syscall"
)

func Dup(from, to int) error {
return syscall.Dup2(from, to)
}
11 changes: 11 additions & 0 deletions fileserver/utils/dup3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build linux && arm64

package utils

import (
"syscall"
)

func Dup(from, to int) error {
return syscall.Dup3(from, to, 0)
}
11 changes: 11 additions & 0 deletions notification-server/dup2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build !(linux && arm64)

package main

import (
"syscall"
)

func Dup(from, to int) error {
return syscall.Dup2(from, to)
}
11 changes: 11 additions & 0 deletions notification-server/dup3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build linux && arm64

package main

import (
"syscall"
)

func Dup(from, to int) error {
return syscall.Dup3(from, to, 0)
}
9 changes: 6 additions & 3 deletions notification-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/gorilla/websocket"
log "github.com/sirupsen/logrus"
"gopkg.in/ini.v1"
stdlog "log"
)

var configDir string
Expand Down Expand Up @@ -197,6 +196,10 @@ func main() {
log.SetOutput(fp)
}

if absLogFile != "" && !logToStdout {
Dup(int(logFp.Fd()), int(os.Stderr.Fd()))
}

if err := loadJwtPrivateKey(); err != nil {
log.Fatalf("Failed to read config: %v", err)
}
Expand All @@ -216,8 +219,6 @@ func main() {
server.Addr = fmt.Sprintf("%s:%d", host, port)
server.Handler = router

errorLog := stdlog.New(log.StandardLogger().Writer(), "", 0)
server.ErrorLog = errorLog
err = server.ListenAndServe()
if err != nil {
log.Infof("notificationserver exiting: %v", err)
Expand Down Expand Up @@ -256,6 +257,8 @@ func logRotate() {
logFp.Close()
logFp = fp
}

Dup(int(logFp.Fd()), int(os.Stderr.Fd()))
}

func newHTTPRouter() *mux.Router {
Expand Down
Loading