Documentation ¶
Overview ¶
Package slog implements a logger formatted to work with Stackdriver structured logs.
Index ¶
- func Alert(v ...interface{})
- func Alertf(format string, v ...interface{})
- func Critical(v ...interface{})
- func Criticalf(format string, v ...interface{})
- func Debug(v ...interface{})
- func Debugf(format string, v ...interface{})
- func Emergency(v ...interface{})
- func Emergencyf(format string, v ...interface{})
- func Error(v ...interface{})
- func Errorf(format string, v ...interface{})
- func Info(v ...interface{})
- func Infof(format string, v ...interface{})
- func NewContext(ctx context.Context, entry *Entry) context.Context
- func Notice(v ...interface{})
- func Noticef(format string, v ...interface{})
- func SetIncludeSources(include bool)
- func SetOutput(w io.Writer)
- func SetProject(project string)
- func Warn(v ...interface{})
- func Warnf(format string, v ...interface{})
- type Entry
- func FromContext(ctx context.Context) *Entry
- func StartOperation(id, producer string) *Entry
- func WithDetail(k string, v interface{}) *Entry
- func WithDetails(details Fields) *Entry
- func WithError(err error) *Entry
- func WithLabels(labels Fields) *Entry
- func WithOperation(id, producer string) *Entry
- func WithSpan(sc trace.SpanContext) *Entry
- func WithStack() *Entry
- func (e *Entry) Alert(v ...interface{})
- func (e *Entry) Alertf(format string, v ...interface{})
- func (e *Entry) Critical(v ...interface{})
- func (e *Entry) Criticalf(format string, v ...interface{})
- func (e *Entry) Debug(v ...interface{})
- func (e *Entry) Debugf(format string, v ...interface{})
- func (e *Entry) Emergency(v ...interface{})
- func (e *Entry) Emergencyf(format string, v ...interface{})
- func (e *Entry) EndOperation()
- func (e *Entry) Error(v ...interface{})
- func (e *Entry) Errorf(format string, v ...interface{})
- func (e *Entry) Info(v ...interface{})
- func (e *Entry) Infof(format string, v ...interface{})
- func (e *Entry) Notice(v ...interface{})
- func (e *Entry) Noticef(format string, v ...interface{})
- func (e *Entry) StartOperation(id, producer string) *Entry
- func (e *Entry) Warn(v ...interface{})
- func (e *Entry) Warnf(format string, v ...interface{})
- func (e *Entry) WithDetail(k string, v interface{}) *Entry
- func (e *Entry) WithDetails(details Fields) *Entry
- func (e *Entry) WithError(err error) *Entry
- func (e *Entry) WithLabels(labels Fields) *Entry
- func (e *Entry) WithOperation(id, producer string) *Entry
- func (e *Entry) WithSpan(sc trace.SpanContext) *Entry
- func (e *Entry) WithStack() *Entry
- type Fields
- type Logger
- func (l *Logger) Alert(v ...interface{})
- func (l *Logger) Alertf(format string, v ...interface{})
- func (l *Logger) Critical(v ...interface{})
- func (l *Logger) Criticalf(format string, v ...interface{})
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Emergency(v ...interface{})
- func (l *Logger) Emergencyf(format string, v ...interface{})
- func (l *Logger) Error(v ...interface{})
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Notice(v ...interface{})
- func (l *Logger) Noticef(format string, v ...interface{})
- func (l *Logger) SetIncludeSources(include bool)
- func (l *Logger) SetOutput(w io.Writer)
- func (l *Logger) SetProject(project string)
- func (l *Logger) StartOperation(id, producer string) *Entry
- func (l *Logger) Warn(v ...interface{})
- func (l *Logger) Warnf(format string, v ...interface{})
- func (l *Logger) WithDetail(k string, v interface{}) *Entry
- func (l *Logger) WithDetails(details Fields) *Entry
- func (l *Logger) WithError(err error) *Entry
- func (l *Logger) WithLabels(labels Fields) *Entry
- func (l *Logger) WithOperation(id, producer string) *Entry
- func (l *Logger) WithSpan(sc trace.SpanContext) *Entry
- func (l *Logger) WithStack() *Entry
- type Operation
- type SourceLocation
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Alert ¶
func Alert(v ...interface{})
Alert sends a message to the default logger with severity Alert. Arguments are handled in the manner of fmt.Print.
func Alertf ¶
func Alertf(format string, v ...interface{})
Alertf sends a message to the default logger with severity Alert. Arguments are handled in the manner of fmt.Printf.
func Critical ¶
func Critical(v ...interface{})
Critical sends a message to the default logger with severity Critical. Arguments are handled in the manner of fmt.Print.
func Criticalf ¶
func Criticalf(format string, v ...interface{})
Criticalf sends a message to the default logger with severity Critical. Arguments are handled in the manner of fmt.Printf.
func Debug ¶
func Debug(v ...interface{})
Debug sends a message to the default logger with severity Debug. Arguments are handled in the manner of fmt.Print.
func Debugf ¶
func Debugf(format string, v ...interface{})
Debugf sends a message to the default logger with severity Debug. Arguments are handled in the manner of fmt.Printf.
func Emergency ¶
func Emergency(v ...interface{})
Emergency sends a message to the default logger with severity Emergency. Arguments are handled in the manner of fmt.Print.
func Emergencyf ¶
func Emergencyf(format string, v ...interface{})
Emergencyf sends a message to the default logger with severity Emergency. Arguments are handled in the manner of fmt.Printf.
func Error ¶
func Error(v ...interface{})
Error sends a message to the default logger with severity Error. Arguments are handled in the manner of fmt.Print.
func Errorf ¶
func Errorf(format string, v ...interface{})
Errorf sends a message to the default logger with severity Error. Arguments are handled in the manner of fmt.Printf.
func Info ¶
func Info(v ...interface{})
Info sends a message to the default logger with severity Info. Arguments are handled in the manner of fmt.Print.
func Infof ¶
func Infof(format string, v ...interface{})
Infof sends a message to the default logger with severity Info. Arguments are handled in the manner of fmt.Printf.
func NewContext ¶ added in v0.5.0
NewContext returns a new Context that carries an entry.
func Notice ¶
func Notice(v ...interface{})
Notice sends a message to the default logger with severity Notice. Arguments are handled in the manner of fmt.Print.
func Noticef ¶
func Noticef(format string, v ...interface{})
Noticef sends a message to the default logger with severity Notice. Arguments are handled in the manner of fmt.Printf.
func SetIncludeSources ¶ added in v0.2.0
func SetIncludeSources(include bool)
SetIncludeSources for the package-level logger. Will include file, line and func.
func SetProject ¶
func SetProject(project string)
SetProject for the package-level logger. Used for things such as traces that require project to be included.
Types ¶
type Entry ¶
type Entry struct { Message string `json:"message"` Severity severity `json:"severity,omitempty"` Labels map[string]string `json:"logging.googleapis.com/labels,omitempty"` SourceLocation *SourceLocation `json:"logging.googleapis.com/sourceLocation,omitempty"` Operation *Operation `json:"logging.googleapis.com/operation,omitempty"` Trace string `json:"logging.googleapis.com/trace,omitempty"` SpanID string `json:"logging.googleapis.com/spanId,omitempty"` TraceSampled bool `json:"logging.googleapis.com/trace_sampled,omitempty"` Details Fields `json:"details,omitempty"` Err string `json:"error,omitempty"` StackTrace string `json:"exception,omitempty"` // contains filtered or unexported fields }
Entry with additional metadata included. See https://cloud.google.com/logging/docs/agent/configuration#special-fields for reference.
func FromContext ¶ added in v0.5.0
FromContext returns the Entry value stored in ctx, or a new Entry if none exists.
Example ¶
entry := &Entry{} ctx := NewContext(context.Background(), entry) entry = FromContext(ctx) entry.Info("entry pulled from context")
Output:
func StartOperation ¶
StartOperation with a given ID and producer. Will log the start of the operation at Notice level.
Example ¶
id := "operationId" producer := "producerName" entry := StartOperation(id, producer) entry.Info("entry logged under new operation") entry.WithOperation(id, producer) entry.Info("entry logged under existing operation") entry.EndOperation()
Output:
func WithDetail ¶ added in v0.6.0
WithDetail for a given Entry. Will create a child entry.
func WithDetails ¶ added in v0.3.0
WithDetails for a given Entry. Will create a child entry.
Example ¶
entry := WithDetail("key", "value") entry.Info("entry with single detail") details := Fields{ "detailOne": "one", "detailTwo": 2, } entry = entry.WithDetails(details) entry.Info("entry with details")
Output:
func WithError ¶ added in v0.6.0
WithError for a given Entry. Will create a child entry.
Example ¶
err := errors.New("error!") entry := WithError(err) entry.Error("entry with error")
Output:
func WithLabels ¶ added in v0.2.0
WithLabels for a given Entry. Will create a child entry.
Example ¶
labels := Fields{ "labelOne": "hello", "labelTwo": "world", } entry := WithLabels(labels) entry.Info("entry with labels")
Output:
func WithOperation ¶
WithOperation details included in all logs written for a given Entry.
func WithSpan ¶
func WithSpan(sc trace.SpanContext) *Entry
WithSpan details included for a given Trace. Will create a child entry.
Example ¶
_, span := trace.StartSpan(context.Background(), "spanName") entry := WithSpan(span.SpanContext()) entry.Info("entry with span")
Output:
func WithStack ¶ added in v0.12.1
func WithStack() *Entry
WithStack included. Will create a child entry.
func (*Entry) Alert ¶
func (e *Entry) Alert(v ...interface{})
Alert sends a message to the logger associated with this entry with severity Alert. Arguments are handled in the manner of fmt.Print.
func (*Entry) Alertf ¶
Alertf sends a message to the logger associated with this entry with severity Alert. Arguments are handled in the manner of fmt.Printf.
func (*Entry) Critical ¶
func (e *Entry) Critical(v ...interface{})
Critical sends a message to the logger associated with this entry with severity Critical. Arguments are handled in the manner of fmt.Print.
func (*Entry) Criticalf ¶
Criticalf sends a message to the logger associated with this entry with severity Critical. Arguments are handled in the manner of fmt.Printf.
func (*Entry) Debug ¶
func (e *Entry) Debug(v ...interface{})
Debug sends a message to the logger associated with this entry with severity Debug. Arguments are handled in the manner of fmt.Print.
func (*Entry) Debugf ¶
Debugf sends a message to the logger associated with this entry with severity Debug. Arguments are handled in the manner of fmt.Printf.
func (*Entry) Emergency ¶
func (e *Entry) Emergency(v ...interface{})
Emergency sends a message to the logger associated with this entry with severity Emergency. Arguments are handled in the manner of fmt.Print.
func (*Entry) Emergencyf ¶
Emergencyf sends a message to the logger associated with this entry with severity Emergency. Arguments are handled in the manner of fmt.Printf.
func (*Entry) EndOperation ¶
func (e *Entry) EndOperation()
EndOperation stops any current operation and further logs will no longer include. Will log the end of the operation at Notice level.
func (*Entry) Error ¶
func (e *Entry) Error(v ...interface{})
Error sends a message to the logger associated with this entry with severity Error. Arguments are handled in the manner of fmt.Print.
func (*Entry) Errorf ¶
Errorf sends a message to the logger associated with this entry with severity Error. Arguments are handled in the manner of fmt.Printf.
func (*Entry) Info ¶
func (e *Entry) Info(v ...interface{})
Info sends a message to the logger associated with this entry with severity Info. Arguments are handled in the manner of fmt.Print.
func (*Entry) Infof ¶
Infof sends a message to the logger associated with this entry with severity Info. Arguments are handled in the manner of fmt.Printf.
func (*Entry) Notice ¶
func (e *Entry) Notice(v ...interface{})
Notice sends a message to the logger associated with this entry with severity Notice. Arguments are handled in the manner of fmt.Print.
func (*Entry) Noticef ¶
Noticef sends a message to the logger associated with this entry with severity Notice. Arguments are handled in the manner of fmt.Printf.
func (*Entry) StartOperation ¶
StartOperation with a given ID and producer. Will log the start of the operation at Notice level.
func (*Entry) Warn ¶
func (e *Entry) Warn(v ...interface{})
Warn sends a message to the logger associated with this entry with severity Warn. Arguments are handled in the manner of fmt.Print.
func (*Entry) Warnf ¶
Warnf sends a message to the logger associated with this entry with severity Warn. Arguments are handled in the manner of fmt.Printf.
func (*Entry) WithDetail ¶ added in v0.6.0
WithDetail for a given Entry. Will create a child entry.
func (*Entry) WithDetails ¶ added in v0.3.0
WithDetails for a given Entry. Will create a child entry.
func (*Entry) WithLabels ¶ added in v0.2.0
WithLabels for a given Entry. Will create a child entry.
func (*Entry) WithOperation ¶
WithOperation details included in all logs written for a given Entry.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger used to write structured logs in a thread-safe manner to a given output.
func (*Logger) Alert ¶
func (l *Logger) Alert(v ...interface{})
Alert sends a message to the logger with severity Alert. Arguments are handled in the manner of fmt.Print.
func (*Logger) Alertf ¶
Alertf sends a message to the logger with severity Alert. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Critical ¶
func (l *Logger) Critical(v ...interface{})
Critical sends a message to the logger with severity Critical. Arguments are handled in the manner of fmt.Print.
func (*Logger) Criticalf ¶
Criticalf sends a message to the logger with severity Critical. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Debug ¶
func (l *Logger) Debug(v ...interface{})
Debug sends a message to the logger with severity Debug. Arguments are handled in the manner of fmt.Print.
func (*Logger) Debugf ¶
Debugf sends a message to the logger with severity Debug. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Emergency ¶
func (l *Logger) Emergency(v ...interface{})
Emergency sends a message to the logger with severity Emergency. Arguments are handled in the manner of fmt.Print.
func (*Logger) Emergencyf ¶
Emergencyf sends a message to the logger with severity Emergency. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Error ¶
func (l *Logger) Error(v ...interface{})
Error sends a message to the logger with severity Error. Arguments are handled in the manner of fmt.Print.
func (*Logger) Errorf ¶
Errorf sends a message to the logger with severity Error. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Info ¶
func (l *Logger) Info(v ...interface{})
Info sends a message to the logger with severity Info. Arguments are handled in the manner of fmt.Print.
func (*Logger) Infof ¶
Infof sends a message to the logger with severity Info. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Notice ¶
func (l *Logger) Notice(v ...interface{})
Notice sends a message to the logger with severity Notice. Arguments are handled in the manner of fmt.Print.
func (*Logger) Noticef ¶
Noticef sends a message to the logger with severity Notice. Arguments are handled in the manner of fmt.Printf.
func (*Logger) SetIncludeSources ¶ added in v0.2.0
SetIncludeSources for the logger. Will include file, line and func.
func (*Logger) SetProject ¶
SetProject for the logger. Used for things such as traces that require project to be included.
func (*Logger) StartOperation ¶
StartOperation with a given ID and producer. Will log the start of the operation at Notice level.
func (*Logger) Warn ¶
func (l *Logger) Warn(v ...interface{})
Warn sends a message to the logger with severity Warn. Arguments are handled in the manner of fmt.Print.
func (*Logger) Warnf ¶
Warnf sends a message to the logger with severity Warn. Arguments are handled in the manner of fmt.Printf.
func (*Logger) WithDetail ¶ added in v0.6.0
WithDetail for a given Entry. Will create a child entry.
func (*Logger) WithDetails ¶ added in v0.3.0
WithDetails for a given Entry. Will create a child entry.
func (*Logger) WithLabels ¶ added in v0.2.0
WithLabels for a given Entry. Will create a child entry.
func (*Logger) WithOperation ¶
WithOperation details included in all logs written for a given Entry.
type Operation ¶
type Operation struct { ID string `json:"id,omitempty"` Producer string `json:"producer,omitempty"` First bool `json:"first,omitempty"` Last bool `json:"last,omitempty"` }
The Operation a given log entry is part of.
type SourceLocation ¶
type SourceLocation struct { File string `json:"file,omitempty"` Line string `json:"line,omitempty"` Function string `json:"function,omitempty"` }
SourceLocation that originated the log call.