Documentation
¶
Index ¶
- Constants
- Variables
- func AddCallDepth(depth int)
- func AppendKVInMsg() kvOption
- func ConvertErrToKV() errOption
- func ConvertObjToKV() objOption
- func CtxAddKVs(ctx context.Context, kvs ...interface{}) context.Context
- func CtxDebug(ctx context.Context, format string, v ...interface{})
- func CtxDebugKVs(ctx context.Context, kvs ...interface{})
- func CtxDebugsf(ctx context.Context, format string, v ...string)
- func CtxError(ctx context.Context, format string, v ...interface{})
- func CtxErrorKVs(ctx context.Context, kvs ...interface{})
- func CtxErrorsf(ctx context.Context, format string, v ...string)
- func CtxFatal(ctx context.Context, format string, v ...interface{})
- func CtxFatalKVs(ctx context.Context, kvs ...interface{})
- func CtxFatalsf(ctx context.Context, format string, v ...string)
- func CtxFlushNotice(ctx context.Context)
- func CtxInfo(ctx context.Context, format string, v ...interface{})
- func CtxInfoKVs(ctx context.Context, kvs ...interface{})
- func CtxInfosf(ctx context.Context, format string, v ...string)
- func CtxNotice(ctx context.Context, format string, v ...interface{})
- func CtxNoticeKVs(ctx context.Context, kvs ...interface{})
- func CtxNoticesf(ctx context.Context, format string, v ...string)
- func CtxPushNotice(ctx context.Context, k, v interface{})
- func CtxStackInfo(ctx context.Context, stackInfo StackInfo) context.Context
- func CtxTrace(ctx context.Context, format string, v ...interface{})
- func CtxTraceKVs(ctx context.Context, kvs ...interface{})
- func CtxTracesf(ctx context.Context, format string, v ...string)
- func CtxWarn(ctx context.Context, format string, v ...interface{})
- func CtxWarnKVs(ctx context.Context, kvs ...interface{})
- func CtxWarnsf(ctx context.Context, format string, v ...string)
- func Debug(format string, v ...interface{})
- func Debugf(format string, v ...interface{})
- func EnableDynamicLogLevel()
- func Error(format string, v ...interface{})
- func Errorf(format string, v ...interface{})
- func Fatal(format string, v ...interface{})
- func Fatalf(format string, v ...interface{})
- func Flush()
- func GetAllKVs(ctx context.Context) []interface{}
- func GetAllKVsStr(ctx context.Context) string
- func GetWriters() []leveledWriter
- func Info(format string, v ...interface{})
- func Infof(format string, v ...interface{})
- func Init()
- func IsSecMarkEnabled() bool
- func NewLogger() *logger
- func NewNoticeCtx(ctx context.Context) context.Context
- func Notice(format string, v ...interface{})
- func Noticef(format string, v ...interface{})
- func PrintStack(printAllGoroutines bool)
- func ResetCallDepth()
- func SecMark(key, val interface{}) string
- func SetCurrentVersion(version string)
- func SetDefaultLogCallDepthOffset(offset int)
- func SetDefaultLogPrefixFileDepth(depth int)
- func SetDefaultLogPrefixWithoutCluster(withoutCluster bool)
- func SetDefaultLogPrefixWithoutHost(withoutHost bool)
- func SetDefaultLogPrefixWithoutPSM(withoutPSM bool)
- func SetDefaultLogPrefixWithoutSpanID(withoutSpanID bool)
- func SetDefaultLogPrefixWithoutStage(withoutStage bool)
- func SetDefaultLogger(ops ...Option)
- func SetLevel(newLevel Level)
- func SetLevelForWriters(newLevel Level, logWriters ...writer.LogWriter)
- func SetLogPrefixTimePrecision(precision TimePrecision)
- func SetNewLogIDCtxKey(newKey string) contextKey
- func SetSecMark(isEnabled bool)
- func Stop()
- func Trace(format string, v ...interface{})
- func Tracef(format string, v ...interface{})
- func ValueToStr(o interface{}) string
- func Warn(format string, v ...interface{})
- func Warnf(format string, v ...interface{})
- func WithCtx(ctx context.Context) loggerOption
- func WithDynamicLoggerLevel(level Level) loggerOption
- type CLogger
- func (l *CLogger) Close() error
- func (l *CLogger) CtxFlushNotice(ctx context.Context)
- func (l *CLogger) CtxLevel(ctx context.Context) (Level, bool)
- func (l *CLogger) Debug(ops ...loggerOption) *Log
- func (l *CLogger) Error(ops ...loggerOption) *Log
- func (l *CLogger) Fatal(ops ...loggerOption) *Log
- func (l *CLogger) Flush() error
- func (l *CLogger) GetLevel() Level
- func (l *CLogger) GetOptions() []Option
- func (l *CLogger) GetWriter() []leveledWriter
- func (l *CLogger) Info(ops ...loggerOption) *Log
- func (l *CLogger) Notice(ops ...loggerOption) *Log
- func (l *CLogger) SetLevel(newLevel Level)
- func (l *CLogger) SetLevelForWriters(newLevel Level, logWriters ...writer.LogWriter)
- func (l *CLogger) Trace(ops ...loggerOption) *Log
- func (l *CLogger) Warn(ops ...loggerOption) *Log
- type CompatLogger
- func (l *CompatLogger) Close() error
- func (l *CompatLogger) CtxDebug(ctx context.Context, format string, v ...interface{})
- func (l *CompatLogger) CtxDebugKVs(ctx context.Context, kvs ...interface{})
- func (l *CompatLogger) CtxDebugsf(ctx context.Context, format string, v ...string)
- func (l *CompatLogger) CtxError(ctx context.Context, format string, v ...interface{})
- func (l *CompatLogger) CtxErrorKVs(ctx context.Context, kvs ...interface{})
- func (l *CompatLogger) CtxErrorsf(ctx context.Context, format string, v ...string)
- func (l *CompatLogger) CtxFatal(ctx context.Context, format string, v ...interface{})
- func (l *CompatLogger) CtxFatalKVs(ctx context.Context, kvs ...interface{})
- func (l *CompatLogger) CtxFatalsf(ctx context.Context, format string, v ...string)
- func (l *CompatLogger) CtxFlushNotice(ctx context.Context)
- func (l *CompatLogger) CtxInfo(ctx context.Context, format string, v ...interface{})
- func (l *CompatLogger) CtxInfoKVs(ctx context.Context, kvs ...interface{})
- func (l *CompatLogger) CtxInfosf(ctx context.Context, format string, v ...string)
- func (l *CompatLogger) CtxNotice(ctx context.Context, format string, v ...interface{})
- func (l *CompatLogger) CtxNoticeKVs(ctx context.Context, kvs ...interface{})
- func (l *CompatLogger) CtxNoticesf(ctx context.Context, format string, v ...string)
- func (l *CompatLogger) CtxTrace(ctx context.Context, format string, v ...interface{})
- func (l *CompatLogger) CtxTraceKVs(ctx context.Context, kvs ...interface{})
- func (l *CompatLogger) CtxTracesf(ctx context.Context, format string, v ...string)
- func (l *CompatLogger) CtxWarn(ctx context.Context, format string, v ...interface{})
- func (l *CompatLogger) CtxWarnKVs(ctx context.Context, kvs ...interface{})
- func (l *CompatLogger) CtxWarnsf(ctx context.Context, format string, v ...string)
- func (l *CompatLogger) Debug(format string, v ...interface{})
- func (l *CompatLogger) Error(format string, v ...interface{})
- func (l *CompatLogger) Fatal(format string, v ...interface{})
- func (l *CompatLogger) Flush()
- func (l *CompatLogger) Info(format string, v ...interface{})
- func (l *CompatLogger) Notice(format string, v ...interface{})
- func (l *CompatLogger) PrintStack(printAllGoroutines bool)
- func (l *CompatLogger) Stop()
- func (l *CompatLogger) Trace(format string, v ...interface{})
- func (l *CompatLogger) Warn(format string, v ...interface{})
- type CompatibleLoggerOption
- type ContentSetter
- type KVPosition
- type Lazier
- type Level
- type Line
- type Log
- func (l *Log) Bool(b bool) *Log
- func (l *Log) CallDepth(d int) *Log
- func (l *Log) Emit()
- func (l *Log) EmitEveryN(n int)
- func (l *Log) EmplaceKV(key interface{}, value interface{}) *Log
- func (l *Log) EmplaceKVs(kvlist ...interface{}) *Log
- func (l *Log) Error(err error, ops ...errOption) *Log
- func (l *Log) Float(fs ...float64) *Log
- func (l *Log) Int(is ...int) *Log
- func (l *Log) Int64(is ...int64) *Log
- func (l *Log) KV(key interface{}, value interface{}, ops ...kvOption) *Log
- func (l *Log) KVs(kvlist ...interface{}) *Log
- func (l *Log) Limit(limit int) *Log
- func (l *Log) Line(line *Line) *Log
- func (l *Log) Location(pos string) *Log
- func (l *Log) Obj(o interface{}, ops ...objOption) *Log
- func (l *Log) Stack(printAllGoroutines bool) *Log
- func (l *Log) Str(contents ...string) *Log
- func (l *Log) StrKV(key, value string) *Log
- func (l *Log) StrKVs(kvlist ...string) *Log
- func (l *Log) With(ctx context.Context) *Log
- type Middleware
- type NoticeKVs
- type Option
- func AppendWriter(level Level, ws ...writer.LogWriter) Option
- func ConfigSecMark(isEnabled bool) Option
- func SetCallDepth(c int) Option
- func SetConvertErrorToKV(isEnabled bool) Option
- func SetConvertObjectToKV(isEnabled bool) Option
- func SetDeduplicateCtxKVs(isEnabled bool) Option
- func SetDisplayEnvInfo(displayEnvInfo bool) Option
- func SetDisplayFuncName(withPackage bool) Option
- func SetEnableDynamicLevel(isEnabled bool) Option
- func SetEnableKVList(isEnabled bool) Optiondeprecated
- func SetFatalOSExit(isEnabled bool) Option
- func SetFullPath(fullpath bool) Option
- func SetKVPosition(position KVPosition) Option
- func SetLazyHandleCtx() Option
- func SetLogPrefixFileDepth(depth int) Option
- func SetLogPrefixWithoutCluster(withoutCluster bool) Option
- func SetLogPrefixWithoutHost(withoutHost bool) Option
- func SetLogPrefixWithoutPSM(withoutPSM bool) Option
- func SetLogPrefixWithoutSpanID(withoutSpanID bool) Option
- func SetLogPrefixWithoutStage(withoutStage bool) Option
- func SetMiddleware(m ...Middleware) Option
- func SetPSM(psm string) Option
- func SetPadding(padding string) Option
- func SetTracing() Option
- func SetWriter(level Level, ws ...writer.LogWriter) Option
- func SetZoneInfo(include bool) Option
- func UpdateMiddleware(m ...Middleware) Option
- type RegionType
- type RewritableLog
- type StackInfo
- type TimePrecision
Examples ¶
Constants ¶
const ( LogIDCtxKey = contextKey("K_LOGID") DynamicLogLevelKey = contextKey("K_DYNAMIC_LOG_LEVEL") )
const ( TimePrecisionSecond = time.TimePrecisionSecond TimePrecisionMillisecond = time.TimePrecisionMillisecond TimePrecisionMicrosecond = time.TimePrecisionMicrosecond )
Variables ¶
var (
DefaultLogPath = "log/app" // 默认日志路径:curDir/log/app/psm.log
)
Functions ¶
func AddCallDepth ¶
func AddCallDepth(depth int)
AddCallDepth temporarily increases the call stack depth of the current logger to get the correct caller location. Remember to call ResetCallDepth() after use.
func AppendKVInMsg ¶
func AppendKVInMsg() kvOption
AppendKVInMsg directly append kv to the log body.
func CtxDebugKVs ¶
CtxDebugKVs provides function like logs.CtxDebugKVs.
func CtxDebugsf ¶
CtxDebugsf works like logs.CtxDebugsf.
func CtxErrorKVs ¶
CtxErrorKVs provides function like logs.CtxErrorKVs.
func CtxErrorsf ¶
CtxErrorsf works like logs.CtxErrorsf.
func CtxFatalKVs ¶
CtxFatalKVs provides function like logs.CtxFatalKVs.
func CtxFatalsf ¶
CtxFatalsf works like logs.CtxFatalsf.
func CtxFlushNotice ¶
CtxFlushNotice provides function like logs.CtxFlushNotice
func CtxInfoKVs ¶
CtxInfoKVs provides function like logs.CtxInfoKVs.
func CtxNoticeKVs ¶
CtxNoticeKVs provides function like logs.CtxNoticeKVs.
func CtxNoticesf ¶
CtxNoticesf works like logs.CtxNoticesf.
func CtxPushNotice ¶
func CtxStackInfo ¶
CtxStackInfo marks whether to print the stack in the current log.
func CtxTraceKVs ¶
CtxTraceKVs provides function like logs.CtxTraceKVs.
func CtxTracesf ¶
CtxTracesf works like logs.CtxDebugsf.
func CtxWarnKVs ¶
CtxWarnKVs provides function like logs.CtxWarnKVs.
func EnableDynamicLogLevel ¶
func EnableDynamicLogLevel()
EnableDynamicLogLevel enableds dynamic context log level for compatibleLogger.
func GetAllKVsStr ¶
func IsSecMarkEnabled ¶
func IsSecMarkEnabled() bool
func PrintStack ¶
func PrintStack(printAllGoroutines bool)
PrintStack prints the stacks in Info level. If printAllGoroutines is true, it prints the stacks of all goroutines. Otherwise, it just prints the current goroutine's stack.
func ResetCallDepth ¶
func ResetCallDepth()
ResetCallDepth resets the call depth for the default logger.
func SecMark ¶
func SecMark(key, val interface{}) string
SecMark adds double brackets to the key-value pairs and return the generated string. This is a function that directly exported to users. So we need to check the type of the parameters
func SetCurrentVersion ¶
func SetCurrentVersion(version string)
SetCurrentVersion sets the current version. Call it in program initialization.
func SetDefaultLogCallDepthOffset ¶
func SetDefaultLogCallDepthOffset(offset int)
SetDefaultLogCallDepthOffset sets the default call stack depth for newly created loggers (without considering internal depth). Unlike AddCallDepth which affects the current logger, this function affects all newly created loggers.
func SetDefaultLogPrefixFileDepth ¶
func SetDefaultLogPrefixFileDepth(depth int)
func SetDefaultLogPrefixWithoutCluster ¶ added in v0.1.1
func SetDefaultLogPrefixWithoutCluster(withoutCluster bool)
func SetDefaultLogPrefixWithoutHost ¶ added in v0.1.1
func SetDefaultLogPrefixWithoutHost(withoutHost bool)
func SetDefaultLogPrefixWithoutPSM ¶ added in v0.1.1
func SetDefaultLogPrefixWithoutPSM(withoutPSM bool)
func SetDefaultLogPrefixWithoutSpanID ¶ added in v0.1.1
func SetDefaultLogPrefixWithoutSpanID(withoutSpanID bool)
func SetDefaultLogPrefixWithoutStage ¶ added in v0.1.1
func SetDefaultLogPrefixWithoutStage(withoutStage bool)
func SetDefaultLogger ¶
func SetDefaultLogger(ops ...Option)
SetDefaultLogger resets the default logger with specified options, it is not thread-safe and please only call it in program initialization. Libraries should not config the default logger and leaves it to the application user, otherwise loggers would cover each other.
func SetLevel ¶
func SetLevel(newLevel Level)
SetLevel sets the minimal level for defaultLogger and all writers. It is safe to increase the level.
func SetLevelForWriters ¶
SetLevelForWriters updates the minimal level for the writer of the defaultLogger. It may also update the loggers' level.
func SetLogPrefixTimePrecision ¶ added in v0.1.1
func SetLogPrefixTimePrecision(precision TimePrecision)
SetLogPrefixTimePrecision sets the time precision for the log prefix. It affects all loggers, including the default logger.
func SetNewLogIDCtxKey ¶ added in v0.1.1
func SetNewLogIDCtxKey(newKey string) contextKey
func SetSecMark ¶
func SetSecMark(isEnabled bool)
SetSecMark updates enableSecMark. Call it in program initialization.
func ValueToStr ¶
func ValueToStr(o interface{}) string
func WithCtx ¶
WithCtx attach a context to a specific logger It can also temporarily change the level of the logger
func WithDynamicLoggerLevel ¶
func WithDynamicLoggerLevel(level Level) loggerOption
WithDynamicLoggerLevel temporarily sets the logger level for a log. It can allow user to temporily print low-level logs.
Types ¶
type CLogger ¶
type CLogger struct {
// contains filtered or unexported fields
}
CLogger is a common logging handler. It is also the default logger.
var (
V1 *CLogger
)
func NewCLogger ¶
NewCLogger creates a new CLogger with options
func (*CLogger) CtxFlushNotice ¶
func (*CLogger) GetLevel ¶
func (l *CLogger) GetLevel() Level
GetLevel gets the minimal level specified in logger writers.
func (*CLogger) GetOptions ¶
func (*CLogger) SetLevel ¶
func (l *CLogger) SetLevel(newLevel Level)
SetLevel sets the minimal level for the logger. It is safe to increase the level. Please not decrease the level directly. Use SetLevelForWriters instead.
func (*CLogger) SetLevelForWriters ¶
SetLevelForWriters updates the minimal level for the writer. It may also update the loggers' level.
type CompatLogger ¶
type CompatLogger struct {
// contains filtered or unexported fields
}
CompatLogger CLogger does not support std string format originally, CompatLogger creates a simple fast approach fmt.Sprintf, map %s to Log.Str, %f to Log.Float, %v to json.Marshal and ignore any prefix on verbs. it is not only able to boost the format performance but also keep the compatibility.
func NewCompatLogger ¶
func NewCompatLogger(ops ...Option) *CompatLogger
NewCompatLogger creates a compatible logger CompatLogger, it supports Info, CtxInfo, CtxInfosf, CtxInfoKVs and other level methods.
func NewCompatLoggerFrom ¶
func NewCompatLoggerFrom(logger *CLogger, ops ...CompatibleLoggerOption) *CompatLogger
NewCompatLoggerFrom creates a compatible logger CompatLogger from a CLogger.
func (*CompatLogger) Close ¶
func (l *CompatLogger) Close() error
Close flushes logger and graceful exit.
func (*CompatLogger) CtxDebug ¶
func (l *CompatLogger) CtxDebug(ctx context.Context, format string, v ...interface{})
func (*CompatLogger) CtxDebugKVs ¶
func (l *CompatLogger) CtxDebugKVs(ctx context.Context, kvs ...interface{})
func (*CompatLogger) CtxDebugsf ¶
func (l *CompatLogger) CtxDebugsf(ctx context.Context, format string, v ...string)
func (*CompatLogger) CtxError ¶
func (l *CompatLogger) CtxError(ctx context.Context, format string, v ...interface{})
func (*CompatLogger) CtxErrorKVs ¶
func (l *CompatLogger) CtxErrorKVs(ctx context.Context, kvs ...interface{})
func (*CompatLogger) CtxErrorsf ¶
func (l *CompatLogger) CtxErrorsf(ctx context.Context, format string, v ...string)
func (*CompatLogger) CtxFatal ¶
func (l *CompatLogger) CtxFatal(ctx context.Context, format string, v ...interface{})
func (*CompatLogger) CtxFatalKVs ¶
func (l *CompatLogger) CtxFatalKVs(ctx context.Context, kvs ...interface{})
func (*CompatLogger) CtxFatalsf ¶
func (l *CompatLogger) CtxFatalsf(ctx context.Context, format string, v ...string)
func (*CompatLogger) CtxFlushNotice ¶
func (l *CompatLogger) CtxFlushNotice(ctx context.Context)
func (*CompatLogger) CtxInfo ¶
func (l *CompatLogger) CtxInfo(ctx context.Context, format string, v ...interface{})
func (*CompatLogger) CtxInfoKVs ¶
func (l *CompatLogger) CtxInfoKVs(ctx context.Context, kvs ...interface{})
func (*CompatLogger) CtxInfosf ¶
func (l *CompatLogger) CtxInfosf(ctx context.Context, format string, v ...string)
func (*CompatLogger) CtxNotice ¶
func (l *CompatLogger) CtxNotice(ctx context.Context, format string, v ...interface{})
func (*CompatLogger) CtxNoticeKVs ¶
func (l *CompatLogger) CtxNoticeKVs(ctx context.Context, kvs ...interface{})
func (*CompatLogger) CtxNoticesf ¶
func (l *CompatLogger) CtxNoticesf(ctx context.Context, format string, v ...string)
func (*CompatLogger) CtxTrace ¶
func (l *CompatLogger) CtxTrace(ctx context.Context, format string, v ...interface{})
func (*CompatLogger) CtxTraceKVs ¶
func (l *CompatLogger) CtxTraceKVs(ctx context.Context, kvs ...interface{})
func (*CompatLogger) CtxTracesf ¶
func (l *CompatLogger) CtxTracesf(ctx context.Context, format string, v ...string)
func (*CompatLogger) CtxWarn ¶
func (l *CompatLogger) CtxWarn(ctx context.Context, format string, v ...interface{})
func (*CompatLogger) CtxWarnKVs ¶
func (l *CompatLogger) CtxWarnKVs(ctx context.Context, kvs ...interface{})
func (*CompatLogger) CtxWarnsf ¶
func (l *CompatLogger) CtxWarnsf(ctx context.Context, format string, v ...string)
func (*CompatLogger) Debug ¶
func (l *CompatLogger) Debug(format string, v ...interface{})
func (*CompatLogger) Error ¶
func (l *CompatLogger) Error(format string, v ...interface{})
func (*CompatLogger) Fatal ¶
func (l *CompatLogger) Fatal(format string, v ...interface{})
func (*CompatLogger) Flush ¶
func (l *CompatLogger) Flush()
Flush blocks logger and flush all buffered logs.
func (*CompatLogger) Info ¶
func (l *CompatLogger) Info(format string, v ...interface{})
func (*CompatLogger) Notice ¶
func (l *CompatLogger) Notice(format string, v ...interface{})
func (*CompatLogger) PrintStack ¶
func (l *CompatLogger) PrintStack(printAllGoroutines bool)
PrintStack prints the stacks in Info level. If printAllGoroutines is true, it prints the stacks of all goroutines. Otherwise, it just prints the current goroutine's stack.
func (*CompatLogger) Stop ¶
func (l *CompatLogger) Stop()
Stop graceful exit with no error returned.
func (*CompatLogger) Trace ¶
func (l *CompatLogger) Trace(format string, v ...interface{})
func (*CompatLogger) Warn ¶
func (l *CompatLogger) Warn(format string, v ...interface{})
type CompatibleLoggerOption ¶
type CompatibleLoggerOption func(*CompatLogger)
CompatibleLoggerOption provides some options to config CompatLogger
func WithCallDepthOffset ¶
func WithCallDepthOffset(offset int) CompatibleLoggerOption
WithCallDepthOffset sets the call depth offset for the compatibale logger.
func WithDynamicLevel ¶
func WithDynamicLevel(isEnabled bool) CompatibleLoggerOption
WithDynamicLevel sets whether the dyancmic level is enabled for the compatibale logger.
type ContentSetter ¶
ContentSetter allows to rewrite the log content.
type KVPosition ¶
type KVPosition int32
KVPosition defines the position of the kv list
const ( BeforeMsg KVPosition = iota AfterMsg )
type Level ¶
type Level int32
Level defines log levels
const ( // TraceLevel defines Trace Level. TraceLevel Level = iota // DebugLevel defines Debug Level. DebugLevel // InfoLevel defines Info Level. InfoLevel // NoticeLevel defines Notice Level. NoticeLevel // WarnLevel defines Warn Level. WarnLevel // ErrorLevel defines Error Level. ErrorLevel // FatalLevel defines Fatal Level. FatalLevel )
type Line ¶
Line creates a cached source code file line information by sync.Once to avoid reflect call of each log printing.
func CustomLine ¶
func LineWithOnlyFilename ¶
func LineWithOnlyFilename() *Line
If user does not want to define log's Line struct for every log, can use LineWithOnlyFilename to generate a global Line var in its file, and use this in all log.XXX().Line() calls within this file
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log is a log instance of execute each log printing. A Log instance is always bound to a specific Logger, But a Logger can get some log from the log pool.
func (*Log) EmitEveryN ¶
EmitEveryN emits the log based on the count of calls. It logs the 1st call, (N+1)st call, (2N+1)st call, etc.
func (*Log) EmplaceKV ¶
EmplaceKV converts a kv pair into a string (key=value) and append it to the message. It is equivalent to use KV(key, value, AppendKVInMsg())
func (*Log) EmplaceKVs ¶
EmplaceKVs converts a KV list into strings and append them to the message body.
func (*Log) KV ¶
KV creates a KV instance and appends it into the kv list. When the log is emitted, the kv list will be handled depending on cases. If security mark is enabled, it converts the kv to a string (pattern: {{key=value}}) and appends it to the message body.
func (*Log) Limit ¶
Limit controls the rate of a log based on its file location. limit is the max frequency in a second. The rate limit is not accurate. You may find the actual number of logs slightly exceeds limit * time.
func (*Log) Line ¶
Line uses a cached Line instance to avoid reflection overhead, if there is no Line provided, Log would try to call runtime.Caller each printing.
func (*Log) Location ¶
Location directly sets the file location of the log. The users must make sure the file location has the right format. Otherwise, StreamLog may fail to parse the log. It must be "{Filename}.go:{LineNumber}"
func (*Log) Obj ¶
Obj prints a object uses json.Marshal by default and prefer fmt.Stringer if the structure implements it, remind that fmt.Stringer would cause extra malloc here.
func (*Log) Stack ¶
Stack will add stack info when composing the log instance. If printAllGoroutines is true, it prints the stacks of all goroutines. Otherwise, it just prints the current goroutine's stack.
type Middleware ¶
type Middleware func(log RewritableLog) RewritableLog
Middleware function is a hook to get and update logs before writing to each writers.
type NoticeKVs ¶
func (*NoticeKVs) PushNotice ¶
func (l *NoticeKVs) PushNotice(k, v interface{})
type Option ¶
type Option func(*CLogger)
Option provides some options to config CLogger.
func AppendWriter ¶
AppendWriter sets CLogger outputs to which writers. It will not remove existing writers.
func ConfigSecMark ¶
ConfigSecMark sets if the logger needs to add double brackets to key-value pairs example:
isEnabled=false: count=100
isEnabled=true: {{count=100}}
If you also specify the current version of your app, otherwise it will use the image tag by default
func SetCallDepth ¶
SetCallDepth sets CLogger call depth while logging file location.
func SetConvertErrorToKV ¶
SetConvertErrorToKV sets if it converts an error to a KV pair.
func SetConvertObjectToKV ¶
SetConvertObjectToKV sets if it converts an object to a KV pair.
func SetDeduplicateCtxKVs ¶
SetDeduplicateCtxKVs sets if it converts the kvlist in the ctx to a string. if isEnabled is true, it keeps the kvlist and will deduplicate the KVs in StreamLog 2.0 Else it allows duplicate kvs and convert the kvs to a string and append it to the message body.
func SetDisplayEnvInfo ¶
SetDisplayEnvInfo sets if the logger will add a KV pair: ("_env", {env}) to all logs.
func SetDisplayFuncName ¶
SetDisplayFuncName sets if the logger will print the function name. It will attach a kv: func={function name} to the logs. It withPackage is true, function name will look like {pkg name}.{func name}, e.g., func=github.com/facebookgo/ensure.TestFunc
func SetEnableDynamicLevel ¶
SetEnableDynamicLevel sets whether to enable dynamic log level in compatLogger. It only works for compatible logger.
func SetEnableKVList
deprecated
func SetFatalOSExit ¶
SetFatalOSExit sets whether log sdk calls os.Exit after printing fatal log.
func SetFullPath ¶
SetFullPath sets print the full path of log file location.
func SetKVPosition ¶
func SetKVPosition(position KVPosition) Option
SetKVPosition sets the positions of the kv list in console and file writers' output.
func SetLazyHandleCtx ¶
func SetLazyHandleCtx() Option
SetLazyHandleCtx sets if the logger lazily handles the ctx, e.g., extrating kvs from ctx.
func SetLogPrefixFileDepth ¶
SetLogPrefixFileDepth sets how many directory levels to include in file path. - When logPrefixFileDepth is 0, returns only the filename - When logPrefixFileDepth is 1, returns the last directory name and filename - When logPrefixFileDepth is n, returns the last n directory names and filename
func SetLogPrefixWithoutCluster ¶ added in v0.1.1
SetLogPrefixWithoutCluster sets if the log prefix should include the cluster.
func SetLogPrefixWithoutHost ¶ added in v0.1.1
SetLogPrefixWithoutHost sets if the log prefix should include the host.
func SetLogPrefixWithoutPSM ¶ added in v0.1.1
SetLogPrefixWithoutPSM sets if the log prefix should include the PSM.
func SetLogPrefixWithoutSpanID ¶ added in v0.1.1
SetLogPrefixWithoutSpanID sets if the log prefix should include the span ID.
func SetLogPrefixWithoutStage ¶ added in v0.1.1
SetLogPrefixWithoutStage sets if the log prefix should include the stage.
func SetMiddleware ¶
func SetMiddleware(m ...Middleware) Option
SetMiddleware adds the middleware to the logger
func SetPadding ¶
SetPadding sets CLogger padding between each element.
func SetTracing ¶
func SetTracing() Option
SetTracing sets a compatible tracing writer to trace level logs, it is only used in compatible cases,
func SetZoneInfo ¶
SetZoneInfo sets if the time string include zone info example:
include=false: 2021-07-15 15:19:14,161 include=true: 2021-07-15 15:19:14,161 +0800
func UpdateMiddleware ¶
func UpdateMiddleware(m ...Middleware) Option
UpdateMiddleware sets middleware to the logger
type RegionType ¶
type RegionType int32
const ( REGION_NORMAL RegionType = iota REGION_1 REGION_2 )
func DetermineRegion ¶
func DetermineRegion() RegionType
type RewritableLog ¶
type RewritableLog interface {
writer.StructuredLog
ContentSetter
}
RewritableLog provides some methods to get and set logs.
type TimePrecision ¶ added in v0.1.1
type TimePrecision = time.TimePrecision