log

package
v0.2.10-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2022 License: MIT Imports: 12 Imported by: 29

Documentation

Overview

Package log provides the both file and console (general) logging capabilities to spacemesh modules such as app and identity.

Index

Constants

View Source
const (

	// PeerIDKey is used to store the peer ID in the p2p stack.
	PeerIDKey correlationIDType
)

Variables

View Source
var Named = FieldNamed

Named is an alias to FieldNamed. FieldNamed returns a field with the provided name instead of the default.

Nop is an option that disables this logger.

Functions

func Debug

func Debug(msg string, args ...interface{})

Debug prints formatted debug level log message.

func Error

func Error(msg string, args ...interface{})

Error prints formatted error level log message.

func ExtractRequestID added in v0.1.27

func ExtractRequestID(ctx context.Context) (string, bool)

ExtractRequestID extracts the request id from a context object.

func ExtractSessionID added in v0.1.27

func ExtractSessionID(ctx context.Context) (string, bool)

ExtractSessionID extracts the session id from a context object.

func Info

func Info(msg string, args ...interface{})

Info prints formatted info level log message.

func JSONLog

func JSONLog(b bool)

JSONLog turns JSON format on or off.

func Panic

func Panic(msg string, args ...interface{})

Panic writes the log message and then panics.

func SetLogger added in v1.0.0

func SetLogger(logger Log)

SetLogger sets logger.

func SetupGlobal added in v1.0.0

func SetupGlobal(logger Log)

SetupGlobal overwrites global logger.

func Warning

func Warning(msg string, args ...interface{})

Warning prints formatted warning level log message.

func WithNewRequestID added in v0.1.27

func WithNewRequestID(ctx context.Context, fields ...LoggableField) context.Context

WithNewRequestID does the same thing as WithRequestID but generates a new, random requestId. It can be used when there isn't a single, clear, unique id associated with a request (e.g., a block or tx hash).

func WithNewSessionID added in v0.1.27

func WithNewSessionID(ctx context.Context, fields ...LoggableField) context.Context

WithNewSessionID does the same thing as WithSessionID but generates a new, random sessionId. It can be used when there isn't a single, clear, unique id associated with a session.

func WithRequestID added in v0.1.27

func WithRequestID(ctx context.Context, requestID string, fields ...LoggableField) context.Context

WithRequestID returns a context which knows its request ID. A request ID tracks the lifecycle of a single request across all execution contexts, including multiple goroutines, task queues, workers, etc. The canonical example is an incoming message received over the network. Rule of thumb: requests "traverse the heap" and may be passed from one session to another via channels. This requires a requestId string, and optionally, other LoggableFields that are added to context and printed in contextual logs.

func WithSessionID added in v0.1.27

func WithSessionID(ctx context.Context, sessionID string, fields ...LoggableField) context.Context

WithSessionID returns a context which knows its session ID A session ID tracks a single thread of execution. This may include multiple goroutines running concurrently, but it does not include asynchronous task execution such as task queues handled in separate threads. The canonical example is a single protocol routine, down to the point where an incoming request is either handled, or else handed off to another routine via a channel. Rule of thumb: sessions live entirely on the stack, and never on the heap (and should not be passed over channels). This requires a sessionId string, and optionally, other LoggableFields that are added to context and printed in contextual logs.

Types

type Field

type Field zap.Field

Field is a log field holding a name and value.

func Binary added in v1.0.0

func Binary(name string, val []byte) Field

Binary will encode binary content in base64 when logged.

func Bool

func Bool(name string, val bool) Field

Bool returns a bool field.

func Duration

func Duration(name string, val time.Duration) Field

Duration returns a duration field.

func Err

func Err(v error) Field

Err returns an error field.

func FieldNamed added in v0.1.15

func FieldNamed(name string, field LoggableField) Field

FieldNamed returns a field with the provided name instead of the default.

func Int

func Int(name string, val int) Field

Int returns an int Field.

func Int32

func Int32(name string, val int32) Field

Int32 returns an int32 Field.

func Namespace

func Namespace(name string) Field

Namespace make next fields be inside a namespace.

func String

func String(name, val string) Field

String returns a string Field.

func Stringer added in v1.0.0

func Stringer(name string, val fmt.Stringer) Field

Stringer returns an fmt.Sringer Field.

func Time added in v1.0.0

func Time(name string, val time.Time) Field

Time returns a field for time.Time struct value.

func Uint16 added in v1.0.0

func Uint16(name string, val uint16) Field

Uint16 returns an uint32 Field.

func Uint32

func Uint32(name string, val uint32) Field

Uint32 returns an uint32 Field.

func Uint64

func Uint64(name string, val uint64) Field

Uint64 returns an uint64 Field.

func (Field) Field added in v0.1.2

func (f Field) Field() Field

Field satisfies loggable field interface.

type FieldLogger added in v0.1.11

type FieldLogger struct {
	// contains filtered or unexported fields
}

FieldLogger is a logger that only logs messages with fields. It does not support formatting.

func Event

func Event() FieldLogger

Event returns a field logger with the Event field set to true.

func With

func With() FieldLogger

With returns a FieldLogger which you can append fields to.

func (FieldLogger) Debug added in v0.1.11

func (fl FieldLogger) Debug(msg string, fields ...LoggableField)

Debug prints message with fields.

func (FieldLogger) Error added in v0.1.11

func (fl FieldLogger) Error(msg string, fields ...LoggableField)

Error prints message with fields.

func (FieldLogger) Info added in v0.1.11

func (fl FieldLogger) Info(msg string, fields ...LoggableField)

Info prints message with fields.

func (FieldLogger) Panic added in v0.1.27

func (fl FieldLogger) Panic(msg string, fields ...LoggableField)

Panic prints message with fields.

func (FieldLogger) Warning added in v0.1.11

func (fl FieldLogger) Warning(msg string, fields ...LoggableField)

Warning prints message with fields.

type Level added in v0.1.11

type Level = zapcore.Level

Level is an alias to zapcore.Level.

func DefaultLevel added in v1.0.0

func DefaultLevel() Level

DefaultLevel returns the zapcore level of logging.

type Log

type Log struct {
	// contains filtered or unexported fields
}

Log is an exported type that embeds our logger.

var (
	AppLog Log
)

AppLog is the local app singleton logger.

func GetLogger added in v1.0.0

func GetLogger() Log

GetLogger gets logger.

func NewDefault

func NewDefault(module string) Log

NewDefault creates a Log with the default log level.

func NewFromLog added in v0.1.15

func NewFromLog(l *zap.Logger) Log

NewFromLog creates a Log from an existing zap-compatible log.

func NewNop added in v1.0.0

func NewNop() Log

NewNop creates silent logger.

func NewWithLevel added in v0.1.15

func NewWithLevel(module string, level zap.AtomicLevel, hooks ...func(zapcore.Entry) error) Log

NewWithLevel creates a logger with a fixed level and with a set of (optional) hooks.

func RegisterHooks added in v1.0.0

func RegisterHooks(lg Log, hooks ...func(zapcore.Entry) error) Log

RegisterHooks wraps provided loggers with hooks.

func (Log) Check added in v1.0.0

func (l Log) Check(level zapcore.Level) bool

Check if following level is supported by the logger.

func (Log) Core added in v1.0.0

func (l Log) Core() zapcore.Core

Core returns logger engine.

func (Log) Debug

func (l Log) Debug(format string, args ...interface{})

Debug prints formatted debug level log message.

func (Log) Error

func (l Log) Error(format string, args ...interface{})

Error prints formatted error level log message.

func (Log) Event

func (l Log) Event() FieldLogger

Event returns a logger with the Event field appended to it.

func (Log) Info

func (l Log) Info(format string, args ...interface{})

Info prints formatted info level log message.

func (Log) Named added in v1.0.0

func (l Log) Named(name string) Log

Named overwrites name.

func (Log) Panic

func (l Log) Panic(format string, args ...interface{})

Panic prints the log message and then panics.

func (Log) SetLevel added in v0.1.2

func (l Log) SetLevel(level *zap.AtomicLevel) Log

SetLevel returns a logger with level as the log level derived from l.

func (Log) Warning

func (l Log) Warning(format string, args ...interface{})

Warning prints formatted warning level log message.

func (Log) With

func (l Log) With() FieldLogger

With returns a logger object that logs fields.

func (Log) WithContext added in v0.1.27

func (l Log) WithContext(ctx context.Context) Log

WithContext creates a Log from an existing log and a context object.

func (Log) WithFields

func (l Log) WithFields(fields ...LoggableField) Log

WithFields returns a logger with fields permanently appended to it.

func (Log) WithName

func (l Log) WithName(prefix string) Log

WithName appends a name to a current name.

func (Log) WithOptions

func (l Log) WithOptions(opts ...zap.Option) Log

WithOptions clones the current Logger, applies the supplied Options, and returns the resulting Logger. It's safe to use concurrently.

type LoggableField added in v0.1.2

type LoggableField interface {
	Field() Field
}

LoggableField as an interface to enable every type to be used as a log field.

func ExtractRequestFields added in v0.1.27

func ExtractRequestFields(ctx context.Context) (fields []LoggableField)

ExtractRequestFields extracts additional loggable fields associated with the request from a context object.

func ExtractSessionFields added in v0.1.27

func ExtractSessionFields(ctx context.Context) (fields []LoggableField)

ExtractSessionFields extracts additional loggable fields associated with the session from a context object.

type Logger

type Logger interface {
	Info(format string, args ...interface{})
	Debug(format string, args ...interface{})
	Error(format string, args ...interface{})
	Warning(format string, args ...interface{})
	With() FieldLogger
	WithContext(context.Context) Log
	WithName(string) Log
}

Logger is an interface for our logging API.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL