log

package
v1.32.1-x.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package log is a generated GoMock package.

Index

Constants

View Source
const (

	// Console output (testing.T.Log):
	TestLogFormatEnvVar = "TEMPORAL_TEST_LOG_FORMAT" // "console" (default) or "json"
	TestLogLevelEnvVar  = "TEMPORAL_TEST_LOG_LEVEL"  // min level written to console (default: debug)

	// File output (written once per process to a shared file):
	TestLogFileEnvVar       = "TEMPORAL_TEST_LOG_FILE"        // path to log file; empty disables file logging
	TestLogFileFormatEnvVar = "TEMPORAL_TEST_LOG_FILE_FORMAT" // "json" (default) or "console"
	TestLogFileLevelEnvVar  = "TEMPORAL_TEST_LOG_FILE_LEVEL"  // min level written to file (default: debug)
)

Variables

View Source
var DefaultZapEncoderConfig = zapcore.EncoderConfig{
	TimeKey:             "ts",
	LevelKey:            "level",
	NameKey:             "logger",
	CallerKey:           zapcore.OmitKey,
	FunctionKey:         zapcore.OmitKey,
	MessageKey:          "msg",
	StacktraceKey:       "stacktrace",
	LineEnding:          zapcore.DefaultLineEnding,
	EncodeLevel:         zapcore.LowercaseLevelEncoder,
	EncodeTime:          zapcore.ISO8601TimeEncoder,
	EncodeDuration:      zapcore.SecondsDurationEncoder,
	EncodeCaller:        zapcore.ShortCallerEncoder,
	NewReflectedEncoder: newSafeReflectedEncoder,
}

Functions

func BuildZapLogger

func BuildZapLogger(cfg Config) *zap.Logger

BuildZapLogger builds and returns a new zap.Logger for this logging configuration

func CapturePanic

func CapturePanic(logger Logger, retError *error)

CapturePanic is used to capture panic, it will log the panic and also return the error through pointer. If the panic value is not error then a default error is returned We have to use pointer is because in golang: "recover return nil if was not called directly by a deferred function." And we have to set the returned error otherwise our handler will return nil as error which is incorrect

func NewCLILogger

func NewCLILogger() *zapLogger

NewCLILogger returns a logger at debug level and log into STDERR for logging from within CLI tools

func NewLazyLogger

func NewLazyLogger(logger Logger, tagFn func() []tag.Tag) *lazyLogger

func NewNoopLogger

func NewNoopLogger() *noopLogger

NewNoopLogger return a noopLogger

func NewReplayLogger

func NewReplayLogger(logger Logger, ctx workflow.Context, enableLogInReplay bool) *replayLogger

NewReplayLogger creates a logger which is aware of Temporal replay mode

func NewSlogLogger

func NewSlogLogger(logger Logger) *slog.Logger

NewSlogLogger creates an slog.Logger from a given logger.

func NewTestLogger

func NewTestLogger() *zapLogger

NewTestLogger returns a logger for tests Deprecated: Use testlogger.TestLogger instead.

func NewThrottledLogger

func NewThrottledLogger(logger Logger, rps quotas.RateFn) *throttledLogger

NewThrottledLogger returns an implementation of logger that throttles the log messages being emitted. The underlying implementation uses a token bucket rate limiter and stops emitting logs once the bucket runs out of tokens

Fatal/Panic/DPanic logs are always emitted without any throttling

func NewZapLogger

func NewZapLogger(zl *zap.Logger) *zapLogger

NewZapLogger returns a new zap based logger from zap.Logger

func ParseZapLevel

func ParseZapLevel(level string) zapcore.Level

Types

type Config

type Config struct {
	// Stdout is true if the output needs to goto standard out; default is stderr
	Stdout bool `yaml:"stdout"`
	// Level is the desired log level; see colocated zap_logger.go::parseZapLevel()
	Level string `yaml:"level"`
	// OutputFile is the path to the log output file
	OutputFile string `yaml:"outputFile"`
	// Format determines the format of each log file printed to the output.
	// Acceptable values are "json" or "console". The default is "json".
	// Use "console" if you want stack traces to appear on multiple lines.
	Format string `yaml:"format"`
	// Development determines whether the logger is run in Development (== Test) or in
	// Production mode.  Default is Production.  Production-stage disables panics from
	// DPanic logging.
	Development bool `yaml:"development"`
}

Config contains the config items for logger

type Logger

type Logger interface {
	Debug(msg string, tags ...tag.Tag)
	Info(msg string, tags ...tag.Tag)
	Warn(msg string, tags ...tag.Tag)
	Error(msg string, tags ...tag.Tag)
	DPanic(msg string, tags ...tag.Tag)
	Panic(msg string, tags ...tag.Tag)
	Fatal(msg string, tags ...tag.Tag)
}

Logger is the logging interface. Usage example:

 logger.Info("hello world",
         tag.WorkflowNextEventID(123),
         tag.WorkflowActionWorkflowStarted,
         tag.WorkflowNamespaceID("test-namespace-id")),
	 )
 Note: msg should be static, do not use fmt.Sprintf() for msg. Anything dynamic should be tagged.

func With

func With(logger Logger, tags ...tag.Tag) Logger

With returns Logger instance that prepend every log entry with tags. If logger implements WithLogger it is used, otherwise every log call will be intercepted.

type MockLogger

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

MockLogger is a mock of Logger interface.

func NewMockLogger

func NewMockLogger(ctrl *gomock.Controller) *MockLogger

NewMockLogger creates a new mock instance.

func (*MockLogger) DPanic

func (m *MockLogger) DPanic(msg string, tags ...tag.Tag)

DPanic mocks base method.

func (*MockLogger) Debug

func (m *MockLogger) Debug(msg string, tags ...tag.Tag)

Debug mocks base method.

func (*MockLogger) EXPECT

func (m *MockLogger) EXPECT() *MockLoggerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockLogger) Error

func (m *MockLogger) Error(msg string, tags ...tag.Tag)

Error mocks base method.

func (*MockLogger) Fatal

func (m *MockLogger) Fatal(msg string, tags ...tag.Tag)

Fatal mocks base method.

func (*MockLogger) Info

func (m *MockLogger) Info(msg string, tags ...tag.Tag)

Info mocks base method.

func (*MockLogger) Panic

func (m *MockLogger) Panic(msg string, tags ...tag.Tag)

Panic mocks base method.

func (*MockLogger) Warn

func (m *MockLogger) Warn(msg string, tags ...tag.Tag)

Warn mocks base method.

type MockLoggerMockRecorder

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

MockLoggerMockRecorder is the mock recorder for MockLogger.

func (*MockLoggerMockRecorder) DPanic

func (mr *MockLoggerMockRecorder) DPanic(msg any, tags ...any) *gomock.Call

DPanic indicates an expected call of DPanic.

func (*MockLoggerMockRecorder) Debug

func (mr *MockLoggerMockRecorder) Debug(msg any, tags ...any) *gomock.Call

Debug indicates an expected call of Debug.

func (*MockLoggerMockRecorder) Error

func (mr *MockLoggerMockRecorder) Error(msg any, tags ...any) *gomock.Call

Error indicates an expected call of Error.

func (*MockLoggerMockRecorder) Fatal

func (mr *MockLoggerMockRecorder) Fatal(msg any, tags ...any) *gomock.Call

Fatal indicates an expected call of Fatal.

func (*MockLoggerMockRecorder) Info

func (mr *MockLoggerMockRecorder) Info(msg any, tags ...any) *gomock.Call

Info indicates an expected call of Info.

func (*MockLoggerMockRecorder) Panic

func (mr *MockLoggerMockRecorder) Panic(msg any, tags ...any) *gomock.Call

Panic indicates an expected call of Panic.

func (*MockLoggerMockRecorder) Warn

func (mr *MockLoggerMockRecorder) Warn(msg any, tags ...any) *gomock.Call

Warn indicates an expected call of Warn.

type MockSkipLogger

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

MockSkipLogger is a mock of SkipLogger interface.

func NewMockSkipLogger

func NewMockSkipLogger(ctrl *gomock.Controller) *MockSkipLogger

NewMockSkipLogger creates a new mock instance.

func (*MockSkipLogger) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockSkipLogger) Skip

func (m *MockSkipLogger) Skip(extraSkip int) Logger

Skip mocks base method.

type MockSkipLoggerMockRecorder

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

MockSkipLoggerMockRecorder is the mock recorder for MockSkipLogger.

func (*MockSkipLoggerMockRecorder) Skip

func (mr *MockSkipLoggerMockRecorder) Skip(extraSkip any) *gomock.Call

Skip indicates an expected call of Skip.

type MockWithLogger

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

MockWithLogger is a mock of WithLogger interface.

func NewMockWithLogger

func NewMockWithLogger(ctrl *gomock.Controller) *MockWithLogger

NewMockWithLogger creates a new mock instance.

func (*MockWithLogger) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockWithLogger) With

func (m *MockWithLogger) With(tags ...tag.Tag) Logger

With mocks base method.

type MockWithLoggerMockRecorder

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

MockWithLoggerMockRecorder is the mock recorder for MockWithLogger.

func (*MockWithLoggerMockRecorder) With

func (mr *MockWithLoggerMockRecorder) With(tags ...any) *gomock.Call

With indicates an expected call of With.

type SLogWrapper

type SLogWrapper interface {
	SLog() *slog.Logger
}

SLogWrapper allows extracting an underlying slog logger.

type SdkLogger

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

func NewSdkLogger

func NewSdkLogger(logger Logger) *SdkLogger

func (*SdkLogger) Debug

func (l *SdkLogger) Debug(msg string, keyvals ...any)

func (*SdkLogger) Error

func (l *SdkLogger) Error(msg string, keyvals ...any)

func (*SdkLogger) Info

func (l *SdkLogger) Info(msg string, keyvals ...any)

func (*SdkLogger) Warn

func (l *SdkLogger) Warn(msg string, keyvals ...any)

func (*SdkLogger) With

func (l *SdkLogger) With(keyvals ...any) log.Logger

type SkipLogger

type SkipLogger interface {
	Skip(extraSkip int) Logger
}

If logger implements SkipLogger then Skip method will be called and extraSkip parameter will have number of extra stack trace frames to skip (useful to log caller func file/line).

type SnTaggedLogger

type SnTaggedLogger Logger

Special logger types for use with fx

type ThrottledLogger

type ThrottledLogger Logger

type WithLogger

type WithLogger interface {
	With(tags ...tag.Tag) Logger
}

Implement WithLogger interface with With method which should return new instance of logger with prepended tags. If WithLogger is not implemented on logger, internal (not very efficient) preppender is used. Create prepended logger example:

logger = log.With(
        logger,
        tag.WorkflowNextEventID(123),
        tag.WorkflowActionWorkflowStarted,
        tag.WorkflowNamespaceID("test-namespace-id"))
...
logger.Info("hello world")

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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