starlog

package module
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: Apache-2.0 Imports: 32 Imported by: 1

README

# starlog

starlog 是一个面向生产环境的 Go 日志库,兼顾控制台可读性与服务端可观测性。

  • Go 版本:1.16+
  • 核心目标:可读、可控、可扩展、可观测

完整使用说明见 docs/USAGE.md,迁移说明见 docs/MIGRATION.md

快速开始

package main

import (
	"os"

	"b612.me/starlog"
)

func main() {
	log := starlog.NewStarlog(os.Stdout)
	log.SetName("demo")
	log.SetShowStd(true)
	log.SetColorMode(starlog.ColorModeLevelOnly)

	log.WithField("user_id", 42).Info("login ok")
	log.WithError(os.ErrNotExist).Error("open file failed")
}

核心能力

  • 结构化日志:WithField/WithFields/WithError/WithContext
  • 级别过滤:SetLevel/GetLevel/IsLevelEnabled/ParseLevel
  • 格式化输出:TextFormatterJSONFormatter、自定义 Formatter
  • 多路输出:SinkMultiSinkRouteHandler
  • 轮转能力:RotatePolicyStartRotate*NewRotate*Sink
  • 关键词预设:ApplyKeywordPreset/MergeKeywordPreset(内置 MobaLite/MobaFull
  • 高频防爆:去重、采样、限流
  • 脱敏治理:规则式脱敏 + 失败策略
  • 指标可观测:写入错误、异步丢弃、pending、多 sink、轮转状态
  • 生命周期收口:Flush/Sync/Close/Shutdown
  • 并发配置:Config 快照 API(GetConfig/ApplyConfig/UpdateConfig

核心接口

type Handler interface { Handle(context.Context, *Entry) error }
type Formatter interface { Format(*Entry) ([]byte, error) }
type Sink interface { Write([]byte) error; Close() error }

type RotatePolicy interface {
	ShouldRotate(FileInfo, *Entry) bool
	NextPath(string, time.Time) string
}

// 可选扩展。若实现该接口,框架会优先使用 ArchivePath。
type RotateArchivePathProvider interface {
	ArchivePath(string, time.Time) string
}

NextPath 的语义是“归档文件目标路径”。

关键词预设

内置预设:

  • KeywordPresetMobaLite:常用关键词高亮(error/true/warn/success 等)
  • KeywordPresetMobaFull:在 Lite 基础上扩展更多运行态词汇
log := starlog.NewDevelopment(os.Stdout)
log.ApplyKeywordPreset(starlog.KeywordPresetMobaLite) // 覆盖现有关键词配置

// 在预设基础上继续自定义
log.SetKeywordColor("OOM", []starlog.Attr{starlog.FgHiRed, starlog.Bold})

// 可选匹配模式(默认关闭,兼容旧行为)
log.SetKeywordMatchOptions(starlog.KeywordMatchOptions{
	IgnoreCase: true, // 忽略大小写
	WholeWord:  true, // 仅匹配完整单词
})

如需保留已有关键词并叠加预设,使用 MergeKeywordPreset(...)

轮转入口

推荐主路径:

  • StartRotatePolicy
  • StartManagedRotatePolicy
  • StartRotateByTime/StartRotateBySize/StartRotateByTimeSize
  • StartManagedRotateByTime/StartManagedRotateBySize/StartManagedRotateByTimeSize

RouteHandler 分流文件可直接使用轮转 sink:

  • NewRotatePolicySink
  • NewManagedRotatePolicySink
  • NewRotateBy*Sink
  • NewManagedRotateBy*Sink

兼容入口:

  • StartArchive(保留兼容,不推荐新代码使用)

生产初始化示例

package main

import (
	"context"
	"time"

	"b612.me/starlog"
)

func main() {
	log := starlog.NewProduction(nil)
	log.SetName("svc")
	log.SetAutoAppendNewline(true)

	if err := starlog.SetLogFile("./logs/app.log", log, true); err != nil {
		panic(err)
	}

	if err := starlog.StartManagedRotateBySize(log, 200*1024*1024, 5, starlog.RotateManageOptions{
		MaxBackups: 14,
		MaxAge:     14 * 24 * time.Hour,
		Compress:   true,
		Pattern:    "20060102-150405",
	}); err != nil {
		panic(err)
	}

	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
	defer cancel()
	defer log.Shutdown(ctx)

	log.WithField("module", "boot").Info("service started")
}

兼容策略

  • 现有旧 API 仍可继续使用。
  • 新功能优先通过新增 API 提供,不强制破坏式迁移。
  • 新项目建议优先使用 Config API 与 RotatePolicy 主路径。

Documentation

Index

Constants

View Source
const (
	LvDebug = iota
	LvInfo
	LvNotice
	LvWarning
	LvError
	LvCritical
	LvPanic
	LvFatal
)
View Source
const (
	FieldTypeString = "string"
	FieldTypeNumber = "number"
	FieldTypeBool   = "bool"
	FieldTypeError  = "error"
	FieldTypeNil    = "nil"
	FieldTypeOther  = "other"
)

Variables

View Source
var (
	// NoColor defines if the output is colorized or not. It's dynamically set to
	// false or true based on the stdout's file descriptor referring to a terminal
	// or not. This is a global option and affects all colors. For more control
	// over each color block use the methods DisableColor() individually.
	NoColor = os.Getenv("TERM") == "dumb" ||
		(!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd()))

	// Output defines the standard output of the print functions. By default
	// os.Stdout is used.
	Output = colorable.NewColorableStdout()

	// Error defines a color supporting writer for os.Stderr.
	Errors = colorable.NewColorableStderr()
)
View Source
var (
	ErrAsyncHandlerPanic   = errors.New("async handler panic")
	ErrAsyncHandlerTimeout = errors.New("async handler timeout")
	ErrAsyncQueueFull      = errors.New("async queue full")
	ErrPendingWriteDropped = errors.New("pending write dropped")
	ErrInvalidLevel        = errors.New("invalid log level")
	ErrRedactionFailed     = errors.New("redaction failed")
)
View Source
var ErrRotatingFileSinkClosed = errors.New("rotating file sink closed")

Functions

func AddRedactRule

func AddRedactRule(rule RedactRule)

func AppendEntryHandler

func AppendEntryHandler(handler Handler)

func ApplyConfig

func ApplyConfig(cfg Config)

func ApplyDevelopmentConfig

func ApplyDevelopmentConfig()

func ApplyKeywordPreset

func ApplyKeywordPreset(preset KeywordPreset)

func ApplyProductionConfig

func ApplyProductionConfig()

func ApplyRotateManageOptions

func ApplyRotateManageOptions(archivePath string, currentPath string, options RotateManageOptions) error

func AsStdlibLogger

func AsStdlibLogger(level int) *log.Logger

func AsStdlibLoggerWithOptions

func AsStdlibLoggerWithOptions(level int, opts ...StdlibBridgeOption) *log.Logger

func AsWriter

func AsWriter(level int) io.Writer

func AsWriterWithOptions

func AsWriterWithOptions(level int, opts ...StdlibBridgeOption) io.Writer

func Black

func Black(format string, a ...interface{})

Black is a convenient helper function to print with black foreground. A newline is appended to format by default.

func BlackString

func BlackString(format string, a ...interface{}) string

BlackString is a convenient helper function to return a string with black foreground.

func Blue

func Blue(format string, a ...interface{})

Blue is a convenient helper function to print with blue foreground. A newline is appended to format by default.

func BlueString

func BlueString(format string, a ...interface{}) string

BlueString is a convenient helper function to return a string with blue foreground.

func ClearFieldValueColors

func ClearFieldValueColors()

func ClearKeywordColors

func ClearKeywordColors()

func ClearRedactRules

func ClearRedactRules()

func Close deprecated

func Close(logger *StarLogger) error

Deprecated: use (*StarLogger).Close or CloseLogFile.

func CloseLogFile

func CloseLogFile(logger *StarLogger) error

func CloseLogFileWithSwitching

func CloseLogFileWithSwitching(logger *StarLogger) error

func CloseStd deprecated

func CloseStd() error

Deprecated: use Shutdown(ctx) for graceful exit.

func CloseWithSwitching deprecated

func CloseWithSwitching(logger *StarLogger) error

Deprecated: use CloseLogFileWithSwitching.

func Critical

func Critical(str ...interface{})

func CriticalContext

func CriticalContext(ctx context.Context, str ...interface{})

func Criticalf

func Criticalf(format string, str ...interface{})

func Criticalln

func Criticalln(str ...interface{})

func Cyan

func Cyan(format string, a ...interface{})

Cyan is a convenient helper function to print with cyan foreground. A newline is appended to format by default.

func CyanString

func CyanString(format string, a ...interface{}) string

CyanString is a convenient helper function to return a string with cyan foreground.

func Debug

func Debug(str ...interface{})

func DebugContext

func DebugContext(ctx context.Context, str ...interface{})

func Debugf

func Debugf(format string, str ...interface{})

func Debugln

func Debugln(str ...interface{})

func EnableDedup

func EnableDedup(enable bool)

func EnableRateLimit

func EnableRateLimit(enable bool)

func EnableSampling

func EnableSampling(enable bool)

func EnableWrite

func EnableWrite()

func EnbaleWrite deprecated

func EnbaleWrite()

Deprecated: use EnableWrite.

func Error

func Error(str ...interface{})

func ErrorContext

func ErrorContext(ctx context.Context, str ...interface{})

func Errorf

func Errorf(format string, str ...interface{})

func Errorln

func Errorln(str ...interface{})

func Exists

func Exists(path string) bool

func Fatal

func Fatal(str ...interface{})

func Fatalf

func Fatalf(format string, str ...interface{})

func Flush

func Flush() error

func GetAsyncDropCount

func GetAsyncDropCount() uint64

func GetAsyncFallbackToSync

func GetAsyncFallbackToSync() bool

func GetAsyncHandlerTimeout

func GetAsyncHandlerTimeout() time.Duration

func GetAutoAppendNewline

func GetAutoAppendNewline() bool

func GetEntryHandlerTimeout

func GetEntryHandlerTimeout() time.Duration

func GetFieldTypeColors

func GetFieldTypeColors() map[string][]Attr

func GetFieldValueColors

func GetFieldValueColors() map[string][]Attr

func GetFileAccessTime

func GetFileAccessTime(fileinfo os.FileInfo) time.Time

func GetFileCreationTime

func GetFileCreationTime(fileinfo os.FileInfo) time.Time

func GetHandler

func GetHandler() func(LogData)

func GetKeywordColors

func GetKeywordColors() map[string][]Attr

func GetKeywordIgnoreCase

func GetKeywordIgnoreCase() bool

func GetKeywordPreset

func GetKeywordPreset(preset KeywordPreset) map[string][]Attr

func GetKeywordWholeWord

func GetKeywordWholeWord() bool

func GetLevel

func GetLevel() int

func GetLogFileInfo

func GetLogFileInfo(logger *StarLogger) (os.FileInfo, error)

func GetPendingBlockCount

func GetPendingBlockCount() uint64

func GetPendingDropCount

func GetPendingDropCount() uint64

func GetPendingPeakLength

func GetPendingPeakLength() int

func GetPendingWriteLimit

func GetPendingWriteLimit() int

func GetRedactErrorCount

func GetRedactErrorCount() uint64

func GetRedactMaskToken

func GetRedactMaskToken() string

func GetRedactRuleCount

func GetRedactRuleCount() int

func GetShowColor

func GetShowColor() bool

func GetShowFieldColor

func GetShowFieldColor() bool

func GetShowFlag

func GetShowFlag() bool

func GetShowFuncName

func GetShowFuncName() bool

func GetShowLevel

func GetShowLevel() bool

func GetShowOriginFile

func GetShowOriginFile() bool

func GetShowStd

func GetShowStd() bool

func GetWriteErrorCount

func GetWriteErrorCount() uint64

func GetWriter

func GetWriter() io.Writer

func Green

func Green(format string, a ...interface{})

Green is a convenient helper function to print with green foreground. A newline is appended to format by default.

func GreenString

func GreenString(format string, a ...interface{}) string

GreenString is a convenient helper function to return a string with green foreground.

func HiBlack

func HiBlack(format string, a ...interface{})

HiBlack is a convenient helper function to print with hi-intensity black foreground. A newline is appended to format by default.

func HiBlackString

func HiBlackString(format string, a ...interface{}) string

HiBlackString is a convenient helper function to return a string with hi-intensity black foreground.

func HiBlue

func HiBlue(format string, a ...interface{})

HiBlue is a convenient helper function to print with hi-intensity blue foreground. A newline is appended to format by default.

func HiBlueString

func HiBlueString(format string, a ...interface{}) string

HiBlueString is a convenient helper function to return a string with hi-intensity blue foreground.

func HiCyan

func HiCyan(format string, a ...interface{})

HiCyan is a convenient helper function to print with hi-intensity cyan foreground. A newline is appended to format by default.

func HiCyanString

func HiCyanString(format string, a ...interface{}) string

HiCyanString is a convenient helper function to return a string with hi-intensity cyan foreground.

func HiGreen

func HiGreen(format string, a ...interface{})

HiGreen is a convenient helper function to print with hi-intensity green foreground. A newline is appended to format by default.

func HiGreenString

func HiGreenString(format string, a ...interface{}) string

HiGreenString is a convenient helper function to return a string with hi-intensity green foreground.

func HiMagenta

func HiMagenta(format string, a ...interface{})

HiMagenta is a convenient helper function to print with hi-intensity magenta foreground. A newline is appended to format by default.

func HiMagentaString

func HiMagentaString(format string, a ...interface{}) string

HiMagentaString is a convenient helper function to return a string with hi-intensity magenta foreground.

func HiRed

func HiRed(format string, a ...interface{})

HiRed is a convenient helper function to print with hi-intensity red foreground. A newline is appended to format by default.

func HiRedString

func HiRedString(format string, a ...interface{}) string

HiRedString is a convenient helper function to return a string with hi-intensity red foreground.

func HiWhite

func HiWhite(format string, a ...interface{})

HiWhite is a convenient helper function to print with hi-intensity white foreground. A newline is appended to format by default.

func HiWhiteString

func HiWhiteString(format string, a ...interface{}) string

HiWhiteString is a convenient helper function to return a string with hi-intensity white foreground.

func HiYellow

func HiYellow(format string, a ...interface{})

HiYellow is a convenient helper function to print with hi-intensity yellow foreground. A newline is appended to format by default.

func HiYellowString

func HiYellowString(format string, a ...interface{}) string

HiYellowString is a convenient helper function to return a string with hi-intensity yellow foreground.

func Info

func Info(str ...interface{})

func InfoContext

func InfoContext(ctx context.Context, str ...interface{})

func Infof

func Infof(format string, str ...interface{})

func Infoln

func Infoln(str ...interface{})

func IsArchiveRun

func IsArchiveRun(logger *StarLogger) bool

func IsFile

func IsFile(path string) bool

func IsFolder

func IsFolder(path string) bool

func IsLevelEnabled

func IsLevelEnabled(level int) bool

func IsWriteStoed deprecated

func IsWriteStoed() bool

Deprecated: use IsWriteStopped.

func IsWriteStopped

func IsWriteStopped() bool

func Log

func Log(isShow bool, level int, str ...interface{})

func LogContext

func LogContext(ctx context.Context, isShow bool, level int, str ...interface{})

func Logf

func Logf(isShow bool, level int, format string, str ...interface{})

func Logln

func Logln(isShow bool, level int, str ...interface{})

func Magenta

func Magenta(format string, a ...interface{})

Magenta is a convenient helper function to print with magenta foreground. A newline is appended to format by default.

func MagentaString

func MagentaString(format string, a ...interface{}) string

MagentaString is a convenient helper function to return a string with magenta foreground.

func MergeKeywordPreset

func MergeKeywordPreset(preset KeywordPreset)

func NewLevelWriterBridge

func NewLevelWriterBridge(logger *StarLogger, level int) io.Writer

func NewStdlibLogger

func NewStdlibLogger(logger *StarLogger, level int) *log.Logger

func NewStdlibLoggerWithOptions

func NewStdlibLoggerWithOptions(logger *StarLogger, level int, opts ...StdlibBridgeOption) *log.Logger

func Notice

func Notice(str ...interface{})

func NoticeContext

func NoticeContext(ctx context.Context, str ...interface{})

func Noticef

func Noticef(format string, str ...interface{})

func Noticeln

func Noticeln(str ...interface{})

func Panicln

func Panicln(str ...interface{})

func ParseLevel

func ParseLevel(level string) (int, error)

func Print

func Print(str ...interface{})

func Printf

func Printf(format string, str ...interface{})

func Println

func Println(str ...interface{})

func Red

func Red(format string, a ...interface{})

Red is a convenient helper function to print with red foreground. A newline is appended to format by default.

func RedString

func RedString(format string, a ...interface{}) string

RedString is a convenient helper function to return a string with red foreground.

func RemoveFieldValueColor

func RemoveFieldValueColor(field string)

func RemoveKeywordColor

func RemoveKeywordColor(keyword string)

func ResetDedupStats

func ResetDedupStats()

func ResetRateLimitStats

func ResetRateLimitStats()

func ResetSamplingStats

func ResetSamplingStats()

func SetAsyncErrorHandler

func SetAsyncErrorHandler(alert func(error, LogData))

func SetAsyncFallbackToSync

func SetAsyncFallbackToSync(enable bool)

func SetAsyncHandlerTimeout

func SetAsyncHandlerTimeout(timeout time.Duration)

func SetAutoAppendNewline

func SetAutoAppendNewline(enable bool)

func SetColorMode

func SetColorMode(mode ColorMode)

func SetContextFieldExtractor

func SetContextFieldExtractor(extractor func(context.Context) Fields)

func SetDedupConfig

func SetDedupConfig(cfg DedupConfig)

func SetDedupDropHandler

func SetDedupDropHandler(handler func(DedupDropData))

func SetEntryHandler

func SetEntryHandler(handler Handler)

func SetEntryHandlerTimeout

func SetEntryHandlerTimeout(timeout time.Duration)

func SetFieldKeyColor

func SetFieldKeyColor(color []Attr)

func SetFieldTypeColor

func SetFieldTypeColor(fieldType string, color []Attr)

func SetFieldValueColor

func SetFieldValueColor(field string, color []Attr)

func SetFormatter

func SetFormatter(formatter Formatter)

func SetHandler

func SetHandler(f func(LogData))

func SetKeywordColor

func SetKeywordColor(keyword string, color []Attr)

func SetKeywordColors

func SetKeywordColors(colors map[string][]Attr)

func SetKeywordIgnoreCase

func SetKeywordIgnoreCase(enable bool)

func SetKeywordMatchOptions

func SetKeywordMatchOptions(opts KeywordMatchOptions)

func SetKeywordWholeWord

func SetKeywordWholeWord(enable bool)

func SetLevel

func SetLevel(level int)

func SetLevelColor

func SetLevelColor(level int, color []Attr)

func SetLogFile

func SetLogFile(path string, logger *StarLogger, appendMode bool) error

func SetPendingDropPolicy

func SetPendingDropPolicy(policy PendingDropPolicy)

func SetPendingWriteLimit

func SetPendingWriteLimit(limit int)

func SetRateLimitConfig

func SetRateLimitConfig(cfg RateLimitConfig)

func SetRateLimitDropHandler

func SetRateLimitDropHandler(handler func(RateLimitDropData))

func SetRedactFailMode

func SetRedactFailMode(mode RedactFailMode)

func SetRedactMaskToken

func SetRedactMaskToken(mask string)

func SetRedactRules

func SetRedactRules(rules []RedactRule)

func SetRedactor

func SetRedactor(redactor Redactor)

func SetSamplingConfig

func SetSamplingConfig(cfg SamplingConfig)

func SetSamplingDropHandler

func SetSamplingDropHandler(handler func(SamplingDropData))

func SetShowColor

func SetShowColor(val bool)

func SetShowFieldColor

func SetShowFieldColor(show bool)

func SetShowFlag

func SetShowFlag(val bool)

func SetShowFuncName

func SetShowFuncName(val bool)

func SetShowLevel

func SetShowLevel(val bool)

func SetShowOriginFile

func SetShowOriginFile(val bool)

func SetShowStd

func SetShowStd(val bool)

func SetSink

func SetSink(sink Sink)

func SetSinks

func SetSinks(sinks ...Sink)

func SetSwitching

func SetSwitching(sw bool)

func SetWriteErrorHandler

func SetWriteErrorHandler(alert func(error, LogData))

func SetWriter

func SetWriter(wr io.Writer)

func Shutdown

func Shutdown(ctx context.Context) error

Shutdown gracefully drains async handlers and closes Std resources.

func ShutdownStd

func ShutdownStd(ctx context.Context) error

func StartArchive deprecated

func StartArchive(logger *StarLogger, arch Archive) error

Deprecated: prefer StartRotatePolicy or StartManagedRotatePolicy.

func StartManagedRotateBySize

func StartManagedRotateBySize(logger *StarLogger, maxSizeBytes int64, checkInterval int64, options RotateManageOptions) error

func StartManagedRotateByTime

func StartManagedRotateByTime(logger *StarLogger, interval time.Duration, checkInterval int64, options RotateManageOptions) error

func StartManagedRotateByTimeSize

func StartManagedRotateByTimeSize(logger *StarLogger, interval time.Duration, maxSizeBytes int64, checkInterval int64, options RotateManageOptions) error

func StartManagedRotatePolicy

func StartManagedRotatePolicy(logger *StarLogger, policy RotatePolicy, checkInterval int64, options RotateManageOptions) error

func StartRotateBySize

func StartRotateBySize(logger *StarLogger, maxSizeBytes int64, checkInterval int64) error

func StartRotateByTime

func StartRotateByTime(logger *StarLogger, interval time.Duration, checkInterval int64) error

func StartRotateByTimeSize

func StartRotateByTimeSize(logger *StarLogger, interval time.Duration, maxSizeBytes int64, checkInterval int64) error

func StartRotatePolicy

func StartRotatePolicy(logger *StarLogger, policy RotatePolicy, checkInterval int64) error

func StartStacks

func StartStacks()

func StdPrint

func StdPrint(attr []Attr, str ...interface{})

func StdPrintf

func StdPrintf(attr []Attr, format string, str ...interface{})

func StdPrintln

func StdPrintln(attr []Attr, str ...interface{})

func Stop

func Stop()

func StopArchive

func StopArchive(logger *StarLogger)

func StopStacks

func StopStacks()

func StopWrite

func StopWrite()

func Sync

func Sync() error

func Unset

func Unset()

Unset resets all escape attributes and clears the output. Usually should be called after Set().

func UpdateConfig

func UpdateConfig(update func(*Config))

func WaitAsyncDrain

func WaitAsyncDrain(ctx context.Context) error

func Warning

func Warning(str ...interface{})

func WarningContext

func WarningContext(ctx context.Context, str ...interface{})

func Warningf

func Warningf(format string, str ...interface{})

func Warningln

func Warningln(str ...interface{})

func White

func White(format string, a ...interface{})

White is a convenient helper function to print with white foreground. A newline is appended to format by default.

func WhiteString

func WhiteString(format string, a ...interface{}) string

WhiteString is a convenient helper function to return a string with white foreground.

func Yellow

func Yellow(format string, a ...interface{})

Yellow is a convenient helper function to print with yellow foreground. A newline is appended to format by default.

func YellowString

func YellowString(format string, a ...interface{}) string

YellowString is a convenient helper function to return a string with yellow foreground.

Types

type Archive

type Archive interface {
	ShouldArchiveNow(*StarLogger, string, os.FileInfo) bool
	NextLogFilePath(*StarLogger, string, os.FileInfo) string
	ArchiveLogFilePath(*StarLogger, string, os.FileInfo) string
	Interval() int64
	// Deprecated: use HookBeforeArchive on concrete implementations.
	HookBeforArchive() func(*StarLogger, string, string, os.FileInfo) error //archivePath;currentPath
	HookAfterArchive() func(*StarLogger, string, string, os.FileInfo) error //archivePath;currentPath
	DoArchive() func(*StarLogger, string, string, os.FileInfo) error
}

type ArchiveByDate

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

func NewArchiveByDate

func NewArchiveByDate(archInterval int64, checkInterval int64, baseFileName string, archiveFileName string, changeArchiveName bool, hookbefore func(*StarLogger, string, string, os.FileInfo) error, hookafter func(*StarLogger, string, string, os.FileInfo) error) *ArchiveByDate

func (*ArchiveByDate) ArchiveLogFilePath

func (abd *ArchiveByDate) ArchiveLogFilePath(l *StarLogger, oldpath string, info os.FileInfo) string

func (*ArchiveByDate) DoArchive

func (abd *ArchiveByDate) DoArchive() func(*StarLogger, string, string, os.FileInfo) error

func (*ArchiveByDate) HookAfterArchive

func (abd *ArchiveByDate) HookAfterArchive() func(*StarLogger, string, string, os.FileInfo) error

func (*ArchiveByDate) HookBeforArchive

func (abd *ArchiveByDate) HookBeforArchive() func(*StarLogger, string, string, os.FileInfo) error

func (*ArchiveByDate) HookBeforeArchive

func (abd *ArchiveByDate) HookBeforeArchive() func(*StarLogger, string, string, os.FileInfo) error

func (*ArchiveByDate) Interval

func (abd *ArchiveByDate) Interval() int64

func (*ArchiveByDate) NextLogFilePath

func (abd *ArchiveByDate) NextLogFilePath(l *StarLogger, oldpath string, info os.FileInfo) string

func (*ArchiveByDate) SetHookAfterArchive

func (abd *ArchiveByDate) SetHookAfterArchive(f func(*StarLogger, string, string, os.FileInfo) error)

func (*ArchiveByDate) SetHookBeforArchive

func (abd *ArchiveByDate) SetHookBeforArchive(f func(*StarLogger, string, string, os.FileInfo) error)

func (*ArchiveByDate) SetHookBeforeArchive

func (abd *ArchiveByDate) SetHookBeforeArchive(f func(*StarLogger, string, string, os.FileInfo) error)

func (*ArchiveByDate) ShouldArchiveNow

func (abd *ArchiveByDate) ShouldArchiveNow(l *StarLogger, fullpath string, info os.FileInfo) bool

type ArchiveByDateSize

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

func NewArchiveByDateSize

func NewArchiveByDateSize(size int64, interval int64, checkInterval int64, baseFileStyle, archiveFileStyle string, changeArchiveFileName bool, hookbefore func(*StarLogger, string, string, os.FileInfo) error, hookafter func(*StarLogger, string, string, os.FileInfo) error) *ArchiveByDateSize

func (*ArchiveByDateSize) ArchiveLogFilePath

func (abd *ArchiveByDateSize) ArchiveLogFilePath(l *StarLogger, oldpath string, info os.FileInfo) string

func (*ArchiveByDateSize) DoArchive

func (abd *ArchiveByDateSize) DoArchive() func(*StarLogger, string, string, os.FileInfo) error

func (*ArchiveByDateSize) HookAfterArchive

func (abd *ArchiveByDateSize) HookAfterArchive() func(*StarLogger, string, string, os.FileInfo) error

func (*ArchiveByDateSize) HookBeforArchive

func (abd *ArchiveByDateSize) HookBeforArchive() func(*StarLogger, string, string, os.FileInfo) error

func (*ArchiveByDateSize) HookBeforeArchive

func (abd *ArchiveByDateSize) HookBeforeArchive() func(*StarLogger, string, string, os.FileInfo) error

func (*ArchiveByDateSize) Interval

func (abd *ArchiveByDateSize) Interval() int64

func (*ArchiveByDateSize) NextLogFilePath

func (abd *ArchiveByDateSize) NextLogFilePath(l *StarLogger, oldpath string, info os.FileInfo) string

func (*ArchiveByDateSize) SetHookAfterArchive

func (abd *ArchiveByDateSize) SetHookAfterArchive(f func(*StarLogger, string, string, os.FileInfo) error)

func (*ArchiveByDateSize) SetHookBeforArchive

func (abd *ArchiveByDateSize) SetHookBeforArchive(f func(*StarLogger, string, string, os.FileInfo) error)

func (*ArchiveByDateSize) SetHookBeforeArchive

func (abd *ArchiveByDateSize) SetHookBeforeArchive(f func(*StarLogger, string, string, os.FileInfo) error)

func (*ArchiveByDateSize) ShouldArchiveNow

func (abd *ArchiveByDateSize) ShouldArchiveNow(l *StarLogger, fullpath string, info os.FileInfo) bool

type ArchiveBySize

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

func NewArchiveBySize

func NewArchiveBySize(size int64, checkInterval int64, baseFileStyle, archiveFileStyle string, changeArchiveFileName bool, hookbefore func(*StarLogger, string, string, os.FileInfo) error, hookafter func(*StarLogger, string, string, os.FileInfo) error) *ArchiveBySize

func (*ArchiveBySize) ArchiveLogFilePath

func (abd *ArchiveBySize) ArchiveLogFilePath(l *StarLogger, oldpath string, info os.FileInfo) string

func (*ArchiveBySize) DoArchive

func (abd *ArchiveBySize) DoArchive() func(*StarLogger, string, string, os.FileInfo) error

func (*ArchiveBySize) HookAfterArchive

func (abd *ArchiveBySize) HookAfterArchive() func(*StarLogger, string, string, os.FileInfo) error

func (*ArchiveBySize) HookBeforArchive

func (abd *ArchiveBySize) HookBeforArchive() func(*StarLogger, string, string, os.FileInfo) error

func (*ArchiveBySize) HookBeforeArchive

func (abd *ArchiveBySize) HookBeforeArchive() func(*StarLogger, string, string, os.FileInfo) error

func (*ArchiveBySize) Interval

func (abd *ArchiveBySize) Interval() int64

func (*ArchiveBySize) NextLogFilePath

func (abd *ArchiveBySize) NextLogFilePath(l *StarLogger, oldpath string, info os.FileInfo) string

func (*ArchiveBySize) SetHookAfterArchive

func (abd *ArchiveBySize) SetHookAfterArchive(f func(*StarLogger, string, string, os.FileInfo) error)

func (*ArchiveBySize) SetHookBeforArchive

func (abd *ArchiveBySize) SetHookBeforArchive(f func(*StarLogger, string, string, os.FileInfo) error)

func (*ArchiveBySize) SetHookBeforeArchive

func (abd *ArchiveBySize) SetHookBeforeArchive(f func(*StarLogger, string, string, os.FileInfo) error)

func (*ArchiveBySize) ShouldArchiveNow

func (abd *ArchiveBySize) ShouldArchiveNow(l *StarLogger, fullpath string, info os.FileInfo) bool

type AsyncMetrics

type AsyncMetrics struct {
	Started        bool
	QueueLength    uint64
	QueueCapacity  uint64
	QueueFree      uint64
	Dropped        uint64
	FallbackToSync bool
	HandlerTimeout time.Duration
}

func GetAsyncMetrics

func GetAsyncMetrics() AsyncMetrics

type Attr

type Attr int

Attr defines a single SGR Code

const (
	Reset Attr = iota
	Bold
	Faint
	Italic
	Underline
	BlinkSlow
	BlinkRapid
	ReverseVideo
	Concealed
	CrossedOut
)

Base attributes

const (
	FgBlack Attr = iota + 30
	FgRed
	FgGreen
	FgYellow
	FgBlue
	FgMagenta
	FgCyan
	FgWhite
)

Foreground text colors

const (
	FgHiBlack Attr = iota + 90
	FgHiRed
	FgHiGreen
	FgHiYellow
	FgHiBlue
	FgHiMagenta
	FgHiCyan
	FgHiWhite
)

Foreground Hi-Intensity text colors

const (
	BgBlack Attr = iota + 40
	BgRed
	BgGreen
	BgYellow
	BgBlue
	BgMagenta
	BgCyan
	BgWhite
)

Background text colors

const (
	BgHiBlack Attr = iota + 100
	BgHiRed
	BgHiGreen
	BgHiYellow
	BgHiBlue
	BgHiMagenta
	BgHiCyan
	BgHiWhite
)

Background Hi-Intensity text colors

func GetFieldKeyColor

func GetFieldKeyColor() []Attr

func GetLevelColor

func GetLevelColor(level int) []Attr

type Color

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

Color defines a custom color object which is defined by SGR parameters.

func NewColor

func NewColor(value ...Attr) *Color

New returns a newly created color object.

func Set

func Set(p ...Attr) *Color

Set sets the given parameters immediately. It will change the color of output with the given SGR parameters until color.Unset() is called.

func (*Color) Add

func (c *Color) Add(value ...Attr) *Color

Add is used to chain SGR parameters. Use as many as parameters to combine and create custom color objects. Example: Add(color.FgRed, color.Underline).

func (*Color) DisableColor

func (c *Color) DisableColor()

DisableColor disables the color output. Useful to not change any existing code and still being able to output. Can be used for flags like "--no-color". To enable back use EnableColor() method.

func (*Color) EnableColor

func (c *Color) EnableColor()

EnableColor enables the color output. Use it in conjunction with DisableColor(). Otherwise this method has no side effects.

func (*Color) Equals

func (c *Color) Equals(c2 *Color) bool

Equals returns a boolean value indicating whether two colors are equal.

func (*Color) Fprint

func (c *Color) Fprint(w io.Writer, a ...interface{}) (n int, err error)

Fprint formats using the default formats for its operands and writes to w. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered. On Windows, users should wrap w with colorable.NewColorable() if w is of type *os.File.

func (*Color) FprintFunc

func (c *Color) FprintFunc() func(w io.Writer, a ...interface{})

FprintFunc returns a new function that prints the passed arguments as colorized with color.Fprint().

func (*Color) Fprintf

func (c *Color) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)

Fprintf formats according to a format specifier and writes to w. It returns the number of bytes written and any write error encountered. On Windows, users should wrap w with colorable.NewColorable() if w is of type *os.File.

func (*Color) FprintfFunc

func (c *Color) FprintfFunc() func(w io.Writer, format string, a ...interface{})

FprintfFunc returns a new function that prints the passed arguments as colorized with color.Fprintf().

func (*Color) Fprintln

func (c *Color) Fprintln(w io.Writer, a ...interface{}) (n int, err error)

Fprintln formats using the default formats for its operands and writes to w. Spaces are always added between operands and a newline is appended. On Windows, users should wrap w with colorable.NewColorable() if w is of type *os.File.

func (*Color) FprintlnFunc

func (c *Color) FprintlnFunc() func(w io.Writer, a ...interface{})

FprintlnFunc returns a new function that prints the passed arguments as colorized with color.Fprintln().

func (*Color) Print

func (c *Color) Print(a ...interface{}) (n int, err error)

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered. This is the standard fmt.Print() method wrapped with the given color.

func (*Color) PrintFunc

func (c *Color) PrintFunc() func(a ...interface{})

PrintFunc returns a new function that prints the passed arguments as colorized with color.Print().

func (*Color) Printf

func (c *Color) Printf(format string, a ...interface{}) (n int, err error)

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered. This is the standard fmt.Printf() method wrapped with the given color.

func (*Color) PrintfFunc

func (c *Color) PrintfFunc() func(format string, a ...interface{})

PrintfFunc returns a new function that prints the passed arguments as colorized with color.Printf().

func (*Color) Println

func (c *Color) Println(a ...interface{}) (n int, err error)

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered. This is the standard fmt.Print() method wrapped with the given color.

func (*Color) PrintlnFunc

func (c *Color) PrintlnFunc() func(a ...interface{})

PrintlnFunc returns a new function that prints the passed arguments as colorized with color.Println().

func (*Color) Set

func (c *Color) Set() *Color

Set sets the SGR sequence.

func (*Color) Sprint

func (c *Color) Sprint(a ...interface{}) string

Sprint is just like Print, but returns a string instead of printing it.

func (*Color) SprintFunc

func (c *Color) SprintFunc() func(a ...interface{}) string

SprintFunc returns a new function that returns colorized strings for the given arguments with fmt.Sprint(). Useful to put into or mix into other string. Windows users should use this in conjunction with color.Output, example:

put := New(FgYellow).SprintFunc()
fmt.Fprintf(color.Output, "This is a %s", put("warning"))

func (*Color) Sprintf

func (c *Color) Sprintf(format string, a ...interface{}) string

Sprintf is just like Printf, but returns a string instead of printing it.

func (*Color) SprintfFunc

func (c *Color) SprintfFunc() func(format string, a ...interface{}) string

SprintfFunc returns a new function that returns colorized strings for the given arguments with fmt.Sprintf(). Useful to put into or mix into other string. Windows users should use this in conjunction with color.Output.

func (*Color) Sprintln

func (c *Color) Sprintln(a ...interface{}) string

Sprintln is just like Println, but returns a string instead of printing it.

func (*Color) SprintlnFunc

func (c *Color) SprintlnFunc() func(a ...interface{}) string

SprintlnFunc returns a new function that returns colorized strings for the given arguments with fmt.Sprintln(). Useful to put into or mix into other string. Windows users should use this in conjunction with color.Output.

type ColorMode

type ColorMode int
const (
	ColorModeOff ColorMode = iota
	ColorModeFullLine
	ColorModeLevelOnly
)

func GetColorMode

func GetColorMode() ColorMode

type Config

type Config struct {
	Name              string
	Level             int
	StdErrLevel       int
	ShowFuncName      bool
	ShowFlag          bool
	ShowLevel         bool
	ShowOriginFile    bool
	ShowColor         bool
	OnlyColorLevel    bool
	ShowStd           bool
	StopWriter        bool
	AutoAppendNewline bool
	Switching         bool
	LevelColors       map[int][]Attr
	KeywordColors     map[string][]Attr
	KeywordMatch      KeywordMatchOptions
	ShowFieldColor    bool
	FieldKeyColor     []Attr
	FieldTypeColors   map[string][]Attr
	FieldValueColors  map[string][]Attr

	EntryHandler        Handler
	EntryHandlerTimeout time.Duration
	Formatter           Formatter
	Sink                Sink
	Writer              io.Writer

	PendingWriteLimit int
	PendingDropPolicy PendingDropPolicy

	Redactor        Redactor
	RedactRules     []RedactRule
	RedactFailMode  RedactFailMode
	RedactMaskToken string

	RateLimit RateLimitConfig
	Sampling  SamplingConfig
	Dedup     DedupConfig

	ContextFieldExtractor func(context.Context) Fields
}

Config is a logger core snapshot that can be read and applied atomically. Prefer GetConfig + UpdateConfig/ApplyConfig for multi-field configuration.

func DefaultConfig

func DefaultConfig() Config

func GetConfig

func GetConfig() Config

func NewDevelopmentConfig

func NewDevelopmentConfig() Config

func NewProductionConfig

func NewProductionConfig() Config

type DedupConfig

type DedupConfig struct {
	Enable bool

	Levels []int
	Window time.Duration
	Scope  DedupScope

	KeyFunc func(*Entry) string
	MaxKeys int
	KeyTTL  time.Duration

	OnDrop func(DedupDropData)
}

func DefaultDedupConfig

func DefaultDedupConfig() DedupConfig

func GetDedupConfig

func GetDedupConfig() DedupConfig

type DedupDropData

type DedupDropData struct {
	Time        time.Time
	Key         string
	Reason      string
	Level       int
	LevelName   string
	LoggerName  string
	Message     string
	Window      time.Duration
	Allowed     uint64
	Dropped     uint64
	CurrentKeys int
}

type DedupScope

type DedupScope int
const (
	DedupScopeGlobal DedupScope = iota
	DedupScopeByKey
)

type DedupStats

type DedupStats struct {
	Enabled      bool
	Window       time.Duration
	Scope        DedupScope
	Allowed      uint64
	Dropped      uint64
	LastDropTime time.Time
	LastDropKey  string
	LastReason   string
	CurrentKeys  int
}

func GetDedupStats

func GetDedupStats() DedupStats

type Entry

type Entry struct {
	Time       time.Time
	Level      int
	LevelName  string
	LoggerName string
	Thread     string
	File       string
	Line       int
	Func       string
	Message    string
	Fields     Fields
	Err        error
	Context    context.Context
}

type ErrorMetrics

type ErrorMetrics struct {
	WriteErrors     uint64
	RedactionErrors uint64
}

type Fields

type Fields map[string]interface{}

type FileInfo

type FileInfo = os.FileInfo

type Formatter

type Formatter interface {
	Format(*Entry) ([]byte, error)
}

func GetFormatter

func GetFormatter() Formatter

type Handler

type Handler interface {
	Handle(context.Context, *Entry) error
}

func ChainHandler

func ChainHandler(handlers ...Handler) Handler

func GetEntryHandler

func GetEntryHandler() Handler

func NewChainHandler

func NewChainHandler(handlers ...Handler) Handler

type HandlerFunc

type HandlerFunc func(context.Context, *Entry) error

func (HandlerFunc) Handle

func (f HandlerFunc) Handle(ctx context.Context, entry *Entry) error

type JSONFormatter

type JSONFormatter struct {
	Pretty bool
}

func NewJSONFormatter

func NewJSONFormatter() *JSONFormatter

func (*JSONFormatter) Format

func (formatter *JSONFormatter) Format(entry *Entry) ([]byte, error)

type KeywordMatchOptions

type KeywordMatchOptions struct {
	IgnoreCase bool
	WholeWord  bool
}

func GetKeywordMatchOptions

func GetKeywordMatchOptions() KeywordMatchOptions

type KeywordPreset

type KeywordPreset string
const (
	KeywordPresetMobaLite KeywordPreset = "moba-lite"
	KeywordPresetMobaFull KeywordPreset = "moba-full"
)

type LevelMatcher

type LevelMatcher = routerx.Matcher

func MatchAllLevels

func MatchAllLevels() LevelMatcher

func MatchAtLeast

func MatchAtLeast(minLevel int) LevelMatcher

func MatchLevels

func MatchLevels(levels ...int) LevelMatcher

type LevelWriter

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

func NewLevelWriter

func NewLevelWriter(logger *StarLogger, level int) *LevelWriter

func NewLevelWriterWithOptions

func NewLevelWriterWithOptions(logger *StarLogger, level int, opts ...StdlibBridgeOption) *LevelWriter

func (*LevelWriter) SetShowStd

func (writer *LevelWriter) SetShowStd(show bool)

func (*LevelWriter) SetTrimNewline

func (writer *LevelWriter) SetTrimNewline(trim bool)

func (*LevelWriter) Write

func (writer *LevelWriter) Write(data []byte) (int, error)

type LogData

type LogData struct {
	Name   string
	Log    string
	Colors []Attr
}

type MessageRegexRule

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

func NewMessageRegexRule

func NewMessageRegexRule(pattern *regexp.Regexp, replacement string) *MessageRegexRule

func (*MessageRegexRule) Apply

func (rule *MessageRegexRule) Apply(ctx context.Context, entry *Entry) (bool, error)

type MetricsSnapshot

type MetricsSnapshot struct {
	Time           time.Time
	LoggerName     string
	Level          int
	HasWriter      bool
	HasSink        bool
	HasMultiSink   bool
	ArchiveRunning bool
	Pending        PendingStats
	Sampling       SamplingStats
	Dedup          DedupStats
	RateLimit      RateLimitStats
	Async          AsyncMetrics
	Errors         ErrorMetrics
	MultiSink      MultiSinkStats
}

func GetMetricsSnapshot

func GetMetricsSnapshot() MetricsSnapshot

type MultiSink

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

func NewMultiSink

func NewMultiSink(sinks ...Sink) *MultiSink

func (*MultiSink) AddSink

func (sink *MultiSink) AddSink(item Sink)

func (*MultiSink) Close

func (sink *MultiSink) Close() error

func (*MultiSink) ContinueOnError

func (sink *MultiSink) ContinueOnError() bool

func (*MultiSink) GetStats

func (sink *MultiSink) GetStats() MultiSinkStats

func (*MultiSink) ResetStats

func (sink *MultiSink) ResetStats()

func (*MultiSink) SetContinueOnError

func (sink *MultiSink) SetContinueOnError(continueOnError bool)

func (*MultiSink) SetSinks

func (sink *MultiSink) SetSinks(sinks ...Sink)

func (*MultiSink) SinkCount

func (sink *MultiSink) SinkCount() int

func (*MultiSink) Write

func (sink *MultiSink) Write(data []byte) error

type MultiSinkStats

type MultiSinkStats struct {
	ContinueOnError bool
	Sinks           []SinkStats
}

type Observer

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

func NewObserver

func NewObserver() *Observer

func NewObserverWithLimit

func NewObserverWithLimit(limit int) *Observer

func (*Observer) Count

func (observer *Observer) Count() int

func (*Observer) Dropped

func (observer *Observer) Dropped() uint64

func (*Observer) Entries

func (observer *Observer) Entries() []Entry

func (*Observer) Handle

func (observer *Observer) Handle(ctx context.Context, entry *Entry) error

func (*Observer) Last

func (observer *Observer) Last() (Entry, bool)

func (*Observer) Limit

func (observer *Observer) Limit() int

func (*Observer) Reset

func (observer *Observer) Reset()

func (*Observer) SetLimit

func (observer *Observer) SetLimit(limit int)

func (*Observer) TakeAll

func (observer *Observer) TakeAll() []Entry

type PendingDropPolicy

type PendingDropPolicy int
const (
	PendingDropOldest PendingDropPolicy = iota
	PendingDropNewest
	PendingBlock
)

func GetPendingDropPolicy

func GetPendingDropPolicy() PendingDropPolicy

type PendingStats

type PendingStats struct {
	Limit      int
	Length     int
	PeakLength int
	DropCount  uint64
	BlockCount uint64
	Policy     PendingDropPolicy
	Switching  bool
}

func GetPendingStats

func GetPendingStats() PendingStats

type RateLimitConfig

type RateLimitConfig struct {
	Enable bool

	Levels        []int
	Rate          float64
	Burst         int
	Scope         RateLimitScope
	KeyFunc       func(*Entry) string
	MaxKeys       int
	KeyTTL        time.Duration
	DropPolicy    RateLimitDropPolicy
	OnDrop        func(RateLimitDropData)
	ExemptLevels  []int
	ExemptMatcher func(*Entry) bool

	SummaryInterval time.Duration
}

func DefaultRateLimitConfig

func DefaultRateLimitConfig() RateLimitConfig

func GetRateLimitConfig

func GetRateLimitConfig() RateLimitConfig

type RateLimitDropData

type RateLimitDropData struct {
	Time               time.Time
	Key                string
	Reason             string
	Level              int
	LevelName          string
	LoggerName         string
	Message            string
	PassThrough        bool
	DroppedCount       uint64
	PassedThroughCount uint64
	Suppressed         uint64
	Summary            bool
	SummarySuppressed  uint64
}

type RateLimitDropPolicy

type RateLimitDropPolicy int
const (
	RateLimitDrop RateLimitDropPolicy = iota
	RateLimitPassThrough
)

type RateLimitScope

type RateLimitScope int
const (
	RateLimitScopeGlobal RateLimitScope = iota
	RateLimitScopeByKey
)

type RateLimitStats

type RateLimitStats struct {
	Enabled       bool
	Rate          float64
	Burst         int
	Scope         RateLimitScope
	Allowed       uint64
	Dropped       uint64
	PassedThrough uint64
	Suppressed    uint64
	Summaries     uint64
	LastDropTime  time.Time
	LastDropKey   string
	LastReason    string
	CurrentKeys   int
}

func GetRateLimitStats

func GetRateLimitStats() RateLimitStats

type RedactFailMode

type RedactFailMode int
const (
	RedactFailMaskAll RedactFailMode = iota
	RedactFailOpen
	RedactFailDrop
)

func GetRedactFailMode

func GetRedactFailMode() RedactFailMode

type RedactRule

type RedactRule interface {
	Apply(context.Context, *Entry) (bool, error)
}

type RedactRuleFunc

type RedactRuleFunc func(context.Context, *Entry) (bool, error)

func (RedactRuleFunc) Apply

func (f RedactRuleFunc) Apply(ctx context.Context, entry *Entry) (bool, error)

type Redactor

type Redactor interface {
	Redact(context.Context, *Entry) error
}

func GetRedactor

func GetRedactor() Redactor

type RedactorFunc

type RedactorFunc func(context.Context, *Entry) error

func (RedactorFunc) Redact

func (f RedactorFunc) Redact(ctx context.Context, entry *Entry) error

type RotateArchivePathProvider

type RotateArchivePathProvider interface {
	ArchivePath(string, time.Time) string
}

RotateArchivePathProvider is an optional extension for RotatePolicy. If implemented, ArchivePath is preferred over NextPath when resolving the archived file destination path.

type RotateBySizePolicy

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

func NewRotateBySizePolicy

func NewRotateBySizePolicy(maxSizeBytes int64) *RotateBySizePolicy

func NewRotateBySizePolicyWithPattern

func NewRotateBySizePolicyWithPattern(maxSizeBytes int64, pattern string) *RotateBySizePolicy

func (*RotateBySizePolicy) NextPath

func (policy *RotateBySizePolicy) NextPath(current string, now time.Time) string

func (*RotateBySizePolicy) ShouldRotate

func (policy *RotateBySizePolicy) ShouldRotate(info FileInfo, entry *Entry) bool

type RotateByTimePolicy

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

func NewRotateByTimePolicy

func NewRotateByTimePolicy(interval time.Duration) *RotateByTimePolicy

func NewRotateByTimePolicyWithPattern

func NewRotateByTimePolicyWithPattern(interval time.Duration, pattern string) *RotateByTimePolicy

func (*RotateByTimePolicy) NextPath

func (policy *RotateByTimePolicy) NextPath(current string, now time.Time) string

func (*RotateByTimePolicy) ShouldRotate

func (policy *RotateByTimePolicy) ShouldRotate(info FileInfo, entry *Entry) bool

type RotateByTimeSizePolicy

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

func NewRotateByTimeSizePolicy

func NewRotateByTimeSizePolicy(interval time.Duration, maxSizeBytes int64) *RotateByTimeSizePolicy

func NewRotateByTimeSizePolicyWithPattern

func NewRotateByTimeSizePolicyWithPattern(interval time.Duration, maxSizeBytes int64, pattern string) *RotateByTimeSizePolicy

func (*RotateByTimeSizePolicy) NextPath

func (policy *RotateByTimeSizePolicy) NextPath(current string, now time.Time) string

func (*RotateByTimeSizePolicy) ShouldRotate

func (policy *RotateByTimeSizePolicy) ShouldRotate(info FileInfo, entry *Entry) bool

type RotateManageOptions

type RotateManageOptions struct {
	MaxBackups int
	MaxAge     time.Duration
	Compress   bool
	Pattern    string
}

type RotatePolicy

type RotatePolicy interface {
	ShouldRotate(FileInfo, *Entry) bool
	NextPath(string, time.Time) string
}

type RotatePolicyArchive

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

func NewManagedRotateArchive

func NewManagedRotateArchive(policy RotatePolicy, checkInterval int64, options RotateManageOptions) *RotatePolicyArchive

func NewRotatePolicyArchive

func NewRotatePolicyArchive(policy RotatePolicy, checkInterval int64) *RotatePolicyArchive

func WithRotateManageOptions

func WithRotateManageOptions(archive *RotatePolicyArchive, options RotateManageOptions) *RotatePolicyArchive

func (*RotatePolicyArchive) ArchiveLogFilePath

func (archive *RotatePolicyArchive) ArchiveLogFilePath(logger *StarLogger, oldpath string, info os.FileInfo) string

func (*RotatePolicyArchive) DoArchive

func (archive *RotatePolicyArchive) DoArchive() func(*StarLogger, string, string, os.FileInfo) error

func (*RotatePolicyArchive) HookAfterArchive

func (archive *RotatePolicyArchive) HookAfterArchive() func(*StarLogger, string, string, os.FileInfo) error

func (*RotatePolicyArchive) HookBeforArchive

func (archive *RotatePolicyArchive) HookBeforArchive() func(*StarLogger, string, string, os.FileInfo) error

func (*RotatePolicyArchive) HookBeforeArchive

func (archive *RotatePolicyArchive) HookBeforeArchive() func(*StarLogger, string, string, os.FileInfo) error

func (*RotatePolicyArchive) Interval

func (archive *RotatePolicyArchive) Interval() int64

func (*RotatePolicyArchive) NextLogFilePath

func (archive *RotatePolicyArchive) NextLogFilePath(logger *StarLogger, oldpath string, info os.FileInfo) string

func (*RotatePolicyArchive) SetHookAfterArchive

func (archive *RotatePolicyArchive) SetHookAfterArchive(hook func(*StarLogger, string, string, os.FileInfo) error)

func (*RotatePolicyArchive) SetHookBeforArchive

func (archive *RotatePolicyArchive) SetHookBeforArchive(hook func(*StarLogger, string, string, os.FileInfo) error)

func (*RotatePolicyArchive) SetHookBeforeArchive

func (archive *RotatePolicyArchive) SetHookBeforeArchive(hook func(*StarLogger, string, string, os.FileInfo) error)

func (*RotatePolicyArchive) ShouldArchiveNow

func (archive *RotatePolicyArchive) ShouldArchiveNow(logger *StarLogger, fullpath string, info os.FileInfo) bool

type RotatingFileSink

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

func NewManagedRotateBySizeSink

func NewManagedRotateBySizeSink(path string, appendMode bool, maxSizeBytes int64, checkInterval time.Duration, options RotateManageOptions) (*RotatingFileSink, error)

func NewManagedRotateByTimeSink

func NewManagedRotateByTimeSink(path string, appendMode bool, interval time.Duration, checkInterval time.Duration, options RotateManageOptions) (*RotatingFileSink, error)

func NewManagedRotateByTimeSizeSink

func NewManagedRotateByTimeSizeSink(path string, appendMode bool, interval time.Duration, maxSizeBytes int64, checkInterval time.Duration, options RotateManageOptions) (*RotatingFileSink, error)

func NewManagedRotatePolicySink

func NewManagedRotatePolicySink(path string, appendMode bool, policy RotatePolicy, checkInterval time.Duration, options RotateManageOptions) (*RotatingFileSink, error)

func NewRotateBySizeSink

func NewRotateBySizeSink(path string, appendMode bool, maxSizeBytes int64, checkInterval time.Duration) (*RotatingFileSink, error)

func NewRotateByTimeSink

func NewRotateByTimeSink(path string, appendMode bool, interval time.Duration, checkInterval time.Duration) (*RotatingFileSink, error)

func NewRotateByTimeSizeSink

func NewRotateByTimeSizeSink(path string, appendMode bool, interval time.Duration, maxSizeBytes int64, checkInterval time.Duration) (*RotatingFileSink, error)

func NewRotatePolicySink

func NewRotatePolicySink(path string, appendMode bool, policy RotatePolicy, checkInterval time.Duration) (*RotatingFileSink, error)

func (*RotatingFileSink) Close

func (sink *RotatingFileSink) Close() error

func (*RotatingFileSink) Path

func (sink *RotatingFileSink) Path() string

func (*RotatingFileSink) Sync

func (sink *RotatingFileSink) Sync() error

func (*RotatingFileSink) Write

func (sink *RotatingFileSink) Write(data []byte) error

type Route

type Route struct {
	Name      string
	Match     LevelMatcher
	Formatter Formatter
	Sink      Sink
}

type RouteHandler

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

func NewRouteHandler

func NewRouteHandler(routes ...Route) *RouteHandler

func (*RouteHandler) Close

func (handler *RouteHandler) Close() error

func (*RouteHandler) CloseWithContext added in v1.4.1

func (handler *RouteHandler) CloseWithContext(ctx context.Context) error

func (*RouteHandler) Handle

func (handler *RouteHandler) Handle(ctx context.Context, entry *Entry) error

func (*RouteHandler) ReplaceRoutes

func (handler *RouteHandler) ReplaceRoutes(routes ...Route)

func (*RouteHandler) SetRoutes

func (handler *RouteHandler) SetRoutes(routes []Route)

type RuleRedactor

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

func NewRuleRedactor

func NewRuleRedactor(rules ...RedactRule) *RuleRedactor

func (*RuleRedactor) Redact

func (redactor *RuleRedactor) Redact(ctx context.Context, entry *Entry) error

type SamplingConfig

type SamplingConfig struct {
	Enable bool

	Levels []int
	Rate   float64
	Scope  SamplingScope

	KeyFunc func(*Entry) string
	MaxKeys int
	KeyTTL  time.Duration

	OnDrop func(SamplingDropData)
}

func DefaultSamplingConfig

func DefaultSamplingConfig() SamplingConfig

func GetSamplingConfig

func GetSamplingConfig() SamplingConfig

type SamplingDropData

type SamplingDropData struct {
	Time        time.Time
	Key         string
	Reason      string
	Level       int
	LevelName   string
	LoggerName  string
	Message     string
	Rate        float64
	Allowed     uint64
	Dropped     uint64
	CurrentKeys int
}

type SamplingScope

type SamplingScope int
const (
	SamplingScopeGlobal SamplingScope = iota
	SamplingScopeByKey
)

type SamplingStats

type SamplingStats struct {
	Enabled      bool
	Rate         float64
	Scope        SamplingScope
	Allowed      uint64
	Dropped      uint64
	LastDropTime time.Time
	LastDropKey  string
	LastReason   string
	CurrentKeys  int
}

func GetSamplingStats

func GetSamplingStats() SamplingStats

type SensitiveFieldRule

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

func NewSensitiveFieldRule

func NewSensitiveFieldRule(mask string, fields ...string) *SensitiveFieldRule

func (*SensitiveFieldRule) Apply

func (rule *SensitiveFieldRule) Apply(ctx context.Context, entry *Entry) (bool, error)

type Sink

type Sink interface {
	Write([]byte) error
	Close() error
}

func GetSink

func GetSink() Sink

type SinkState

type SinkState string
const (
	SinkStateHealthy   SinkState = SinkState(multisinkx.StateHealthy)
	SinkStateDegraded  SinkState = SinkState(multisinkx.StateDegraded)
	SinkStateRecovered SinkState = SinkState(multisinkx.StateRecovered)
)

type SinkStats

type SinkStats struct {
	Index                  int
	Writes                 uint64
	WriteErrors            uint64
	Closes                 uint64
	CloseErrors            uint64
	ConsecutiveWriteErrors uint64
	ConsecutiveCloseErrors uint64
	LastWriteError         string
	LastCloseError         string
	State                  SinkState
}

type StarLogger

type StarLogger struct {
	// contains filtered or unexported fields
}
var Std *StarLogger

func NewDevelopment

func NewDevelopment(out io.Writer) *StarLogger

func NewProduction

func NewProduction(out io.Writer) *StarLogger

func NewStarlog

func NewStarlog(out io.Writer) *StarLogger

func WithContext

func WithContext(ctx context.Context) *StarLogger

func WithError

func WithError(err error) *StarLogger

func WithField

func WithField(key string, value interface{}) *StarLogger

func WithFields

func WithFields(fields Fields) *StarLogger

func (*StarLogger) AddRedactRule

func (logger *StarLogger) AddRedactRule(rule RedactRule)

func (*StarLogger) AppendEntryHandler

func (logger *StarLogger) AppendEntryHandler(handler Handler)

func (*StarLogger) ApplyConfig

func (logger *StarLogger) ApplyConfig(cfg Config)

func (*StarLogger) ApplyDevelopmentConfig

func (logger *StarLogger) ApplyDevelopmentConfig()

func (*StarLogger) ApplyKeywordPreset

func (logger *StarLogger) ApplyKeywordPreset(preset KeywordPreset)

func (*StarLogger) ApplyProductionConfig

func (logger *StarLogger) ApplyProductionConfig()

func (*StarLogger) AsStdlibLogger

func (logger *StarLogger) AsStdlibLogger(level int) *log.Logger

func (*StarLogger) AsStdlibLoggerWithOptions

func (logger *StarLogger) AsStdlibLoggerWithOptions(level int, opts ...StdlibBridgeOption) *log.Logger

func (*StarLogger) AsWriter

func (logger *StarLogger) AsWriter(level int) io.Writer

func (*StarLogger) AsWriterWithOptions

func (logger *StarLogger) AsWriterWithOptions(level int, opts ...StdlibBridgeOption) io.Writer

func (*StarLogger) ClearFieldValueColors

func (logger *StarLogger) ClearFieldValueColors()

func (*StarLogger) ClearKeywordColors

func (logger *StarLogger) ClearKeywordColors()

func (*StarLogger) ClearRedactRules

func (logger *StarLogger) ClearRedactRules()

func (*StarLogger) Close

func (logger *StarLogger) Close() error

Close flushes/syncs and closes archive-managed file/sink/writer resources. It does not wait for async handler queue; use Shutdown for graceful app exit.

func (*StarLogger) Critical

func (logger *StarLogger) Critical(str ...interface{})

func (*StarLogger) CriticalContext

func (logger *StarLogger) CriticalContext(ctx context.Context, str ...interface{})

func (*StarLogger) Criticalf

func (logger *StarLogger) Criticalf(format string, str ...interface{})

func (*StarLogger) Criticalln

func (logger *StarLogger) Criticalln(str ...interface{})

func (*StarLogger) Debug

func (logger *StarLogger) Debug(str ...interface{})

func (*StarLogger) DebugContext

func (logger *StarLogger) DebugContext(ctx context.Context, str ...interface{})

func (*StarLogger) Debugf

func (logger *StarLogger) Debugf(format string, str ...interface{})

func (*StarLogger) Debugln

func (logger *StarLogger) Debugln(str ...interface{})

func (*StarLogger) EnableDedup

func (logger *StarLogger) EnableDedup(enable bool)

func (*StarLogger) EnableRateLimit

func (logger *StarLogger) EnableRateLimit(enable bool)

func (*StarLogger) EnableSampling

func (logger *StarLogger) EnableSampling(enable bool)

func (*StarLogger) EnableWrite

func (logger *StarLogger) EnableWrite()

func (*StarLogger) EnbaleWrite deprecated

func (logger *StarLogger) EnbaleWrite()

Deprecated: use EnableWrite.

func (*StarLogger) Error

func (logger *StarLogger) Error(str ...interface{})

func (*StarLogger) ErrorContext

func (logger *StarLogger) ErrorContext(ctx context.Context, str ...interface{})

func (*StarLogger) Errorf

func (logger *StarLogger) Errorf(format string, str ...interface{})

func (*StarLogger) Errorln

func (logger *StarLogger) Errorln(str ...interface{})

func (*StarLogger) Fatal

func (logger *StarLogger) Fatal(str ...interface{})

func (*StarLogger) Fatalf

func (logger *StarLogger) Fatalf(format string, str ...interface{})

func (*StarLogger) Fatalln

func (logger *StarLogger) Fatalln(str ...interface{})

func (*StarLogger) Flush

func (logger *StarLogger) Flush() error

func (*StarLogger) GetAsyncDropCount

func (logger *StarLogger) GetAsyncDropCount() uint64

func (*StarLogger) GetAsyncFallbackToSync

func (logger *StarLogger) GetAsyncFallbackToSync() bool

func (*StarLogger) GetAsyncHandlerTimeout

func (logger *StarLogger) GetAsyncHandlerTimeout() time.Duration

func (*StarLogger) GetAsyncMetrics

func (logger *StarLogger) GetAsyncMetrics() AsyncMetrics

func (*StarLogger) GetAutoAppendNewline

func (logger *StarLogger) GetAutoAppendNewline() bool

func (*StarLogger) GetColorMode

func (logger *StarLogger) GetColorMode() ColorMode

func (*StarLogger) GetConfig

func (logger *StarLogger) GetConfig() Config

func (*StarLogger) GetDedupConfig

func (logger *StarLogger) GetDedupConfig() DedupConfig

func (*StarLogger) GetDedupStats

func (logger *StarLogger) GetDedupStats() DedupStats

func (*StarLogger) GetEntryHandler

func (logger *StarLogger) GetEntryHandler() Handler

func (*StarLogger) GetEntryHandlerTimeout

func (logger *StarLogger) GetEntryHandlerTimeout() time.Duration

func (*StarLogger) GetFieldKeyColor

func (logger *StarLogger) GetFieldKeyColor() []Attr

func (*StarLogger) GetFieldTypeColors

func (logger *StarLogger) GetFieldTypeColors() map[string][]Attr

func (*StarLogger) GetFieldValueColors

func (logger *StarLogger) GetFieldValueColors() map[string][]Attr

func (*StarLogger) GetFormatter

func (logger *StarLogger) GetFormatter() Formatter

func (*StarLogger) GetHandler

func (logger *StarLogger) GetHandler() func(LogData)

func (*StarLogger) GetKeywordColors

func (logger *StarLogger) GetKeywordColors() map[string][]Attr

func (*StarLogger) GetKeywordIgnoreCase

func (logger *StarLogger) GetKeywordIgnoreCase() bool

func (*StarLogger) GetKeywordMatchOptions

func (logger *StarLogger) GetKeywordMatchOptions() KeywordMatchOptions

func (*StarLogger) GetKeywordWholeWord

func (logger *StarLogger) GetKeywordWholeWord() bool

func (*StarLogger) GetLevel

func (logger *StarLogger) GetLevel() int

func (*StarLogger) GetLevelColor

func (logger *StarLogger) GetLevelColor(level int) []Attr

func (*StarLogger) GetMetricsSnapshot

func (logger *StarLogger) GetMetricsSnapshot() MetricsSnapshot

func (*StarLogger) GetName

func (logger *StarLogger) GetName() string

func (*StarLogger) GetOnlyColorLevel

func (logger *StarLogger) GetOnlyColorLevel() bool

func (*StarLogger) GetPendingBlockCount

func (logger *StarLogger) GetPendingBlockCount() uint64

func (*StarLogger) GetPendingDropCount

func (logger *StarLogger) GetPendingDropCount() uint64

func (*StarLogger) GetPendingDropPolicy

func (logger *StarLogger) GetPendingDropPolicy() PendingDropPolicy

func (*StarLogger) GetPendingPeakLength

func (logger *StarLogger) GetPendingPeakLength() int

func (*StarLogger) GetPendingStats

func (logger *StarLogger) GetPendingStats() PendingStats

func (*StarLogger) GetPendingWriteLimit

func (logger *StarLogger) GetPendingWriteLimit() int

func (*StarLogger) GetRateLimitConfig

func (logger *StarLogger) GetRateLimitConfig() RateLimitConfig

func (*StarLogger) GetRateLimitStats

func (logger *StarLogger) GetRateLimitStats() RateLimitStats

func (*StarLogger) GetRedactErrorCount

func (logger *StarLogger) GetRedactErrorCount() uint64

func (*StarLogger) GetRedactFailMode

func (logger *StarLogger) GetRedactFailMode() RedactFailMode

func (*StarLogger) GetRedactMaskToken

func (logger *StarLogger) GetRedactMaskToken() string

func (*StarLogger) GetRedactRuleCount

func (logger *StarLogger) GetRedactRuleCount() int

func (*StarLogger) GetRedactor

func (logger *StarLogger) GetRedactor() Redactor

func (*StarLogger) GetSamplingConfig

func (logger *StarLogger) GetSamplingConfig() SamplingConfig

func (*StarLogger) GetSamplingStats

func (logger *StarLogger) GetSamplingStats() SamplingStats

func (*StarLogger) GetShowColor

func (logger *StarLogger) GetShowColor() bool

func (*StarLogger) GetShowFieldColor

func (logger *StarLogger) GetShowFieldColor() bool

func (*StarLogger) GetShowFlag

func (logger *StarLogger) GetShowFlag() bool

func (*StarLogger) GetShowFuncName

func (logger *StarLogger) GetShowFuncName() bool

func (*StarLogger) GetShowLevel

func (logger *StarLogger) GetShowLevel() bool

func (*StarLogger) GetShowOriginFile

func (logger *StarLogger) GetShowOriginFile() bool

func (*StarLogger) GetShowStd

func (logger *StarLogger) GetShowStd() bool

func (*StarLogger) GetSink

func (logger *StarLogger) GetSink() Sink

func (*StarLogger) GetWriteErrorCount

func (logger *StarLogger) GetWriteErrorCount() uint64

func (*StarLogger) GetWriter

func (logger *StarLogger) GetWriter() io.Writer

func (*StarLogger) Info

func (logger *StarLogger) Info(str ...interface{})

func (*StarLogger) InfoContext

func (logger *StarLogger) InfoContext(ctx context.Context, str ...interface{})

func (*StarLogger) Infof

func (logger *StarLogger) Infof(format string, str ...interface{})

func (*StarLogger) Infoln

func (logger *StarLogger) Infoln(str ...interface{})

func (*StarLogger) IsLevelEnabled

func (logger *StarLogger) IsLevelEnabled(level int) bool

func (*StarLogger) IsWriteStoed deprecated

func (logger *StarLogger) IsWriteStoed() bool

Deprecated: use IsWriteStopped.

func (*StarLogger) IsWriteStopped

func (logger *StarLogger) IsWriteStopped() bool

func (*StarLogger) Log

func (logger *StarLogger) Log(showLog bool, level int, str ...interface{})

func (*StarLogger) LogContext

func (logger *StarLogger) LogContext(ctx context.Context, showLog bool, level int, str ...interface{})

func (*StarLogger) Logf

func (logger *StarLogger) Logf(showLog bool, level int, format string, str ...interface{})

func (*StarLogger) Logln

func (logger *StarLogger) Logln(showLog bool, level int, str ...interface{})

func (*StarLogger) MergeKeywordPreset

func (logger *StarLogger) MergeKeywordPreset(preset KeywordPreset)

func (*StarLogger) NewFlag

func (logger *StarLogger) NewFlag() *StarLogger

func (*StarLogger) Notice

func (logger *StarLogger) Notice(str ...interface{})

func (*StarLogger) NoticeContext

func (logger *StarLogger) NoticeContext(ctx context.Context, str ...interface{})

func (*StarLogger) Noticef

func (logger *StarLogger) Noticef(format string, str ...interface{})

func (*StarLogger) Noticeln

func (logger *StarLogger) Noticeln(str ...interface{})

func (*StarLogger) Panic

func (logger *StarLogger) Panic(str ...interface{})

func (*StarLogger) Panicf

func (logger *StarLogger) Panicf(format string, str ...interface{})

func (*StarLogger) Panicln

func (logger *StarLogger) Panicln(str ...interface{})

func (*StarLogger) Print

func (logger *StarLogger) Print(str ...interface{})

func (*StarLogger) Printf

func (logger *StarLogger) Printf(format string, str ...interface{})

func (*StarLogger) Println

func (logger *StarLogger) Println(str ...interface{})

func (*StarLogger) RemoveFieldValueColor

func (logger *StarLogger) RemoveFieldValueColor(field string)

func (*StarLogger) RemoveKeywordColor

func (logger *StarLogger) RemoveKeywordColor(keyword string)

func (*StarLogger) ResetDedupStats

func (logger *StarLogger) ResetDedupStats()

func (*StarLogger) ResetRateLimitStats

func (logger *StarLogger) ResetRateLimitStats()

func (*StarLogger) ResetSamplingStats

func (logger *StarLogger) ResetSamplingStats()

func (*StarLogger) SetAsyncErrorHandler

func (logger *StarLogger) SetAsyncErrorHandler(alert func(error, LogData))

func (*StarLogger) SetAsyncFallbackToSync

func (logger *StarLogger) SetAsyncFallbackToSync(enable bool)

func (*StarLogger) SetAsyncHandlerTimeout

func (logger *StarLogger) SetAsyncHandlerTimeout(timeout time.Duration)

func (*StarLogger) SetAutoAppendNewline

func (logger *StarLogger) SetAutoAppendNewline(enable bool)

func (*StarLogger) SetColorMode

func (logger *StarLogger) SetColorMode(mode ColorMode)

func (*StarLogger) SetContextFieldExtractor

func (logger *StarLogger) SetContextFieldExtractor(extractor func(context.Context) Fields)

func (*StarLogger) SetDedupConfig

func (logger *StarLogger) SetDedupConfig(cfg DedupConfig)

func (*StarLogger) SetDedupDropHandler

func (logger *StarLogger) SetDedupDropHandler(handler func(DedupDropData))

func (*StarLogger) SetEntryHandler

func (logger *StarLogger) SetEntryHandler(handler Handler)

func (*StarLogger) SetEntryHandlerTimeout

func (logger *StarLogger) SetEntryHandlerTimeout(timeout time.Duration)

func (*StarLogger) SetFieldKeyColor

func (logger *StarLogger) SetFieldKeyColor(color []Attr)

func (*StarLogger) SetFieldTypeColor

func (logger *StarLogger) SetFieldTypeColor(fieldType string, color []Attr)

func (*StarLogger) SetFieldValueColor

func (logger *StarLogger) SetFieldValueColor(field string, color []Attr)

func (*StarLogger) SetFormatter

func (logger *StarLogger) SetFormatter(formatter Formatter)

func (*StarLogger) SetHandler

func (logger *StarLogger) SetHandler(f func(LogData))

func (*StarLogger) SetKeywordColor

func (logger *StarLogger) SetKeywordColor(keyword string, color []Attr)

func (*StarLogger) SetKeywordColors

func (logger *StarLogger) SetKeywordColors(colors map[string][]Attr)

func (*StarLogger) SetKeywordIgnoreCase

func (logger *StarLogger) SetKeywordIgnoreCase(enable bool)

func (*StarLogger) SetKeywordMatchOptions

func (logger *StarLogger) SetKeywordMatchOptions(opts KeywordMatchOptions)

func (*StarLogger) SetKeywordWholeWord

func (logger *StarLogger) SetKeywordWholeWord(enable bool)

func (*StarLogger) SetLevel

func (logger *StarLogger) SetLevel(level int)

func (*StarLogger) SetLevelColor

func (logger *StarLogger) SetLevelColor(level int, color []Attr)

func (*StarLogger) SetName

func (logger *StarLogger) SetName(name string)

func (*StarLogger) SetNewRandomFlag

func (logger *StarLogger) SetNewRandomFlag()

func (*StarLogger) SetOnlyColorLevel

func (logger *StarLogger) SetOnlyColorLevel(ocl bool)

func (*StarLogger) SetPendingDropPolicy

func (logger *StarLogger) SetPendingDropPolicy(policy PendingDropPolicy)

func (*StarLogger) SetPendingWriteLimit

func (logger *StarLogger) SetPendingWriteLimit(limit int)

func (*StarLogger) SetRateLimitConfig

func (logger *StarLogger) SetRateLimitConfig(cfg RateLimitConfig)

func (*StarLogger) SetRateLimitDropHandler

func (logger *StarLogger) SetRateLimitDropHandler(handler func(RateLimitDropData))

func (*StarLogger) SetRedactFailMode

func (logger *StarLogger) SetRedactFailMode(mode RedactFailMode)

func (*StarLogger) SetRedactMaskToken

func (logger *StarLogger) SetRedactMaskToken(mask string)

func (*StarLogger) SetRedactRules

func (logger *StarLogger) SetRedactRules(rules []RedactRule)

func (*StarLogger) SetRedactor

func (logger *StarLogger) SetRedactor(redactor Redactor)

func (*StarLogger) SetSamplingConfig

func (logger *StarLogger) SetSamplingConfig(cfg SamplingConfig)

func (*StarLogger) SetSamplingDropHandler

func (logger *StarLogger) SetSamplingDropHandler(handler func(SamplingDropData))

func (*StarLogger) SetShowColor

func (logger *StarLogger) SetShowColor(val bool)

func (*StarLogger) SetShowFieldColor

func (logger *StarLogger) SetShowFieldColor(show bool)

func (*StarLogger) SetShowFlag

func (logger *StarLogger) SetShowFlag(val bool)

func (*StarLogger) SetShowFuncName

func (logger *StarLogger) SetShowFuncName(val bool)

func (*StarLogger) SetShowLevel

func (logger *StarLogger) SetShowLevel(val bool)

func (*StarLogger) SetShowOriginFile

func (logger *StarLogger) SetShowOriginFile(val bool)

func (*StarLogger) SetShowStd

func (logger *StarLogger) SetShowStd(val bool)

func (*StarLogger) SetSink

func (logger *StarLogger) SetSink(sink Sink)

func (*StarLogger) SetSinks

func (logger *StarLogger) SetSinks(sinks ...Sink)

func (*StarLogger) SetStdErrLevel

func (logger *StarLogger) SetStdErrLevel(level int)

func (*StarLogger) SetSwitching

func (logger *StarLogger) SetSwitching(sw bool)

func (*StarLogger) SetWriteErrorHandler

func (logger *StarLogger) SetWriteErrorHandler(alert func(error, LogData))

func (*StarLogger) SetWriter

func (logger *StarLogger) SetWriter(wr io.Writer)

func (*StarLogger) Shutdown

func (logger *StarLogger) Shutdown(ctx context.Context) error

func (*StarLogger) StdErrLevel

func (logger *StarLogger) StdErrLevel() int

func (*StarLogger) StopWrite

func (logger *StarLogger) StopWrite()

func (*StarLogger) Sync

func (logger *StarLogger) Sync() error

func (*StarLogger) UpdateConfig

func (logger *StarLogger) UpdateConfig(update func(*Config))

func (*StarLogger) Warning

func (logger *StarLogger) Warning(str ...interface{})

func (*StarLogger) WarningContext

func (logger *StarLogger) WarningContext(ctx context.Context, str ...interface{})

func (*StarLogger) Warningf

func (logger *StarLogger) Warningf(format string, str ...interface{})

func (*StarLogger) Warningln

func (logger *StarLogger) Warningln(str ...interface{})

func (*StarLogger) WithContext

func (logger *StarLogger) WithContext(ctx context.Context) *StarLogger

func (*StarLogger) WithError

func (logger *StarLogger) WithError(err error) *StarLogger

func (*StarLogger) WithField

func (logger *StarLogger) WithField(key string, value interface{}) *StarLogger

func (*StarLogger) WithFields

func (logger *StarLogger) WithFields(fields Fields) *StarLogger

func (*StarLogger) Write

func (logger *StarLogger) Write(str ...interface{})

func (*StarLogger) Writef

func (logger *StarLogger) Writef(format string, str ...interface{})

func (*StarLogger) Writeln

func (logger *StarLogger) Writeln(str ...interface{})

type StdlibBridgeOption

type StdlibBridgeOption = stdlibx.Option

func WithStdlibFlags

func WithStdlibFlags(flags int) StdlibBridgeOption

func WithStdlibLevelMapper

func WithStdlibLevelMapper(mapper StdlibLevelMapper) StdlibBridgeOption

func WithStdlibPrefix

func WithStdlibPrefix(prefix string) StdlibBridgeOption

func WithStdlibShowStd

func WithStdlibShowStd(show bool) StdlibBridgeOption

func WithStdlibTrimNewline

func WithStdlibTrimNewline(trim bool) StdlibBridgeOption

type StdlibBridgeOptions

type StdlibBridgeOptions = stdlibx.Options

func DefaultStdlibBridgeOptions

func DefaultStdlibBridgeOptions() StdlibBridgeOptions

type StdlibLevelMapper

type StdlibLevelMapper = stdlibx.LevelMapper

type TestHook

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

func NewStdTestHook

func NewStdTestHook() *TestHook

func NewTestHook

func NewTestHook(logger *StarLogger) *TestHook

func (*TestHook) Close

func (hook *TestHook) Close() bool

Close tries to restore the previous entry handler. It returns false when current handler was replaced externally.

func (*TestHook) Count

func (hook *TestHook) Count() int

func (*TestHook) Entries

func (hook *TestHook) Entries() []Entry

func (*TestHook) Last

func (hook *TestHook) Last() (Entry, bool)

func (*TestHook) Observer

func (hook *TestHook) Observer() *Observer

func (*TestHook) Reset

func (hook *TestHook) Reset()

type TextFormatter

type TextFormatter struct {
	IncludeTimestamp bool
	IncludeLevel     bool
	IncludeSource    bool
	IncludeThread    bool
	IncludeLogger    bool
}

func NewTextFormatter

func NewTextFormatter() *TextFormatter

func (*TextFormatter) Format

func (formatter *TextFormatter) Format(entry *Entry) ([]byte, error)

type WriterSink

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

func NewWriterSink

func NewWriterSink(writer io.Writer) *WriterSink

func (*WriterSink) Close

func (sink *WriterSink) Close() error

func (*WriterSink) Write

func (sink *WriterSink) Write(data []byte) error

Directories

Path Synopsis
internal
Package isatty implements interface to isatty
Package isatty implements interface to isatty

Jump to

Keyboard shortcuts

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