log

package
v2.26.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

* @license * Copyright 2025 Dynatrace LLC * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

Index

Constants

View Source
const (
	LogDirectory                 = ".logs"
	LogFileTimestampPrefixFormat = "20060102-150405"
)

Variables

This section is empty.

Functions

func CoordinateAttr added in v2.24.0

func CoordinateAttr(coordinate coordinate.Coordinate) slog.Attr

CoordinateAttr returns an attribute containing information taken from the provided coordinate.

func Debug

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

func DebugContext added in v2.24.0

func DebugContext(ctx context.Context, msg string, a ...interface{})

func EnvironmentAttr added in v2.24.0

func EnvironmentAttr(environment, group string) slog.Attr

EnvironmentAttr returns an attribute containing environment information for structured logging.

func Error

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

func ErrorAttr added in v2.24.0

func ErrorAttr(err error) slog.Attr

ErrorAttr returns an attribute containing error information for structured logging.

func ErrorContext added in v2.24.0

func ErrorContext(ctx context.Context, msg string, a ...interface{})

func ErrorFilePath added in v2.8.1

func ErrorFilePath() string

ErrorFilePath returns the path of an error logfile for the current execution time - depending on when this function is called such a file may not yet exist

func Fatal

func Fatal(msg string, a ...interface{})

func FatalContext added in v2.24.0

func FatalContext(ctx context.Context, msg string, a ...interface{})

func Info

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

func InfoContext added in v2.24.0

func InfoContext(ctx context.Context, msg string, a ...interface{})

func LogFilePath added in v2.8.1

func LogFilePath() string

LogFilePath returns the path of a logfile for the current execution time - depending on when this function is called such a file may not yet exist

func MemStatFilePath added in v2.16.0

func MemStatFilePath() string

MemStatFilePath returns the full path of an memory statistics log file for the current execution time - if no stats are written (yet) no file may exist at this path.

func PrepareLogFiles added in v2.24.0

func PrepareLogFiles(ctx context.Context, fs afero.Fs, enableMemstatLogging bool) (logFile afero.File, errFile afero.File, err error)

prepareLogFiles tries to create a LogDirectory (if none exists) and a file each to write all logs and filtered error logs to. As errors in preparing log files are viewed as optional for the logger setup using this method, partial data may be returned in case of errors. If log directory or logFile creation fails, no log files are returned. If errLog creation fails, a valid logFile is still being returned with an error.

func PrepareLogging

func PrepareLogging(ctx context.Context, fs afero.Fs, verbose bool, loggerSpy io.Writer, fileLogging bool, enableMemstatLogging bool)

PrepareLogging sets up the default slog.Logger using the specified options.

func TypeAttr added in v2.24.0

func TypeAttr[X ~string](t X) slog.Attr

TypeAttr returns an attribute containing information about a config type. This is used in cases where no full coordinate exists, but only a config type is known - for example in download or deletion.

func Warn

func Warn(msg string, a ...interface{})

func WarnContext added in v2.24.0

func WarnContext(ctx context.Context, msg string, a ...interface{})

Types

type ContextHandler added in v2.24.0

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

ContextHandler is an implementation of slog.Handler that extracts attributes from the context provided in a log calls, adds them to the record and delegates to the specified handler.

func NewContextHandler added in v2.24.0

func NewContextHandler(h slog.Handler) *ContextHandler

NewContextHandler creates a new ContextHandler wrapping the specified handler.

func (*ContextHandler) Enabled added in v2.24.0

func (h *ContextHandler) Enabled(ctx context.Context, l slog.Level) bool

Enabled returns true iff the wrapped handler in enabled for the specified level.

func (*ContextHandler) Handle added in v2.24.0

func (h *ContextHandler) Handle(ctx context.Context, r slog.Record) error

Handle adds attributes extracted from the context before calling Handle on the wrapped Handler.

func (*ContextHandler) WithAttrs added in v2.24.0

func (h *ContextHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new ContextHandler created by calling WithAttr on the wrapped handler.

func (*ContextHandler) WithGroup added in v2.24.0

func (h *ContextHandler) WithGroup(name string) slog.Handler

WithGroup returns a new ContextHandler created by calling WithGroup on the wrapped handler.

type CtxGraphComponentId added in v2.6.0

type CtxGraphComponentId struct{}

CtxGraphComponentId context key used for correlating logs that belong to deployment of a sub graph

type CtxKeyAccount added in v2.10.0

type CtxKeyAccount struct{}

CtxKeyAccount context key used for contextual account information

type CtxKeyCoord

type CtxKeyCoord struct{}

CtxKeyCoord context key used for contextual coordinate information

type CtxKeyEnv

type CtxKeyEnv struct{}

CtxKeyEnv context key used for contextual environment information

type CtxValEnv

type CtxValEnv struct {
	Name  string
	Group string
}

CtxValEnv context value used for contextual environment information

type CtxValGraphComponentId added in v2.6.0

type CtxValGraphComponentId int

CtxValGraphComponentId context value used for correlating logs that belong to deployment of a sub graph

type Slogger added in v2.24.0

type Slogger struct {
	Logger *slog.Logger
}

Slogger is a simple logger that wraps an `slog.Logger`.

func With added in v2.24.0

func With(attributes ...any) *Slogger

With adds additional [attribute.Attr] for structured logs It accepts vararg attributes and should not be called more than once per log call

func (*Slogger) Debug added in v2.24.0

func (w *Slogger) Debug(msg string, a ...interface{})

func (*Slogger) DebugContext added in v2.24.0

func (w *Slogger) DebugContext(ctx context.Context, msg string, a ...interface{})

func (*Slogger) Error added in v2.24.0

func (w *Slogger) Error(msg string, a ...interface{})

func (*Slogger) ErrorContext added in v2.24.0

func (w *Slogger) ErrorContext(ctx context.Context, msg string, a ...interface{})

func (*Slogger) Fatal added in v2.24.0

func (w *Slogger) Fatal(msg string, a ...any)

func (*Slogger) FatalContext added in v2.24.0

func (w *Slogger) FatalContext(ctx context.Context, msg string, a ...any)

func (*Slogger) Info added in v2.24.0

func (w *Slogger) Info(msg string, a ...interface{})

func (*Slogger) InfoContext added in v2.24.0

func (w *Slogger) InfoContext(ctx context.Context, msg string, a ...interface{})

func (*Slogger) SLogger added in v2.24.0

func (w *Slogger) SLogger() *slog.Logger

func (*Slogger) Warn added in v2.24.0

func (w *Slogger) Warn(msg string, a ...interface{})

func (*Slogger) WarnContext added in v2.24.0

func (w *Slogger) WarnContext(ctx context.Context, msg string, a ...interface{})

func (*Slogger) With added in v2.24.0

func (w *Slogger) With(attributes ...any) *Slogger

With adds additional [attribute.Attr] for structured logs It accepts vararg attributes and should not be called more than once per log call

type TeeHandler added in v2.24.0

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

TeeHandler implements the Handler interface by delegating to one or more handlers.

func NewTeeHandler added in v2.24.0

func NewTeeHandler(h ...slog.Handler) *TeeHandler

NewTeeHandler creates a new TeeHandler that delegates handling to the specified handlers.

func (*TeeHandler) Enabled added in v2.24.0

func (t *TeeHandler) Enabled(ctx context.Context, l slog.Level) bool

Enabled returns true if one or more handlers is enabled for the given log level.

func (*TeeHandler) Handle added in v2.24.0

func (t *TeeHandler) Handle(ctx context.Context, r slog.Record) error

Handle handles the given record.

func (*TeeHandler) WithAttrs added in v2.24.0

func (t *TeeHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new TeeHandler where each delegate handler has the specified attributes.

func (*TeeHandler) WithGroup added in v2.24.0

func (t *TeeHandler) WithGroup(name string) slog.Handler

WithGroup returns a new TeeHandler where each delegate handler has the specified group.

Jump to

Keyboard shortcuts

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