-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(log):add zap library and logging capabilities
- fix write bug, mv don't need to delete temp file. - add some unit tests. - fix fs open bug, check and auto create dir. - refactoring space, add mutex.
- Loading branch information
Showing
15 changed files
with
380 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package common | ||
|
||
const KReadBatchSize = 1024 | ||
const KManifestTempFileName = "manifest.tmp" | ||
const KManifestFileName = "manifest" | ||
const KManifestTempFileName = ".manifest.tmp" | ||
const KManifestFileName = ".manifest" | ||
const KManifestDir = "versions" | ||
const KParquetDataFileSuffix = ".parquet" | ||
const KParquetDataDir = "data" | ||
const KOffsetFieldName = "__offset" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package log | ||
|
||
import "go.uber.org/zap" | ||
|
||
var ( | ||
// not lint | ||
Skip = zap.Skip | ||
Binary = zap.Binary | ||
Bool = zap.Bool | ||
Boolp = zap.Boolp | ||
ByteString = zap.ByteString | ||
Complex128 = zap.Complex128 | ||
Complex128p = zap.Complex128p | ||
Complex64 = zap.Complex64 | ||
Complex64p = zap.Complex64p | ||
Float64 = zap.Float64 | ||
Float64p = zap.Float64p | ||
Float32 = zap.Float32 | ||
Float32p = zap.Float32p | ||
Int = zap.Int | ||
Intp = zap.Intp | ||
Int64 = zap.Int64 | ||
Int64p = zap.Int64p | ||
Int32 = zap.Int32 | ||
Int32p = zap.Int32p | ||
Int16 = zap.Int16 | ||
Int16p = zap.Int16p | ||
Int8 = zap.Int8 | ||
Int8p = zap.Int8p | ||
String = zap.String | ||
Stringp = zap.Stringp | ||
Uint = zap.Uint | ||
Uintp = zap.Uintp | ||
Uint64 = zap.Uint64 | ||
Uint64p = zap.Uint64p | ||
Uint32 = zap.Uint32 | ||
Uint32p = zap.Uint32p | ||
Uint16 = zap.Uint16 | ||
Uint16p = zap.Uint16p | ||
Uint8 = zap.Uint8 | ||
Uint8p = zap.Uint8p | ||
Uintptr = zap.Uintptr | ||
Uintptrp = zap.Uintptrp | ||
Reflect = zap.Reflect | ||
Namespace = zap.Namespace | ||
Stringer = zap.Stringer | ||
Time = zap.Time | ||
Timep = zap.Timep | ||
Stack = zap.Stack | ||
StackSkip = zap.StackSkip | ||
Duration = zap.Duration | ||
Durationp = zap.Durationp | ||
Object = zap.Object | ||
Inline = zap.Inline | ||
Any = zap.Any | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package log | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
) | ||
|
||
type Level = zapcore.Level | ||
|
||
const ( | ||
DebugLevel = zapcore.DebugLevel | ||
InfoLevel = zapcore.InfoLevel | ||
WarnLevel = zapcore.WarnLevel | ||
ErrorLevel = zapcore.ErrorLevel | ||
PanicLevel = zapcore.PanicLevel | ||
FatalLevel = zapcore.FatalLevel | ||
) | ||
|
||
type Logger struct { | ||
l *zap.Logger | ||
al *zap.AtomicLevel | ||
} | ||
|
||
func New(out io.Writer, level Level) *Logger { | ||
if out == nil { | ||
out = os.Stderr | ||
} | ||
|
||
al := zap.NewAtomicLevelAt(level) | ||
cfg := zap.NewDevelopmentEncoderConfig() | ||
|
||
core := zapcore.NewCore( | ||
zapcore.NewConsoleEncoder(cfg), | ||
zapcore.AddSync(out), | ||
al, | ||
) | ||
return &Logger{l: zap.New(core, zap.AddCaller(), zap.AddCallerSkip(2)), al: &al} | ||
} | ||
|
||
func (l *Logger) SetLevel(level Level) { | ||
if l.al != nil { | ||
l.al.SetLevel(level) | ||
} | ||
} | ||
|
||
type Field = zap.Field | ||
|
||
func (l *Logger) Debug(msg string, fields ...Field) { | ||
l.l.Debug(msg, fields...) | ||
} | ||
|
||
func (l *Logger) Info(msg string, fields ...Field) { | ||
l.l.Info(msg, fields...) | ||
} | ||
|
||
func (l *Logger) Warn(msg string, fields ...Field) { | ||
l.l.Warn(msg, fields...) | ||
} | ||
|
||
func (l *Logger) Error(msg string, fields ...Field) { | ||
l.l.Error(msg, fields...) | ||
} | ||
|
||
func (l *Logger) Panic(msg string, fields ...Field) { | ||
l.l.Panic(msg, fields...) | ||
} | ||
|
||
func (l *Logger) Fatal(msg string, fields ...Field) { | ||
l.l.Fatal(msg, fields...) | ||
} | ||
|
||
func (l *Logger) Sync() error { | ||
return l.l.Sync() | ||
} | ||
|
||
var std = New(os.Stderr, DebugLevel) | ||
|
||
func Default() *Logger { return std } | ||
func ReplaceDefault(l *Logger) { std = l } | ||
func SetLevel(level Level) { std.SetLevel(level) } | ||
|
||
func Debug(msg string, fields ...Field) { std.Debug(msg, fields...) } | ||
func Info(msg string, fields ...Field) { std.Info(msg, fields...) } | ||
func Warn(msg string, fields ...Field) { std.Warn(msg, fields...) } | ||
func Error(msg string, fields ...Field) { std.Error(msg, fields...) } | ||
func Panic(msg string, fields ...Field) { std.Panic(msg, fields...) } | ||
func Fatal(msg string, fields ...Field) { std.Fatal(msg, fields...) } | ||
|
||
func Sync() error { return std.Sync() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package log | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestLogger(t *testing.T) { | ||
defer Sync() | ||
Info("Testing") | ||
Debug("Testing") | ||
Warn("Testing") | ||
Error("Testing") | ||
defer func() { | ||
if err := recover(); err != nil { | ||
Debug("logPanic recover") | ||
} | ||
}() | ||
Panic("Testing") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package log | ||
|
||
import "go.uber.org/zap" | ||
|
||
type Option = zap.Option | ||
|
||
var ( | ||
WrapCore = zap.WrapCore | ||
Hooks = zap.Hooks | ||
Fields = zap.Fields | ||
ErrorOutput = zap.ErrorOutput | ||
Development = zap.Development | ||
AddCaller = zap.AddCaller | ||
WithCaller = zap.WithCaller | ||
AddCallerSkip = zap.AddCallerSkip | ||
AddStacktrace = zap.AddStacktrace | ||
IncreaseLevel = zap.IncreaseLevel | ||
WithFatalHook = zap.WithFatalHook | ||
WithClock = zap.WithClock | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.