slog

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2022 License: MIT Imports: 11 Imported by: 1

README

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string) (err error)

Debug logs a message at SeverityDebug.

func DebugWithCtx

func DebugWithCtx(ctx context.Context, msg string) (err error)

DebugWithCtx logs a message at SeverityDebug.

func DebugWithCtxf added in v0.3.0

func DebugWithCtxf(ctx context.Context, format string, a ...interface{}) (err error)

DebugWithCtxf logs a message at SeverityDebug.

func DebugWithSpan

func DebugWithSpan(span trace.Span, msg string) (err error)

DebugWithSpan logs a message at SeverityDebug.

func DebugWithSpanf added in v0.3.0

func DebugWithSpanf(span trace.Span, format string, a ...interface{}) (err error)

DebugWithSpanf logs a message at SeverityDebug.

func Debugf added in v0.3.0

func Debugf(format string, a ...interface{}) (err error)

Debugf logs a message at SeverityDebug.

func Enabled

func Enabled(s Severity) bool

Enabled decides whether a given logging level is enabled when logging a message.

func Error

func Error(msg string) (err error)

Error logs a message at SeverityError.

func ErrorWithCtx

func ErrorWithCtx(ctx context.Context, msg string) (err error)

ErrorWithCtx logs a message at SeverityError.

func ErrorWithCtxf added in v0.3.0

func ErrorWithCtxf(ctx context.Context, format string, a ...interface{}) (err error)

ErrorWithCtxf logs a message at SeverityError.

func ErrorWithSpan

func ErrorWithSpan(span trace.Span, msg string) (err error)

ErrorWithSpan logs a message at SeverityError.

func ErrorWithSpanf added in v0.3.0

func ErrorWithSpanf(span trace.Span, format string, a ...interface{}) (err error)

ErrorWithSpanf logs a message at SeverityError.

func Errorf added in v0.3.0

func Errorf(format string, a ...interface{}) (err error)

Errorf logs a message at SeverityError.

func Info

func Info(msg string) (err error)

Info logs a message at SeverityInfo.

func InfoWithCtx

func InfoWithCtx(ctx context.Context, msg string) (err error)

InfoWithCtx logs a message at SeverityInfo.

func InfoWithCtxf added in v0.3.0

func InfoWithCtxf(ctx context.Context, format string, a ...interface{}) (err error)

InfoWithCtxf logs a message at SeverityInfo.

func InfoWithSpan

func InfoWithSpan(span trace.Span, msg string) (err error)

InfoWithSpan logs a message at SeverityInfo.

func InfoWithSpanf added in v0.3.0

func InfoWithSpanf(span trace.Span, format string, a ...interface{}) (err error)

InfoWithSpanf logs a message at SeverityInfo.

func Infof added in v0.3.0

func Infof(format string, a ...interface{}) (err error)

Infof logs a message at SeverityInfo.

func ReportError added in v0.2.0

func ReportError(msg string) (err error)

ReportError outputs a log with stacktrace so that error reporting can recognize the error.

func ReportErrorWithCtx added in v0.2.0

func ReportErrorWithCtx(ctx context.Context, msg string) (err error)

ReportErrorWithCtx outputs a log with stacktrace so that error reporting can recognize the error.

func ReportErrorWithCtxf added in v0.3.0

func ReportErrorWithCtxf(ctx context.Context, format string, a ...interface{}) (err error)

ReportErrorWithCtx outputs a log with stacktrace so that error reporting can recognize the error.

func ReportErrorWithSpan added in v0.2.0

func ReportErrorWithSpan(span trace.Span, msg string) (err error)

ReportErrorWithSpan outputs a log with stacktrace so that error reporting can recognize the error.

func ReportErrorWithSpanf added in v0.3.0

func ReportErrorWithSpanf(span trace.Span, format string, a ...interface{}) (err error)

ReportErrorWithSpanf outputs a log with stacktrace so that error reporting can recognize the error.

func ReportErrorf added in v0.3.0

func ReportErrorf(format string, a ...interface{}) (err error)

ReportErrorf outputs a log with stacktrace so that error reporting can recognize the error.

func Setup

func Setup(traceProjectID string, opts ...Option) error

Setup is setup function for slog package.

func Warn

func Warn(msg string) (err error)

Warn logs a message at SeverityWarning.

func WarnWithCtx

func WarnWithCtx(ctx context.Context, msg string) (err error)

WarnWithCtx logs a message at SeverityWarning.

func WarnWithCtxf added in v0.3.0

func WarnWithCtxf(ctx context.Context, format string, a ...interface{}) (err error)

WarnWithCtxf logs a message at SeverityWarning.

func WarnWithSpan

func WarnWithSpan(span trace.Span, msg string) (err error)

WarnWithSpan logs a message at SeverityWarning.

func WarnWithSpanf added in v0.3.0

func WarnWithSpanf(span trace.Span, format string, a ...interface{}) (err error)

WarnWithSpanf logs a message at SeverityWarning.

func Warnf added in v0.3.0

func Warnf(format string, a ...interface{}) (err error)

Warnf logs a message at SeverityWarning.

Types

type Entry

type Entry struct {
	// A severity as string.
	Severity string `json:"severity"`
	// Optional. Resource name of the trace associated with the log entry, if any.
	// If it contains a relative resource name, the name is assumed to be relative to //tracing.googleapis.com.
	// Example: projects/my-projectid/traces/06796866738c859f2f19b7cfb3214824
	Trace string `json:"logging.googleapis.com/trace,omitempty"`
	// Optional. The span ID within the trace associated with the log entry.
	// For Trace spans, this is the same format that the Trace API v2 uses: a 16-character hexadecimal encoding
	// of an 8-byte array, such as 000000000000004a.
	SpanID string `json:"logging.googleapis.com/spanId,omitempty"`
	// Optional. Source code location information associated with the log entry, if any.
	SourceLocation *SourceLocation `json:"logging.googleapis.com/sourceLocation,omitempty"`
	// The log entry payload, represented as a Unicode string (UTF-8).
	Message string `json:"message"`
}

Entry is a log entry. See https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry.

type Option

type Option func()

An Option is an option for a slog package.

func WithLogLevel

func WithLogLevel(lvl string) Option

WithLogLevel returns an Option that specifies a log level.

func WithSeverity added in v0.2.0

func WithSeverity(s Severity) Option

WithSeverity returns an Option that specifies a severity. Default severity is SeverityDebug.

type Severity

type Severity uint32

Severity is implementation of https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverity.

const (
	// SeverityDefault represents log entry has no assigned severity level.
	SeverityDefault Severity = 0
	// SeverityDebug represents debug or trace information.
	SeverityDebug Severity = 1
	// SeverityInfo represents routine information, such as ongoing status or performance.
	SeverityInfo Severity = 2
	// SeverityNotice represents normal but significant events, such as start up, shut down, or a configuration change.
	SeverityNotice Severity = 3
	// SeverityWarning represents warning events might cause problems.
	SeverityWarning Severity = 4
	// SeverityError represents error events are likely to cause problems.
	SeverityError Severity = 5
	// SeverityCritical represents critical events cause more severe problems or outages.
	SeverityCritical Severity = 6
	// SeverityAlert represents a person must take an action immediately.
	SeverityAlert Severity = 7
	// SeverityEmergency represents one or more systems are unusable.
	SeverityEmergency Severity = 8
)

func (Severity) String

func (s Severity) String() string

type SourceLocation

type SourceLocation struct {
	// Optional. Source file name. Depending on the runtime environment,
	// this might be a simple name or a fully-qualified name.
	File string `json:"file,omitempty"`
	// Optional. Line within the source file. 1-based; 0 indicates no line number available.
	Line int64 `json:"line,omitempty"`
	// Optional. Human-readable name of the function or method being invoked,
	// with optional context such as the class or package name.
	// This information may be used in contexts such as the logs viewer,
	// where a file and line number are less meaningful. The format can vary by language.
	// For example: qual.if.ied.Class.method (Java), dir/package.func (Go), function (Python).
	Function string `json:"function,omitempty"`
}

SourceLocation is additional information about the source code location that produced the log entry.

Directories

Path Synopsis
example module

Jump to

Keyboard shortcuts

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