log

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: Apache-2.0 Imports: 13 Imported by: 36

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CapturePanic

func CapturePanic(errPanic interface{}, 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 errPanic MUST be the result from calling recover, which MUST be done in a single level deep deferred function. The usual way of calling this is: - defer func() { log.CapturePanic(recover(), logger, &err) }()

Types

type Logger

type Logger interface {
	Debugf(msg string, args ...any)
	Debug(msg string, tags ...tag.Tag)
	Info(msg string, tags ...tag.Tag)
	Warn(msg string, tags ...tag.Tag)
	Error(msg string, tags ...tag.Tag)
	Fatal(msg string, tags ...tag.Tag)
	WithTags(tags ...tag.Tag) Logger
	SampleInfo(msg string, sampleRate int, tags ...tag.Tag)
	DebugOn() bool
	// Helper returns a logger that will skip one more level in stack trace. This is helpful for layered architecture, when you want to point to a business logic error, instead of pointing to the wrapped generated level.
	Helper() Logger
}

Logger is our abstraction for logging Usage examples:

 import "github.com/uber/cadence/common/log/tag"
 1) logger = logger.WithTags(
         tag.WorkflowNextEventID( 123),
         tag.WorkflowActionWorkflowStarted,
         tag.WorkflowDomainID("test-domain-id"))
    logger.Info("hello world")
 2) logger.Info("hello world",
         tag.WorkflowNextEventID( 123),
         tag.WorkflowActionWorkflowStarted,
         tag.WorkflowDomainID("test-domain-id"))
	   )
 Note: msg should be static, it is not recommended to use fmt.Sprintf() for msg.
       Anything dynamic should be tagged.

func NewLogger added in v1.3.0

func NewLogger(zapLogger *zap.Logger, opts ...Option) Logger

NewLogger returns a new logger

func NewNoop

func NewNoop() Logger

NewNoop return a noop logger

func NewReplayLogger added in v1.3.0

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

NewReplayLogger creates a logger which is aware of cadence's replay mode

func NewThrottledLogger added in v1.3.0

func NewThrottledLogger(logger Logger, rps dynamicproperties.IntPropertyFn) Logger

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

Fatal/Panic logs are always emitted without any throttling

type MockLogger

type MockLogger struct {
	mock.Mock
}

MockLogger is an autogenerated mock type for the Logger type

func NewMockLogger added in v1.3.1

func NewMockLogger(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockLogger

NewMockLogger creates a new instance of MockLogger. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockLogger) Debug

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

Debug provides a mock function with given fields: msg, tags

func (*MockLogger) DebugOn added in v1.3.0

func (_m *MockLogger) DebugOn() bool

DebugOn provides a mock function with given fields:

func (*MockLogger) Debugf added in v1.2.7

func (_m *MockLogger) Debugf(msg string, args ...interface{})

Debugf provides a mock function with given fields: msg, args

func (*MockLogger) Error

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

Error provides a mock function with given fields: msg, tags

func (*MockLogger) Fatal

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

Fatal provides a mock function with given fields: msg, tags

func (*MockLogger) Helper added in v1.3.1

func (_m *MockLogger) Helper() Logger

Helper provides a mock function with given fields:

func (*MockLogger) Info

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

Info provides a mock function with given fields: msg, tags

func (*MockLogger) SampleInfo added in v1.0.0

func (_m *MockLogger) SampleInfo(msg string, sampleRate int, tags ...tag.Tag)

SampleInfo provides a mock function with given fields: msg, sampleRate, tags

func (*MockLogger) Warn

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

Warn provides a mock function with given fields: msg, tags

func (*MockLogger) WithTags

func (_m *MockLogger) WithTags(tags ...tag.Tag) Logger

WithTags provides a mock function with given fields: tags

type Option added in v1.3.0

type Option func(impl *loggerImpl)

Option is used to set options for the logger.

func WithSampleFunc added in v1.3.0

func WithSampleFunc(fn func(int) bool) Option

WithSampleFunc sets the sampling function for the logger.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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