Documentation
¶
Overview ¶
Package log logging library.
import "gitee.com/go-wares/log" func main() { // Call close when main function end to report log and span to // reporter. Log or span will be discarded if not called. defer log.Close() // You can call like follows at any code point. log.Info("info message") log.Infof("info message with: %d", 1) // With fields for logging. log.Field{ "captcha": "9981", "mobile": "13966013721", }.Info("info message") }
Index ¶
- func Close()
- func Config() *conf.Config
- func ContextHeaders(ctx context.Context) map[string]string
- func Debug(text string)
- func Debugf(format string, args ...any)
- func Debugfc(ctx context.Context, format string, args ...any)
- func Error(text string)
- func Errorf(format string, args ...any)
- func Errorfc(ctx context.Context, format string, args ...any)
- func Fatal(text string)
- func Fatalf(format string, args ...any)
- func Fatalfc(ctx context.Context, format string, args ...any)
- func Info(text string)
- func Infof(format string, args ...any)
- func Infofc(ctx context.Context, format string, args ...any)
- func NewContext(ctx ...context.Context) context.Context
- func Panic(text string)
- func Panicf(format string, args ...any)
- func Panicfc(ctx context.Context, format string, args ...any)
- func Warn(text string)
- func Warnf(format string, args ...any)
- func Warnfc(ctx context.Context, format string, args ...any)
- type Field
- func (o Field) Debug(text string)
- func (o Field) Debugf(format string, args ...any)
- func (o Field) Debugfc(ctx context.Context, format string, args ...any)
- func (o Field) Error(text string)
- func (o Field) Errorf(format string, args ...any)
- func (o Field) Errorfc(ctx context.Context, format string, args ...any)
- func (o Field) Fatal(text string)
- func (o Field) Fatalf(format string, args ...any)
- func (o Field) Fatalfc(ctx context.Context, format string, args ...any)
- func (o Field) Info(text string)
- func (o Field) Infof(format string, args ...any)
- func (o Field) Infofc(ctx context.Context, format string, args ...any)
- func (o Field) Warn(text string)
- func (o Field) Warnf(format string, args ...any)
- func (o Field) Warnfc(ctx context.Context, format string, args ...any)
- type Management
- func (o *Management) Config() *conf.Config
- func (o *Management) ConfigLoggerAdapter(adapter base.Adapter)
- func (o *Management) ConfigTracerReporter(tracer base.Tracer)
- func (o *Management) GetLoggerAdapter() base.Logger
- func (o *Management) GetTracerReporter() base.Reporter
- func (o *Management) Log(ctx context.Context, field map[string]any, level base.Level, format string, ...)
- func (o *Management) LogItem(item *base.Item)
- func (o *Management) Report(span base.Span)
- func (o *Management) StopAndWait()
- type Span
Examples ¶
- Config
- ContextHeaders
- Debug
- Debugf
- Debugfc
- Error
- Errorf
- Errorfc
- Fatal
- Fatalf
- Fatalfc
- Field.Debug
- Field.Error
- Field.Fatal
- Field.Info
- Field.Warn
- Info
- Infof
- Infofc
- Management.Config
- Management.GetLoggerAdapter
- Management.GetTracerReporter
- NewContext
- NewSpan
- NewSpanWithContext
- NewSpanWithRequest
- Panic
- Panicf
- Panicfc
- Warn
- Warnf
- Warnfc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Close ¶
func Close()
Close logging and span reporter. This should be called in main function before exited.
func main(){ defer log.Close() ... }
func Config ¶
Config returns the configuration of log.
conf := log.Config() conf := log.Manager.Config()
Example ¶
cfg := Config() fmt.Printf("config: %+v\n", cfg) // level: DEBUG
Output:
func ContextHeaders ¶
ContextHeaders creates the headers map from a context.
Example ¶
ctx := NewContext() headers := ContextHeaders(ctx) for key, value := range headers { println("header: key =", key, " & value =", value) } // header: key = X-B3-TraceId & value = 90e1e3641c9a3ffcb8b9fce8b71463d5 // header: key = X-B3-SpanId & value = fdcedf10be021b59 // header: key = X-B3-Version & value = 0
Output:
func Debug ¶
func Debug(text string)
Debug send debug level log.
Example ¶
Debug("debug message")
Output:
func Debugf ¶
Debugf send debug level log with standard format.
Example ¶
Debugf("debug message with: %s", "formatter")
Output:
func Debugfc ¶
Debugfc send debug level log with context and standard format.
Example ¶
ctx := NewContext() Debugfc(ctx, "debug message with: %s", "formatter and context")
Output:
func Error ¶
func Error(text string)
Error send error level log.
Example ¶
Error("error message")
Output:
func Errorf ¶
Errorf send error level log with standard format.
Example ¶
Errorf("error message with: %s", "formatter")
Output:
func Errorfc ¶
Errorfc send error level log with context and standard format.
Example ¶
ctx := NewContext() Errorfc(ctx, "error message with: %s", "formatter and context")
Output:
func Fatal ¶
func Fatal(text string)
Fatal send fatal level log.
Example ¶
Fatal("fatal message")
Output:
func Fatalf ¶
Fatalf send fatal level log with standard format.
Example ¶
Fatalf("fatal message with: %s", "formatter")
Output:
func Fatalfc ¶
Fatalfc send fatal level log with context and standard format.
Example ¶
ctx := NewContext() Fatalfc(ctx, "fatal message with: %s", "formatter and context")
Output:
func Infof ¶
Infof send info level log with standard format.
Example ¶
Infof("info message with: %s", "formatter")
Output:
func Infofc ¶
Infofc send info level log with context and standard format.
Example ¶
ctx := NewContext() Infofc(ctx, "info message with: %s", "formatter and context")
Output:
func NewContext ¶
NewContext creates a new context with a tracing component.
Example ¶
ctx := NewContext() fmt.Printf("context: %v\n", ctx)
Output:
func Panic ¶
func Panic(text string)
Panic send fatal level log.
Example ¶
Panic("panic message")
Output:
func Panicf ¶
Panicf send fatal level log with standard format.
Example ¶
Panicf("panic message with: %s", "formatter")
Output:
func Panicfc ¶
Panicfc send fatal level log with context and standard format.
Example ¶
ctx := NewContext() Panicfc(ctx, "panic message with: %s", "formatter and context")
Output:
Types ¶
type Field ¶
Field is a map of key-value pairs.
- log.Field{"key": "value"}.Info()
func (Field) Debug ¶
Debug send debug level log.
Example ¶
Field{ "Key": "value", }.Debug("debug message")
Output:
func (Field) Error ¶
Error send error level log.
Example ¶
Field{ "Key": "value", }.Error("error message")
Output:
func (Field) Fatal ¶
Fatal send fatal level log.
Example ¶
Field{ "Key": "value", }.Fatal("fatal message")
Output:
func (Field) Info ¶
Info send info level log.
Example ¶
Field{ "Key": "value", }.Info("info message")
Output:
func (Field) Warn ¶
Warn send warn level log.
Example ¶
Field{ "Key": "value", }.Warn("warn message")
Output:
type Management ¶
type Management struct {
// contains filtered or unexported fields
}
Management is a component for managing logging and trace.
var ( // Manager // is a component for managing logging and trace. Manager *Management )
func (*Management) Config ¶
func (o *Management) Config() *conf.Config
Config returns the configuration of the log management.
Example ¶
// Config is initialized from config file. // Path: config/log.yaml cfg := Manager.Config() // You can override configured values. cfg.SetAdapter("term") cfg.SetLevel("debug") println("debug status: ", cfg.DebugOn())
Output:
func (*Management) ConfigLoggerAdapter ¶
func (o *Management) ConfigLoggerAdapter(adapter base.Adapter)
ConfigLoggerAdapter configure the logger adapter.
func (*Management) ConfigTracerReporter ¶
func (o *Management) ConfigTracerReporter(tracer base.Tracer)
ConfigTracerReporter configure the tracer reporter.
func (*Management) GetLoggerAdapter ¶
func (o *Management) GetLoggerAdapter() base.Logger
GetLoggerAdapter returns the latest logger adapter.
Example ¶
// Define your formatter. formatter := &term.Formatter{} // Override default formatter. adapter := Manager.GetLoggerAdapter() adapter.SetFormatter(formatter)
Output:
func (*Management) GetTracerReporter ¶
func (o *Management) GetTracerReporter() base.Reporter
GetTracerReporter returns the latest tracer reporter.
Example ¶
// Define your formatter. formatter := &jaeger.Formatter{} // Override default formatter. reporter := Manager.GetTracerReporter() reporter.SetFormatter(formatter)
Output:
func (*Management) Log ¶
func (o *Management) Log(ctx context.Context, field map[string]any, level base.Level, format string, args ...any)
Log report the log with level and contents.
func (*Management) LogItem ¶
func (o *Management) LogItem(item *base.Item)
LogItem report the log with item.
func (*Management) Report ¶
func (o *Management) Report(span base.Span)
Report reports the span of a trace.
func (*Management) StopAndWait ¶
func (o *Management) StopAndWait()
StopAndWait stops the log management and waits for the log to be reported.
type Span ¶
Span is an interface for call chain span.
func NewSpan ¶
NewSpan creates a new span component.
Example ¶
span := NewSpan("test") defer span.End() span.Info("info log on a span")
Output:
func NewSpanWithContext ¶
NewSpanWithContext creates a new span component.
Example ¶
span := NewSpanWithContext(nil, "example") defer span.End() span.SetAttr("key", "value") span.Info("info log on a span")
Output:
func NewSpanWithHeader ¶ added in v0.1.11
Directories
¶
Path | Synopsis |
---|---|
Package conf is a component that defines the log configuration.
|
Package conf is a component that defines the log configuration. |
plugins
|
|
reporters/zipkin/model
Package model contains the Zipkin V2 model which is used by the Zipkin Go tracer implementation.
|
Package model contains the Zipkin V2 model which is used by the Zipkin Go tracer implementation. |