svc1log

package
v1.55.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: Apache-2.0 Imports: 15 Imported by: 40

Documentation

Index

Constants

View Source
const (
	TypeValue = "service.1"

	LevelKey        = "level"
	LevelDebugValue = "DEBUG"
	LevelInfoValue  = "INFO"
	LevelWarnValue  = "WARN"
	LevelErrorValue = "ERROR"

	OriginKey     = "origin"
	ThreadKey     = "thread"
	MessageKey    = "message"
	ParamsKey     = "params"
	StacktraceKey = "stacktrace"
	TagsKey       = "tags"
)

Variables

This section is empty.

Functions

func ApplyParam

func ApplyParam(p Param, entry wlog.LogEntry)

func CallerPkg

func CallerPkg(parentCaller, parentPkg int) string

CallerPkg returns a package path based on the location at which this function is called and the parameters given to the function. This can be used in conjunction with the "Origin" param to set the origin field programmatically.

The parentCaller parameter specifies the number of "parents" to go back in the call stack, while the parentPkg parameter determines the level of the parent package that should be used. For example, if this function is called in a file with the package path "github.com/palantir/witchcraft-go-logging/wlog" and that function is called from a file with the package path "github.com/palantir/project/helper", then with parentCaller=0 and parentPkg=0 the returned value would be "github.com/palantir/witchcraft-go-logging/wlog", while with parentCaller=1 and parentPkg=1 the value would be "github.com/palantir/project" (parentCaller=1 sets the package to "github.com/palantir/project/helper" and parentPkg=1 causes the package to become "github.com/palantir/project").

func DebugLevelParam added in v1.11.0

func DebugLevelParam() wlog.Param

func ErrorLevelParam added in v1.11.0

func ErrorLevelParam() wlog.Param

func InfoLevelParam added in v1.11.0

func InfoLevelParam() wlog.Param

func SetDefaultLoggerCreator

func SetDefaultLoggerCreator(creator func() Logger)

func ToParams added in v1.11.0

func ToParams(level wlog.Param, inParams []Param) []wlog.Param

func WarnLevelParam added in v1.11.0

func WarnLevelParam() wlog.Param

func WithLogger

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

WithLogger returns a copy of the provided context with the provided Logger included as a value. This operation will replace any logger that was previously set on the context (along with all parameters that may have been set on the logger).

func WithLoggerParams

func WithLoggerParams(ctx context.Context, params ...Param) context.Context

WithLoggerParams returns a copy of the provided context whose logger is configured with the provided parameters. If no parameters are provided, the original context is returned unmodified. If the provided context did not have a logger set on it, the returned context will contain the default logger configured with the provided parameters. If any of the provided parameters set safe or unsafe values, the returned context will also have those values set on it using the wparams.ContextWithSafeAndUnsafeParams function.

Types

type Logger

type Logger interface {
	Debug(msg string, params ...Param)
	Info(msg string, params ...Param)
	Warn(msg string, params ...Param)
	Error(msg string, params ...Param)
	SetLevel(level wlog.LogLevel)
}

func FromContext

func FromContext(ctx context.Context) Logger

FromContext returns the Logger stored in the provided context. If no logger is set on the context, returns the logger created by calling DefaultLogger. If the context contains a TraceID set using wtracing, the returned logger has that TraceID set on it as a parameter. Any safe or unsafe parameters stored on the context using wparams are also set as parameters on the returned logger.

func New

func New(w io.Writer, level wlog.LogLevel, params ...Param) Logger

func NewFromCreator

func NewFromCreator(w io.Writer, level wlog.LogLevel, creator wlog.LeveledLoggerCreator, params ...Param) Logger

func WithParams

func WithParams(logger Logger, params ...Param) Logger

type Param

type Param interface {
	// contains filtered or unexported methods
}

func OrgID added in v1.41.0

func OrgID(orgID string) Param

func Origin

func Origin(origin string) Param

Origin sets the "origin" field to be the provided value if it is non-empty.

func OriginFromCallLine

func OriginFromCallLine() Param

OriginFromCallLine sets the "origin" field to be the filename and line of the location at which the logger invocation is performed.

Note that, when this parameter is used, every log invocation will perform a "runtime.Caller" call, which may not be suitable for performance-critical scenarios.

Note that this parameter is tied to the implementation details of the logger implementations defined in the svc1log package (it hard-codes assumptions relating to the number of call stacks that must be skipped to reach the log site). Using this parameter with an svc1log.Logger implementation not defined in the svc1log package may result in incorrect output. If wrapping the default implementation of svc1log.Logger, OriginFromCallLineWithSkip allows for trimming additional stack frames.

func OriginFromCallLineWithSkip added in v1.8.0

func OriginFromCallLineWithSkip(skipFrames int) Param

OriginFromCallLineWithSkip is like OriginFromCallLine but allows for configuring additional skipped stack frames. This allows for libraries wrapping loggers to hide their implementation frames from the caller.

func OriginFromInitLine

func OriginFromInitLine() Param

OriginFromInitLine sets the "origin" field to be the filename and line of the location at which this function is called.

func OriginFromInitPkg

func OriginFromInitPkg(skipPkg int) Param

OriginFromInitPkg sets the "origin" field to be the package path of the location at which this function is called. The skipPkg parameter determines the level of the parent package that should be used. For example, if this function is called in a file with the package path "github.com/palantir/witchcraft-go-logging/wlog", then with skipPkg=0 the origin would be "github.com/palantir/witchcraft-go-logging/wlog", while with skipPkg=1 the origin would be "github.com/palantir/witchcraft-go-logging".

func Params

func Params(object wparams.ParamStorer) Param

func SID

func SID(sid string) Param

func SafeParam

func SafeParam(key string, value interface{}) Param

func SafeParams

func SafeParams(safe map[string]interface{}) Param

func Stacktrace

func Stacktrace(err error) Param

func Tag

func Tag(key, value string) Param

func Tags

func Tags(tags map[string]string) Param

func TokenID

func TokenID(tokenID string) Param

func TraceID

func TraceID(traceID string) Param

func UID

func UID(uid string) Param

func UnsafeParam

func UnsafeParam(key string, value interface{}) Param

func UnsafeParams

func UnsafeParams(unsafe map[string]interface{}) Param

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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