Help us shape the future of Go! Take the 2026 Go Developer Survey

logger

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 14 Imported by: 791

Documentation

Index

Constants

View Source
const (
	// LogTypeLog is normal log type.
	LogTypeLog = "log"
	// LogTypeRequest is Request log type.
	LogTypeRequest = "request"
)

Variables

View Source
var DaprVersion = "unknown"

Functions

func ApplyOptionsToLoggers

func ApplyOptionsToLoggers(options *Options) error

ApplyOptionsToLoggers applys options to all registered loggers.

func NewContext added in v0.0.4

func NewContext(ctx context.Context, logger Logger) context.Context

NewContext returns a new Context, derived from ctx, which carries the provided Logger.

Types

type LogLevel

type LogLevel string

LogLevel is Dapr Logger Level type.

const (
	// DebugLevel has verbose message.
	DebugLevel LogLevel = "debug"
	// InfoLevel is default log level.
	InfoLevel LogLevel = "info"
	// WarnLevel is for logging messages about possible issues.
	WarnLevel LogLevel = "warn"
	// ErrorLevel is for logging errors.
	ErrorLevel LogLevel = "error"
	// FatalLevel is for logging fatal messages. The system shuts down after logging the message.
	FatalLevel LogLevel = "fatal"

	// UndefinedLevel is for undefined log level.
	UndefinedLevel LogLevel = "undefined"
)

type Logger

type Logger interface {
	// EnableJSONOutput enables JSON formatted output log
	EnableJSONOutput(enabled bool)

	// SetAppID sets dapr_id field in the log. Default value is empty string
	SetAppID(id string)

	// SetOutputLevel sets the log output level
	SetOutputLevel(outputLevel LogLevel)
	// SetOutput sets the destination for the logs
	SetOutput(dst io.Writer)

	// IsOutputLevelEnabled returns true if the logger will output this LogLevel.
	IsOutputLevelEnabled(level LogLevel) bool

	// WithLogType specifies the log_type field in log. Default value is LogTypeLog
	WithLogType(logType string) Logger

	// WithFields returns a logger with the added structured fields.
	WithFields(fields map[string]any) Logger

	// Info logs a message at level Info.
	Info(args ...any)
	// Infof logs a message at level Info.
	Infof(format string, args ...any)
	// Debug logs a message at level Debug.
	Debug(args ...any)
	// Debugf logs a message at level Debug.
	Debugf(format string, args ...any)
	// Warn logs a message at level Warn.
	Warn(args ...any)
	// Warnf logs a message at level Warn.
	Warnf(format string, args ...any)
	// Error logs a message at level Error.
	Error(args ...any)
	// Errorf logs a message at level Error.
	Errorf(format string, args ...any)
	// Fatal logs a message at level Fatal then the process will exit with status set to 1.
	Fatal(args ...any)
	// Fatalf logs a message at level Fatal then the process will exit with status set to 1.
	Fatalf(format string, args ...any)
}

Logger includes the logging api sets.

func FromContextOrDefault added in v0.0.4

func FromContextOrDefault(ctx context.Context) Logger

FromContextOrDefault returns a Logger from ctx. If no Logger is found, this returns a Logger that discards all log messages.

func NewLogger

func NewLogger(name string) Logger

NewLogger creates new Logger instance.

type Options

type Options struct {

	// JSONFormatEnabled is the flag to enable JSON formatted log
	JSONFormatEnabled bool

	// OutputLevel is the level of logging
	OutputLevel string

	// OutputFile is the destination file path for logs.
	OutputFile string

	// TimestampFormat is the format used for log timestamps, expressed as a
	// Go time layout. An empty value means the default (RFC3339 with
	// nanoseconds).
	TimestampFormat string
	// contains filtered or unexported fields
}

Options defines the sets of options for Dapr logging.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns default values of Options.

func (*Options) AttachCmdFlags

func (o *Options) AttachCmdFlags(
	stringVar func(p *string, name string, value string, usage string),
	boolVar func(p *bool, name string, value bool, usage string),
)

AttachCmdFlags attaches log options to command flags.

func (*Options) SetAppID

func (o *Options) SetAppID(id string)

SetAppID sets Application ID.

func (*Options) SetOutputLevel

func (o *Options) SetOutputLevel(outputLevel string) error

SetOutputLevel sets the log output level.

Jump to

Keyboard shortcuts

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