conf

package
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultElasticLoggerAddresses = "http://127.0.0.1:9200"
	DefaultElasticLoggerIndex     = "log-2006.01.02"
	DefaultElasticLoggerIndexType = "_doc"
	DefaultElasticLoggerTimeout   = 5
)
View Source
const (
	DefaultFileLoggerName      = "2006-01-02.log"
	DefaultFileLoggerPath      = "./logs"
	DefaultFileLoggerSeparator = "2006-01"
)
View Source
const (
	DefaultKafkaLoggerAddresses = "127.0.0.1:9092"
	DefaultKafkaLoggerTopic     = "go-logs"

	DefaultKafkaLoggerDialTimeout  = 5
	DefaultKafkaLoggerReadTimeout  = 5
	DefaultKafkaLoggerWriteTimeout = 5
)
View Source
const (
	DefaultJaegerTracerEndpoint = "http://127.0.0.1:14268/api/traces"
	DefaultJaegerTracerTimeout  = 3
)
View Source
const (
	DefaultZipkinTracerEndpoint = "http://localhost:9411/api/v2/spans"
	DefaultZipkinTracerTimeout  = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Adapter    base.Adapter    `yaml:"adapter" json:"adapter,omitempty"`
	Level      base.Level      `yaml:"level" json:"level,omitempty"`
	TimeFormat base.TimeFormat `yaml:"time-format" json:"time_format,omitempty"`
	Tracer     base.Tracer     `yaml:"tracer" json:"tracer,omitempty"`

	// 日志适配
	FileAdapter    *FileAdapterConfig    `yaml:"file-adapter"`
	ElasticAdapter *ElasticAdapterConfig `yaml:"elastic-adapter"`
	KafkaAdapter   *KafkaAdapterConfig   `yaml:"kafka-adapter"`
	TermAdapter    *TermAdapterConfig    `yaml:"term-adapter"`

	JaegerTracer *JaegerTracerConfig `yaml:"jaeger-tracer"`
	ZipkinTracer *ZipkinTracerConfig `yaml:"zipkin-tracer"`

	// 链路适配.
	OpenTracingSampled      string `yaml:"opentracing-sampled"`
	OpenTracingSpanId       string `yaml:"opentracing-span-id"`
	OpenTracingSpanPosition string `yaml:"opentracing-span-position"`
	OpenTracingTraceId      string `yaml:"opentracing-trace-id"`

	// 动态计算.
	Pid              int      `yaml:"-" json:"pid"`
	ServiceAddresses []string `yaml:"-" json:"service_addresses,omitempty"`
	ServiceHost      string   `yaml:"-" json:"service_host,omitempty"`
	ServicePort      int      `yaml:"-" json:"service_port,omitempty"`
	ServiceName      string   `yaml:"-" json:"service_name,omitempty"`
	ServiceVersion   string   `yaml:"-" json:"service_version,omitempty"`
	// contains filtered or unexported fields
}

Config 系统配置.

func New

func New() *Config

New 配置单例.

func (*Config) After

func (o *Config) After()

After 后置处理, 从 YAML 解析完成之后触发.

func (*Config) DebugOn

func (o *Config) DebugOn() bool

func (*Config) ErrorOn

func (o *Config) ErrorOn() bool

func (*Config) FatalOn

func (o *Config) FatalOn() bool

func (*Config) InfoOn

func (o *Config) InfoOn() bool

func (*Config) SetLevel added in v1.1.2

func (o *Config) SetLevel(name string)

func (*Config) WarnOn

func (o *Config) WarnOn() bool

type ElasticAdapterConfig

type ElasticAdapterConfig struct {
	// Addresses
	// Elasticsearch 地址.
	Addresses []string `yaml:"addresses"`

	// Index
	// 索引名称.
	Index string `yaml:"index"`

	// IndexType
	// 索引类型.
	IndexType string `yaml:"index-type"`

	// Timeout
	// 超时时长.
	Timeout int `yaml:"timeout"`

	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

ElasticAdapterConfig Elasticsearch 配置.

type FileAdapterConfig

type FileAdapterConfig struct {
	// Sync
	// 是否同步, 在同步模式日志顺序写入文件, 但是影响业务执行速度. 默认为 false, 即
	// 异步写入.
	//
	// default: false
	Sync bool `yaml:"sync"`

	// Json
	// 是否输出JSON格式.
	//
	// default: false
	Json bool `yaml:"json"`

	// FileName
	// 文件名.
	//
	// default: 2024-01-10.log
	FileName string `yaml:"name"`

	// FilePath
	// 存储位置.
	//
	// default: ./logs
	FilePath string `yaml:"path"`

	// FileSeparator
	// 分隔模式.
	//
	// default: 2006-01 (按月分隔)
	FileSeparator string `yaml:"separator"`
}

FileAdapterConfig 文本适配器, 日志写入到文件中.

  • /var/logs/sketch/2024-01/2024-01-10.log

type JaegerTracerConfig

type JaegerTracerConfig struct {
	Endpoint string `yaml:"endpoint"`
	Timeout  int    `yaml:"timeout"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

JaegerTracerConfig is the configuration of the Jaeger tracer.

type KafkaAdapterConfig

type KafkaAdapterConfig struct {
	// Addresses
	// is kafka clusters address.
	Addresses []string `yaml:"addresses"`

	// Topic
	// log published to.
	//
	//   Default: go-logs
	Topic string `yaml:"topic"`

	DialTimeout   int    `yaml:"dial-timeout"`
	ReadTimeout   int    `yaml:"read-timeout"`
	WriteTimeout  int    `yaml:"write-timeout"`
	ClientVersion string `yaml:"client-version"`
}

KafkaAdapterConfig is a component for kafka.

type TermAdapterConfig

type TermAdapterConfig struct {
	// Color
	// 开启颜色.
	//
	// default: false
	Color bool

	// Sync
	// 是否同步, 在同步模式日志顺序写入文件, 但是影响业务执行速度. 默认为 false, 即
	// 异步写入.
	//
	// default: false
	Sync bool `yaml:"sync"`
}

TermAdapterConfig 终端适配器.

type ZipkinTracerConfig

type ZipkinTracerConfig struct {
	Endpoint string `yaml:"endpoint"`
	Timeout  int    `yaml:"timeout"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

ZipkinTracerConfig is a component for zipkin tracer.

Jump to

Keyboard shortcuts

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