Skip to content

Commit

Permalink
Merge pull request #2 from glin-gogogo/master
Browse files Browse the repository at this point in the history
fix log
  • Loading branch information
glin-gogogo authored Jan 16, 2025
2 parents f440473 + 36295fc commit e414dc5
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 29 deletions.
26 changes: 0 additions & 26 deletions dflog/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ package dflog
import (
"fmt"
"os"
"path"
"strconv"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"golang.org/x/sys/unix"
"google.golang.org/grpc/grpclog"
)

Expand Down Expand Up @@ -301,27 +299,3 @@ func (z *zapGrpc) Fatalln(args ...any) {
func (z *zapGrpc) V(level int) bool {
return level <= z.verbose
}

// Redirect stdout and stderr to file for debugging.
func RedirectStdoutAndStderr(console bool, logDir string) {
// When console log is enabled, skip redirect.
if console {
return
}

// Redirect stdout to stdout.log file.
stdoutPath := path.Join(logDir, "stdout.log")
if stdout, err := os.OpenFile(stdoutPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND|os.O_SYNC, 0644); err != nil {
Warnf("open %s error: %s", stdoutPath, err)
} else if err := unix.Dup2(int(stdout.Fd()), int(os.Stdout.Fd())); err != nil {
Warnf("redirect stdout error: %s", err)
}

// Redirect stderr to stderr.log file.
stderrPath := path.Join(logDir, "stderr.log")
if stderr, err := os.OpenFile(stderrPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND|os.O_SYNC, 0644); err != nil {
Warnf("open %s error: %s", stderrPath, err)
} else if err := unix.Dup2(int(stderr.Fd()), int(os.Stderr.Fd())); err != nil {
Warnf("redirect stderr error: %s", err)
}
}
4 changes: 2 additions & 2 deletions dflog/loginit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package dflog

import (
"github.com/urchinfs/sugon-sdk/types"
"go.uber.org/zap"
"path"
"path/filepath"
"go.uber.org/zap"
"github.com/urchinfs/sugon-sdk/types"
)

type logInitMeta struct {
Expand Down
2 changes: 1 addition & 1 deletion dflog/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (

func startLoggerSignalHandler() {
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGUSR1)
signal.Notify(signals, syscall.SIGINT)

go func() {
for {
Expand Down
Binary file removed test.zip
Binary file not shown.

0 comments on commit e414dc5

Please sign in to comment.