config

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	B = 1 << (10 * iota)
	KB
	MB
	GB

	Day = 24 * time.Hour
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Level is the level of logger.
	// Values: debug, info, warn, error.
	Level string `json:"level" yaml:"level" toml:"level" bson:"level"`

	// Handler is how the handler handles the logs.
	// Values: "tape", "text", "json".
	// Also, you can register your handlers to logit, see RegisterHandler.
	Handler string `json:"handler" yaml:"handler" toml:"handler" bson:"handler"`

	// Writer is the config of writer.
	Writer WriterConfig `json:"writer" yaml:"writer" toml:"writer" bson:"writer"`

	// WithSource adds source to logs if true.
	WithSource bool `json:"with_source" yaml:"with_source" toml:"with_source" bson:"with_source"`

	// WithPID adds pid to logs if true.
	WithPID bool `json:"with_pid" yaml:"with_pid" toml:"with_pid" bson:"with_pid"`

	// SyncTimer is the timer duration of syncing.
	// An empty string means syncing is manual.
	// You can use common words like "5m" or "60s".
	// See time.Duration and time.ParseDuration.
	SyncTimer string `json:"sync_timer" yaml:"sync_timer" toml:"sync_timer" bson:"sync_timer"`
}

func (*Config) Options

func (c *Config) Options() (opts []logit.Option, err error)

Options parses a config and returns a list of options. Return an error if parse failed.

type WriterConfig

type WriterConfig struct {
	// Target is where the writer writes logs.
	// Values: "stdout", "stderr", or a file path like "./logit.log".
	Target string `json:"target" yaml:"target" toml:"target" bson:"target"`

	// FileRotate is log file should split and backup when satisfy some conditions.
	// It's useful in production so we recommend you to set it to true.
	// Only available when target is a file path.
	FileRotate bool `json:"file_rotate" yaml:"file_rotate" toml:"file_rotate" bson:"file_rotate"`

	// FileMaxSize is the max size of a log file.
	// If size of data in one output operation is bigger than this value, then file will rotate before writing,
	// which means file and its backups may be bigger than this value in size.
	// You can use common words like "100MB" or "1GB".
	// Only available when rotate is true.
	FileMaxSize string `json:"file_max_size" yaml:"file_max_size" toml:"file_max_size" bson:"file_max_size"`

	// FileMaxAge is the time that backups will live.
	// All backups reach max age will be removed automatically.
	// You can use common words like "7d" or "24h".
	// See time.Duration and time.ParseDuration.
	// Only available when rotate is true.
	FileMaxAge string `json:"file_max_age" yaml:"file_max_age" toml:"file_max_age" bson:"file_max_age"`

	// FileMaxBackups is the max count of file backups.
	// Only available when rotate is true.
	FileMaxBackups uint32 `json:"file_max_backups" yaml:"file_max_backups" toml:"file_max_backups" bson:"file_max_backups"`

	// BufferSize is the size of a buffer.
	// You can use common words like "512B" or "4KB".
	// Only available when mode is "buffer".
	BufferSize string `json:"buffer_size" yaml:"buffer_size" toml:"buffer_size" bson:"buffer_size"`

	// BatchSize is the size of a batch.
	// Only available when mode is "batch".
	BatchSize uint64 `json:"batch_size" yaml:"batch_size" toml:"batch_size" bson:"batch_size"`
}

func (*WriterConfig) Options added in v1.5.10

func (wc *WriterConfig) Options() (opts []logit.Option, err error)

Options parses a writer config and returns a list of options. Return an error if parse failed.

Jump to

Keyboard shortcuts

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