# README
wzap
A wrapper of zap supporting file rotating and more humanfriendly console output.
Quick Start
file writer.
package main
import "github.com/sevenNt/wzap"
var logger = wzap.New(
wzap.WithPath("/tmp/async.log"), // set log path.
wzap.WithLevel(wzap.Error), // set log minimum level.
)
func main() {
logger.Info("some information about LiLei",
"name", "LiLei",
"age", 17,
"sex", "male",
)
}
Fan-out
package main
import "github.com/sevenNt/wzap"
var logger = wzap.New(
// add a file writer.
wzap.WithPath("/tmp/sync.log"),
wzap.WithLevel(wzap.Error),
wzap.WithOutput(
wzap.WithOutput(
// add another file writer.
wzap.WithLevel(wzap.Info),
wzap.WithPath("/tmp/info.log"),
),
// add a console writer.
wzap.WithOutput(
wzap.WithLevelMask(wzap.DebugLevel|wzap.InfoLevel|wzap.WarnLevel),
wzap.WithColorful(true),
wzap.WithPrefix("H"),
wzap.WithAsync(false),
),
// add an another file writer.
wzap.WithOutput(
wzap.WithLevelMask(wzap.FatalLevel|wzap.ErrorLevel),
wzap.WithPath("/tmp/error.log")
),
)
)
func main() {
logger.Errorf("sync write %s", "How are you? I'm fine, thank you.")
logger.Debug("debug")
logger.Info("info")
logger.Warn("warn")
logger.Error("error")
}
setting default fields.
- setting global default fields.
wzap.SetDefaultFields(
wzap.String("aid", "12341234"),
wzap.String("iid", "187281f-f983891-ff01923"),
wzap.String("tid", "dasfasd-123asf-314dasfa"),
)
- setting default fields for single logger instance.
logger := wzap.New(
wzap.WithLevel(wzap.Info),
wzap.WithPath("./defaultLogger.log"),
wzap.WithFields(wzap.Int("appid", 100010), wzap.String("appname", "test-go")),
)
wzap.SetDefaultLogger(logger)
wzap.Debug("debug")
# Packages
No description provided by the author
# Functions
Any takes a key and an arbitrary value and chooses the best way to represent them as a field, falling back to a reflection-based approach only if necessary.
Array constructs a field with the given key and ArrayMarshaler.
Binary constructs a field that carries an opaque binary blob.
Bool constructs a field that carries a bool.
Bools constructs a field that carries a slice of bools.
ByteString constructs a field that carries UTF-8 encoded text as a []byte.
ByteStrings constructs a field that carries a slice of []byte, each of which must be UTF-8 encoded text.
CheckErr checks error with default logger.
Complex128 constructs a field that carries a complex number.
Complex128s constructs a field that carries a slice of complex numbers.
Complex64 constructs a field that carries a complex number.
Complex64s constructs a field that carries a slice of complex numbers.
Debug logs debug level messages with default logger.
Debugf logs debug level messages with default logger in printf-style.
Default returns a default Logger instance.
DefaultDir gets defaultDir.
DefaultFields gets defaultFields.
Duration constructs a field with the given key and value.
Durations constructs a field that carries a slice of time.Durations.
Err is shorthand for the common idiom NamedError("error", err).
Error logs Error level messages with default logger in structured-style.
Errorf logs Error level messages with default logger in printf-style.
Errors constructs a field that carries a slice of errors.
Fatal logs Fatal level messages with default logger in structured-style.
Fatalf logs Fatalf level messages with default logger in printf-style.
Float32 constructs a field that carries a float32.
Float32s constructs a field that carries a slice of floats.
Float64 constructs a field that carries a float64.
Float64s constructs a field that carries a slice of floats.
Info logs Info level messages with default logger in structured-style.
Infof logs Info level messages with default logger in printf-style.
Int constructs a field with the given key and value.
Int16 constructs a field with the given key and value.
Int16s constructs a field that carries a slice of integers.
Int32 constructs a field with the given key and value.
Int32s constructs a field that carries a slice of integers.
Int64 constructs a field with the given key and value.
Int64s constructs a field that carries a slice of integers.
Int8 constructs a field with the given key and value.
Int8s constructs a field that carries a slice of integers.
Ints constructs a field that carries a slice of integers.
Log returns logger with provided name.
NamedErr constructs a field that lazily stores err.Error() under the provided key.
Namespace creates a named, isolated scope within the logger's context.
New constructs a new Logger instance.
NewConsoleWriter constructs a new ConsoleWriter instance.
NewZapWriter constructs a new ZapWriter instance.
Object constructs a field with the given key and ObjectMarshaler.
Panic logs Panic level messages with default logger in structured-style.
Panicf logs Panicf level messages with default logger in printf-style.
Reflect constructs a field with the given key and an arbitrary object.
Register registers logger into loggers.
SetDefaultDir sets default directory of all zap writer logger.
SetDefaultFields sets default fields of all logger.
SetDefaultFileSuffix sets default file suffix.
SetDefaultLogger sets default logger with provided logger.
Skip constructs a no-op field, which is often useful when handling invalid inputs in other Field constructors.
String constructs a field with the given key and value.
Stringer constructs a field with the given key and the output of the value's String method.
Strings constructs a field that carries a slice of strings.
Sync syncs logger messages.
Time constructs a zapcore.Field with the given key and value.
Times constructs a field that carries a slice of time.Times.
Uint constructs a field with the given key and value.
Uint16 constructs a field with the given key and value.
Uint16s constructs a field that carries a slice of unsigned integers.
Uint32 constructs a field with the given key and value.
Uint32s constructs a field that carries a slice of unsigned integers.
Uint64 constructs a field with the given key and value.
Uint64s constructs a field that carries a slice of unsigned integers.
Uint8 constructs a field with the given key and value.
Uint8s constructs a field that carries a slice of unsigned integers.
Uintptr constructs a field with the given key and value.
Uintptrs constructs a field that carries a slice of pointer addresses.
Uints constructs a field that carries a slice of unsigned integers.
Warn logs Warn level messages with default logger in structured-style.
Warnf logs Warn level messages with default logger in printf-style.
WDebug logs debug level messages with default logger.
WDebugf logs debug level messages with default logger.
WError logs Error level messages with default logger in structured-style.
WErrorf logs Error level messages with default logger in printf-style.
WFatal logs Fatal level messages with default logger in structured-style.
WFatalf logs Fatalf level messages with default logger in printf-style.
WInfo logs Info level messages with default logger in structured-style.
WInfof logs Info level messages with default logger in structured-style.
WithAsync configures the console-log's async trigger.
WithColorful configures the console-log's colorful trigger.
WithFields adds fields to the Logger.
WithLevel configures logger minimum level.
WithLevelCombo configures the Logger enabled levels with level combos.
WithLevelMask configures logger enabled levels with level masks.
WithLevelString configures the Logger enabled levels with combined level string.
WithName adds name to the Logger.
WithOutput adds log a new writer with options.
WithOutputKV adds logger a new writer with KV.
WithOutputKVs adds logger a new writer with KVs.
WithPath configures logger path.
WithPrefix configures the console-log's prefix.
WPanic logs Panic level messages with default logger in structured-style.
WPanicf logs Panicf level messages with default logger in printf-style.
WWarn logs Warn level messages with default logger in structured-style.
WWarnf logs Warn level messages with default logger in printf-style.
# Constants
No description provided by the author
DebugLevel logs are typically voluminous, and are usually disabled in production.
ErrorLevel logs are high-priority.
FatalLevel logs a message, then calls os.Exit(1).
InfoLevel is the default logging priority.
PanicLevel logs a message, then panics.
WarnLevel logs are more important than Info, but don't need individual human review.
# Structs
ConsoleWriter will print logger mesgaes into console.
Logger is an interface supports printf-style and structured-style logging.
Options wraps logger options.
A ZapWriter wraps the zap.SugarWriter.
# Interfaces
Writer defines logger's writer.