Skip to content

Commit

Permalink
refact(zap): custom lumberjack with sync.WaitGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
Matrix-X committed Jun 22, 2024
1 parent dce1335 commit 768fb31
Show file tree
Hide file tree
Showing 7 changed files with 1,477 additions and 1 deletion.
5 changes: 4 additions & 1 deletion logger/drivers/zap/log.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package zap

import (
"github.com/ArtisanCloud/PowerLibs/v3/fmt"
"github.com/ArtisanCloud/PowerLibs/v3/logger/contract"
lumberjack "github.com/ArtisanCloud/PowerLibs/v3/logger/lib"
"github.com/ArtisanCloud/PowerLibs/v3/object"
os2 "github.com/ArtisanCloud/PowerLibs/v3/os"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"gopkg.in/natefinch/lumberjack.v2"
"os"
"time"
)
Expand Down Expand Up @@ -71,6 +72,8 @@ func newZapLogger(config *object.HashMap) (logger *zap.Logger, err error) {
Compress: true, // disabled by default
})

fmt.Dump(outputWriter)

//errorSyncer, err := newFileWriteSyncer(errorFile)
//if err != nil {
// return nil, err
Expand Down
11 changes: 11 additions & 0 deletions logger/lib/chown.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build !linux

package lumberjack

import (
"os"
)

func chown(_ string, _ os.FileInfo) error {
return nil
}
19 changes: 19 additions & 0 deletions logger/lib/chown_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package lumberjack

import (
"os"
"syscall"
)

// osChown is a var so we can mock it out during tests.
var osChown = os.Chown

func chown(name string, info os.FileInfo) error {
f, err := os.OpenFile(name, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, info.Mode())
if err != nil {
return err
}
f.Close()
stat := info.Sys().(*syscall.Stat_t)
return osChown(name, int(stat.Uid), int(stat.Gid))
}
Loading

0 comments on commit 768fb31

Please sign in to comment.