Documentation
¶
Index ¶
Constants ¶
View Source
const ( FIELD_TRACE_ID = "trace_id" FIELD_SPAN_ID = "span_id" )
View Source
const ( DefaultLogLevel = InfoLevel DefaultLogLevelString = "info" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Level ¶
type Level int8
const ( // TraceLevel level. Designates finer-grained informational events than the Debug. TraceLevel Level = iota - 2 // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel // InfoLevel is the default logging priority. // General operational entries about what's going on inside the application. InfoLevel // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. ErrorLevel // FatalLevel level. Logs and then calls `logger.Exit(1)`. highest level of severity. FatalLevel )
func GetLevel ¶
GetLevel converts a level string into a logger Level value. returns an error if the input string does not match known values.
type Logger ¶
type Logger interface { // Init initializes options Init(options ...Option) error // The Logger options Options() Options // Fields set fields to always be logged Fields(fields map[string]interface{}) Logger // Log writes a log entry Log(ctx context.Context, level Level, args ...interface{}) // Logf writes a formatted log entry Logf(ctx context.Context, level Level, format string, args ...interface{}) // Log Trace Trace(ctx context.Context, args ...interface{}) // Logf Trace Tracef(ctx context.Context, format string, args ...interface{}) // Log Debug Debug(ctx context.Context, args ...interface{}) // Logf Debug Debugf(ctx context.Context, format string, args ...interface{}) // Log Info Info(ctx context.Context, args ...interface{}) // Logf Info Infof(ctx context.Context, format string, args ...interface{}) // Log Warn Warn(ctx context.Context, args ...interface{}) // Logf Warn Warnf(ctx context.Context, format string, args ...interface{}) // Log Error Error(ctx context.Context, args ...interface{}) // Logf Error Errorf(ctx context.Context, format string, args ...interface{}) // Log Fatal Fatal(ctx context.Context, args ...interface{}) // Logf Fatal Fatalf(ctx context.Context, format string, args ...interface{}) // String returns the name of logger String() string }
type Option ¶
type Option func(*Options)
func WithCallerSkipCount ¶
WithCallerSkipCount set frame count to skip.
func WithFields ¶
WithFields set default fields for the logger.
func WithOutput ¶
WithOutput set default output writer for the logger.
func WithTracer ¶
type Options ¶
type Options struct { // It's common to set this to a file, or leave it default which is `os.Stderr` Out io.Writer // fields to always be logged Fields map[string]interface{} // Caller skip frame count for file:line info CallerSkipCount int // The logging level the logger should log at. default is `InfoLevel` Level Level // Alternative options Context context.Context //tracer for extract Trace ID, Span ID Tracer trace.Tracer }
Click to show internal directories.
Click to hide internal directories.