Documentation ¶
Index ¶
- func Debug(ctx context.Context, msg string)
- func Debugf(ctx context.Context, msg string, args ...interface{})
- func Error(ctx context.Context, msg string)
- func Errorf(ctx context.Context, msg string, args ...interface{})
- func Fatal(ctx context.Context, msg string)
- func Fatalf(ctx context.Context, msg string, args ...interface{})
- func Info(ctx context.Context, msg string)
- func Infof(ctx context.Context, msg string, args ...interface{})
- func SetGlobal(l Logger)
- func Warn(ctx context.Context, msg string)
- func Warnf(ctx context.Context, msg string, args ...interface{})
- type DefaultLogger
- func (l *DefaultLogger) EventOptions() []EventOption
- func (l *DefaultLogger) LogEntryOptions() []LogEntryOption
- func (l *DefaultLogger) SetEncoder(enc Encoder)
- func (l *DefaultLogger) SetEventOptions(opts ...EventOption)
- func (l *DefaultLogger) SetLogEntryOptions(opts ...LogEntryOption)
- func (l *DefaultLogger) StreamEvent(event *Event)
- func (l *DefaultLogger) StreamLogEntry(entry *LogEntry)
- type Encoder
- type Event
- type EventOption
- type Eventful
- type JSONEncoder
- type LogEntry
- func (e *LogEntry) Debug(ctx context.Context, message string)
- func (e *LogEntry) Debugf(ctx context.Context, message string, args ...interface{})
- func (e *LogEntry) Error(ctx context.Context, message string)
- func (e *LogEntry) Errorf(ctx context.Context, message string, args ...interface{})
- func (e *LogEntry) Fatal(ctx context.Context, message string)
- func (e *LogEntry) Fatalf(ctx context.Context, message string, args ...interface{})
- func (e *LogEntry) Info(ctx context.Context, message string)
- func (e *LogEntry) Infof(ctx context.Context, message string, args ...interface{})
- func (e *LogEntry) Warn(ctx context.Context, message string)
- func (e *LogEntry) Warnf(ctx context.Context, message string, args ...interface{})
- func (e *LogEntry) With(key string, value interface{}) Loggable
- type LogEntryOption
- type Loggable
- type Logger
- type Severity
- type StackdriverEncoder
- type TerminalEncoder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DefaultLogger ¶
type DefaultLogger struct {
// contains filtered or unexported fields
}
func (*DefaultLogger) EventOptions ¶
func (l *DefaultLogger) EventOptions() []EventOption
func (*DefaultLogger) LogEntryOptions ¶
func (l *DefaultLogger) LogEntryOptions() []LogEntryOption
func (*DefaultLogger) SetEncoder ¶
func (l *DefaultLogger) SetEncoder(enc Encoder)
func (*DefaultLogger) SetEventOptions ¶
func (l *DefaultLogger) SetEventOptions(opts ...EventOption)
func (*DefaultLogger) SetLogEntryOptions ¶
func (l *DefaultLogger) SetLogEntryOptions(opts ...LogEntryOption)
func (*DefaultLogger) StreamEvent ¶
func (l *DefaultLogger) StreamEvent(event *Event)
func (*DefaultLogger) StreamLogEntry ¶
func (l *DefaultLogger) StreamLogEntry(entry *LogEntry)
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event describes a single action that happens at a given time. Typically, it has a short life span where it gathers field, labels and log entries. It must be accompanied by its End method to mark the once of its lifecycle, usually from a defer function call.
func (*Event) End ¶
func (ev *Event) End()
End signals the once of the lifecycle to the event. It will apply all gathered Labels onto all child log entries, and it will finally output using the configured logger instance. Safe to be called multiple times.
func (*Event) Set ¶
Set registers a key/value pair for the current event. These pairs are not being passed down to child log entries.
func (*Event) SetLabel ¶
SetLabel registers a key/value pair as a label. This pair will then be passed down and stamped/written onto all child log entries that this event might collect throughout its lifecycle.
func (*Event) SetOnErr ¶
SetOnErr registers a key/value pair for the current event that will be logged (outputted) only in case the severity is raised over the Info threshold e.g. by registering an error log entry. fields Set with this method get logged only if an error occurs during the event's lifecycle. Otherwise, these are discarded.
type EventOption ¶
func WithExampleEventOption ¶
func WithExampleEventOption() EventOption
func WithOpenCensusTrace ¶
func WithOpenCensusTrace() EventOption
func WithOpenTelemetryTrace ¶
func WithOpenTelemetryTrace() EventOption
type Eventful ¶
type Eventful interface { Set(key string, value interface{}) Eventful SetOnErr(key string, value interface{}) Eventful SetLabel(key string, value interface{}) Eventful }
func Set ¶
Setters (Eventful interface)
Set decorates the event's fields with the given key/value pair. These fields are outputted only in the event entry itself, and it is not passed down to its child log entries (use SetLabel for that). Set Should only be used if you have started an event in your call chain and passed ctx. If no event was found, it will create (ad-hoc) an "Unnamed event" with its severity raised to Warning. All subsequent calls to the Eventful interface will be attached to this event, whether it existed or was created ad-hoc.
func SetLabel ¶
SetLabel decorates the event's labels with the given key/value pair. Labels pass down their fields (key/value pairs) to all the event's child log entries. SetLabel Should only be used if you have started an event in your call chain and passed ctx. If no event was found, it will create (ad-hoc) an "Unnamed event" with its severity raised to Warning. All subsequent calls to the Eventful interface will be attached to this event, whether it existed or was created ad-hoc.
func SetOnErr ¶
SetOnErr decorates the event's error fields with the given key/value pair. Error fields are skipped (not outputted) if "nothing happens", meaning if no log entry raises the severity level over the configured threshold. It is generally useful to log additional fields but only when an error occurs. SetOnErr Should only be used if you have started an event in your call chain and passed ctx. If no event was found, it will create (ad-hoc) an "Unnamed event" with its severity raised to Warning. All subsequent calls to the Eventful interface will be attached to this event, whether it existed or was created ad-hoc.
type JSONEncoder ¶
type JSONEncoder struct{}
func (*JSONEncoder) EncodeEvent ¶
func (j *JSONEncoder) EncodeEvent(event *Event) ([]byte, error)
func (*JSONEncoder) EncodeLogEntry ¶
func (j *JSONEncoder) EncodeLogEntry(entry *LogEntry) ([]byte, error)
type LogEntry ¶
type LogEntry struct {
// contains filtered or unexported fields
}
LogEntry defines the structure of a single, unitary log entry.
type LogEntryOption ¶
func WithExampleEntryOption ¶
func WithExampleEntryOption() LogEntryOption
func WithOpenCensusSpan ¶
func WithOpenCensusSpan() LogEntryOption
func WithOpenTelemetrySpan ¶
func WithOpenTelemetrySpan() LogEntryOption
type Loggable ¶
type Loggable interface { With(key string, value interface{}) Loggable Debug(ctx context.Context, message string) Debugf(ctx context.Context, message string, args ...interface{}) Info(ctx context.Context, message string) Infof(ctx context.Context, message string, args ...interface{}) Warn(ctx context.Context, message string) Warnf(ctx context.Context, message string, args ...interface{}) Error(ctx context.Context, message string) Errorf(ctx context.Context, message string, args ...interface{}) Fatal(ctx context.Context, message string) Fatalf(ctx context.Context, message string, args ...interface{}) }
type Logger ¶
type Logger interface { StreamLogEntry(e *LogEntry) SetLogEntryOptions(opts ...LogEntryOption) LogEntryOptions() []LogEntryOption StreamEvent(ev *Event) SetEventOptions(opts ...EventOption) EventOptions() []EventOption SetEncoder(enc Encoder) }
func NewDefaultLogger ¶
func NewDefaultLogger() Logger
type StackdriverEncoder ¶
type StackdriverEncoder struct{}
https://cloud.google.com/logging/docs/structured-logging
{ "severity":"ERROR", "message":"There was an error in the application.", "httpRequest":{ "requestMethod":"GET" }, "time":"2020-10-12T07:20:50.52Z", "logging.googleapis.com/labels":{ "user_label_1":"value_1", "user_label_2":"value_2" }, "logging.googleapis.com/sourceLocation":{ "file":"get_data.py", "line":"142", "function":"getData" }, "logging.googleapis.com/spanId":"000000000000004a", "logging.googleapis.com/trace":"projects/my-projectid/traces/06796866738c859f2f19b7cfb3214824", "logging.googleapis.com/trace_sampled":false }
func (*StackdriverEncoder) EncodeEvent ¶
func (j *StackdriverEncoder) EncodeEvent(event *Event) ([]byte, error)
func (*StackdriverEncoder) EncodeLogEntry ¶
func (j *StackdriverEncoder) EncodeLogEntry(entry *LogEntry) ([]byte, error)
type TerminalEncoder ¶
type TerminalEncoder struct{}
func (*TerminalEncoder) EncodeEvent ¶
func (t *TerminalEncoder) EncodeEvent(event *Event) ([]byte, error)
func (*TerminalEncoder) EncodeLogEntry ¶
func (t *TerminalEncoder) EncodeLogEntry(entry *LogEntry) ([]byte, error)