package
0.0.0-20240707130328-7cf8dae7750a
Repository: https://github.com/nite-coder/blackbear.git
Documentation: pkg.go.dev
# README
log
It is a simple structured logging package for Go.
Features
- fast, easy to use, and pretty logging for development
- low to zero allocation
- JSON encoding format
- colored text for text handler
context.Context
integration
Handlers
- Text (development use)
- JSON (default, Production)
Installation
Use go get
go get -u github.com/nite-coder/blackbear
Get Started
package main
import (
"os"
"github.com/nite-coder/blackbear/pkg/log"
"github.com/nite-coder/blackbear/pkg/log/handler/text"
)
func main() {
// json handler
log.Debug().Msg("Hello World") // output: {"time":"2023-06-23T06:17:43Z","level":"DEBUG","msg":"Hello World"}
// text handler
opts := log.HandlerOptions{
Level: log.DebugLevel,
DisableTime: true,
}
logger := log.New(text.New(os.Stderr, &opts))
log.SetDefault(logger)
log.Debug().Msg("Hello World") // output: 06:17:43.991 DEBUG Hello World
}
Fields
package main
import (
"github.com/nite-coder/blackbear/pkg/log"
)
func main() {
// example1
logger := log.With().Str("app_id", "blackbear").Logger()
logger.Debug().Msg("Hello World")
// example2
log.Debug().Str("request_id", "abc").Msg("cool")
}
Pass Context
package main
import (
"github.com/nite-coder/blackbear/pkg/log"
)
func main() {
ctx := context.Background()
log.DebugCtx(ctx).Str("request_id", "abc").Msg("cool")
}
insipred by zerolog
# Packages
No description provided by the author
# Functions
Debug logs at DebugLevel.
DebugCtx logs at LevelDebug with the given context.
No description provided by the author
Error level formatted message.
ErrorCtx logs at ErrorLevel with the given context.
Fatal level formatted message, followed by an exit.
FatalCtx logs at FatalLevel with the given context.
Flush clear all handler's buffer.
FromContext return a logger from the standard context.
Info logs at InfoLevel.
InfoCtx logs at InfoLevel with the given context.
No description provided by the author
No description provided by the author
NewLevel returns Level struct.
New create a new Console instance.
Panic level formatted message.
PanicCtx logs at PanicLevel with the given context.
SetDefault makes l the default Logger.
Warn logs at WarnLevel.
WarnCtx logs at WarnLevel with the given context.
No description provided by the author
# Constants
Log levels.
Log levels.
Log levels.
Log levels.
Log levels.
Log levels.
Log levels.
# Structs
Context use for meta data.
Entry defines a single log entry.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
TextHandler is an instance of the text handler.
# Type aliases
Level of the log.