Documentation ¶
Index ¶
- Constants
- func ApplyParam(p Param, entry wlog.LogEntry)
- func CallerPkg(parentCaller, parentPkg int) string
- func SetDefaultLoggerCreator(creator func() Logger)
- func WithLogger(ctx context.Context, logger Logger) context.Context
- func WithLoggerParams(ctx context.Context, params ...Param) context.Context
- type Logger
- type Param
- func Origin(origin string) Param
- func OriginFromCallLine() Param
- func OriginFromInitLine() Param
- func OriginFromInitPkg(skipPkg int) Param
- func Params(object wparams.ParamStorer) Param
- func SID(sid string) Param
- func SafeParam(key string, value interface{}) Param
- func SafeParams(safe map[string]interface{}) Param
- func Stacktrace(err error) Param
- func Tag(key, value string) Param
- func Tags(tags map[string]string) Param
- func TokenID(tokenID string) Param
- func TraceID(traceID string) Param
- func UID(uid string) Param
- func UnsafeParam(key string, value interface{}) Param
- func UnsafeParams(unsafe map[string]interface{}) Param
Constants ¶
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 CallerPkg ¶
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 SetDefaultLoggerCreator ¶
func SetDefaultLoggerCreator(creator func() Logger)
func WithLogger ¶
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 ¶
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 ¶
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 NewFromCreator ¶
func WithParams ¶
type Param ¶
type Param interface {
// contains filtered or unexported methods
}
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.
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 ¶
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".