logx

package
v0.0.0-...-ff598de Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: Unlicense Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRollingSize     = errors.New("rrscpkgs.logx: rolling size must be greater than 0")
	ErrInvalidCompressWorkers = errors.New("rrscpkgs.logx: compress workers must be greater than 0")
	ErrNilRollingOptions      = errors.New("rrscpkgs.logx: rolling options is nil")
)
View Source
var (
	ErrInvalidRollingKind = errors.New("rolling kind is invalid")
)

Functions

func Error

func Error(e error) slog.Attr

func ErrorWithStacktrace

func ErrorWithStacktrace(e error, opts *StacktraceOptions) slog.Attr

func Lazy

func Lazy(key string, f func() slog.Value) slog.Attr

func LazyGroup

func LazyGroup(key string, f func() []slog.Attr) slog.Attr

func New

func New(opts *Opts) (*slog.Logger, error)

func NewSlowWriter

func NewSlowWriter(ctx context.Context, w io.Writer, sizeinbytes int64, duration time.Duration) io.Writer

func Recovered

func Recovered(v any) slog.Attr

func RecoveredWithStacktrace

func RecoveredWithStacktrace(pv any, opts *StacktraceOptions) slog.Attr

Types

type AutoSaveWriter

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

func NewAutoSaveWriter

func NewAutoSaveWriter(w io.Writer, closes ...func() error) *AutoSaveWriter

func (*AutoSaveWriter) Close

func (afw *AutoSaveWriter) Close() error

func (*AutoSaveWriter) Write

func (afw *AutoSaveWriter) Write(p []byte) (n int, err error)

type CompressOptions

type CompressOptions struct {
	Enable   bool                 `json:"enable" toml:"enable"`
	Directly bool                 `json:"directly" toml:"directly"`
	Slow     *SlowCompressOptions `json:"slow" toml:"slow"`
}

type Flusher

type Flusher interface {
	Flush() error
}

type IFile

type IFile interface {
	io.WriteCloser
	Sync() error
	Stat() (os.FileInfo, error)
}

type LazyType

type LazyType func() slog.Value

func (LazyType) LogValue

func (l LazyType) LogValue() slog.Value

type LockFile

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

LockFile for multi process safe

func OpenLockFile

func OpenLockFile(fp string, flag int, perm os.FileMode) (*LockFile, error)

func (*LockFile) Close

func (f *LockFile) Close() error

func (*LockFile) Stat

func (f *LockFile) Stat() (os.FileInfo, error)

func (*LockFile) Sync

func (f *LockFile) Sync() error

func (*LockFile) Write

func (f *LockFile) Write(p []byte) (int, error)

type NoBufferedWriter

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

func NewNoBufferedWriter

func NewNoBufferedWriter(w io.Writer) *NoBufferedWriter

func (*NoBufferedWriter) Write

func (nbw *NoBufferedWriter) Write(p []byte) (int, error)

type OpenWriterFnc

type OpenWriterFnc func(string, int, os.FileMode) (IFile, error)

type Opts

type Opts struct {
	Filename         string `json:"filename" toml:"filename"`
	MultiProcessSafe bool   `json:"multi_process_safe" toml:"multi_process_safe"`

	Level       slog.Level `json:"level" toml:"level"`
	AddSource   bool       `json:"add_source" toml:"add_source"`
	WithStdout  bool       `json:"with_stdout" toml:"with_stdout"`
	StdoutLevel slog.Level `json:"stdout_level" toml:"stdout_level"`

	BufferSize int `json:"buffer_size" toml:"buffer_size"`

	Rolling *RollingOptions `json:"rolling" toml:"rolling"`

	DisableLocal bool           `json:"disable_local" toml:"disable_local"`
	Forwards     []slog.Handler `json:"-" toml:"-"`
}

type RollingFile

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

func NewRollingFile

func NewRollingFile(fp string, opts *RollingOptions) (*RollingFile, error)

func (*RollingFile) Close

func (r *RollingFile) Close() error

func (*RollingFile) Write

func (r *RollingFile) Write(p []byte) (n int, err error)

type RollingKind

type RollingKind int
const (
	RollingKindNone RollingKind = iota
	RollingKindDaily
	RollingKindHourly
	RollingKindMinutely
	RollingKindSize
)

func (RollingKind) String

func (i RollingKind) String() string

func (*RollingKind) UnmarshalJSON

func (i *RollingKind) UnmarshalJSON(text []byte) error

func (*RollingKind) UnmarshalText

func (i *RollingKind) UnmarshalText(text []byte) error

type RollingOptions

type RollingOptions struct {
	Kind       RollingKind      `json:"kind" toml:"rolling_kind"`
	FileSize   int64            `json:"size" toml:"size"`
	Backups    int              `json:"backups" toml:"backups"`
	Compress   *CompressOptions `json:"compress" toml:"compress"`
	BufferSize int              `json:"buffer_size" toml:"buffer_size"`
	OpenFile   OpenWriterFnc    `json:"-" toml:"-"`
}

type SlowCompressOptions

type SlowCompressOptions struct {
	Workers        int    `json:"workers" toml:"workers"`
	BytesPerSecond int64  `json:"limit" toml:"limit"`
	TempDir        string `json:"temp" toml:"temp"`
}

type StacktraceOptions

type StacktraceOptions struct {
	Skip int
	Size int
}

type Syncer

type Syncer interface {
	Sync() error
}

Directories

Path Synopsis
test
main command

Jump to

Keyboard shortcuts

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