Documentation ¶
Index ¶
- Constants
- Variables
- func Emitter(opt ...Option) alog.Emitter
- func LogCritical(ctx context.Context, logger *alog.Logger, f string, v ...interface{})
- func LogDebug(ctx context.Context, logger *alog.Logger, f string, v ...interface{})
- func LogError(ctx context.Context, logger *alog.Logger, f string, v ...interface{})
- func LogInfo(ctx context.Context, logger *alog.Logger, f string, v ...interface{})
- func LogSeverity(ctx context.Context, logger *alog.Logger, severity string, f string, ...)
- func LogWarning(ctx context.Context, logger *alog.Logger, f string, v ...interface{})
- func NewSeverityLogger(logger *alog.Logger) leveled.Logger
- func SpanDecimalToHex(spanID uint64) string
- func TraceFromRequest(req *http.Request) (trace string, span string)
- func WithMinSeverity(parent context.Context, severity string) context.Context
- func WithRequest(parent context.Context, req *http.Request) context.Context
- func WithRequestLatency(parent context.Context, latency time.Duration) context.Context
- func WithRequestStatus(parent context.Context, status int) context.Context
- func WithRequestTrace(parent context.Context, req *http.Request) context.Context
- func WithSeverity(parent context.Context, severity string) context.Context
- func WithSpan(parent context.Context, span string) context.Context
- func WithTrace(parent context.Context, trace string) context.Context
- type Option
- type Options
- type SpanContext
- type TraceSpanExtractor
Constants ¶
const ( SeverityDefault = "DEFAULT" // The log entry has no assigned severity level. SeverityDebug = "DEBUG" // Debug or trace information. SeverityInfo = "INFO" // Routine information, such as ongoing status or performance. SeverityNotice = "NOTICE" // Normal but significant events, such as start up, shut down, or a configuration change. SeverityWarning = "WARNING" // Warning events might cause problems. SeverityError = "ERROR" // Error events are likely to cause problems. SeverityCritical = "CRITICAL" // Critical events cause more severe problems or outages. SeverityAlert = "ALERT" // A person must take an action immediately. SeverityEmergency = "EMERGENCY" // One or more systems are unusable. )
Severity levels
Variables ¶
var DefaultLogger = alog.New(alog.WithEmitter(Emitter()))
DefaultLogger is a *alog.Logger that logs to stderr
Functions ¶
func Emitter ¶
func Emitter(opt ...Option) alog.Emitter
Emitter emits log messages as single lines of JSON.
Logs are output to w. Every entry generates a single Write call to w, and calls are serialized.
func LogCritical ¶ added in v3.3.0
LogCritical writes a log entry using SeverityCritical
func LogSeverity ¶ added in v3.3.0
func LogSeverity(ctx context.Context, logger *alog.Logger, severity string, f string, v ...interface{})
LogSeverity writes a log entry using the specified severity
func LogWarning ¶ added in v3.3.0
LogWarning writes a log entry using SeverityWarning
func NewSeverityLogger ¶ added in v3.4.0
func SpanDecimalToHex ¶
SpanDecimalToHex converts a decimal Span ID value to hexidecimal.
func TraceFromRequest ¶
TraceFromRequest returns a trace and/or span from a http.Request.
func WithMinSeverity ¶ added in v3.8.0
WithMinSeverity sets the minimum severity to log. Use one of the Severity* constants.
func WithRequest ¶
WithRequest returns a copy of parent with the specified http.Request value. It also calls WithRequestTrace to add trace information to the context.
func WithRequestLatency ¶
WithRequestLatency returns a copy of the parent with the specified HTTP request latency value.
func WithRequestStatus ¶
WithRequestStatus returns a copy of the parent with the specified HTTP return status code.
func WithRequestTrace ¶
WithRequestTrace returns a copy of parent with the trace information from the specified http.Request.
func WithSeverity ¶
WithSeverity returns a copy of parent with the specified severity value.
func WithSpan ¶
WithSpan returns a copy of parent with the specified Span ID value.
This should be a 8-byte hex string (16 digits). Note that some Google services like load balancers use a 64-bit decimal number instead of hexidecimal. Those values can be converted to the correct format with SpanDecimalToHex.
Types ¶
type Option ¶
type Option func(*Options)
Option sets an option for the emitter.
Options are applied in the order specified.
func WithShortFile ¶
func WithShortFile() Option
WithShortFile indicates to only use the filename instead of the full file path for sourceLocation.
func WithTraceSpanExtractor ¶ added in v3.6.0
func WithTraceSpanExtractor(extractor TraceSpanExtractor) Option
WithTraceSpanExtractor registers a trace-span extractor so trace-span IDs from the context (as found by the extractor) are placed in the appropriate fields to be correlated by stackdriver tracing.
func WithWriter ¶
WithWriter sets the writer to use for log output.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options holds option values.
type SpanContext ¶ added in v3.6.0
SpanContext contains the necessary trace-context data to populate the logging.googleapis.com/spanId, logging.googleapis.com/trace and logging.googleapis.com/trace_sampled fields. See https://cloud.google.com/logging/docs/agent/configuration#special-fields for details on these fields.
type TraceSpanExtractor ¶ added in v3.6.0
type TraceSpanExtractor func(context.Context) SpanContext
TraceSpanExtractor implementations extract a trace spanID from the passed context. The return values should be: spanID, traceID, isSampled