conf

package
v0.1.12 Latest Latest
Warning

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

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

Documentation

Overview

Package conf is a component that defines the log configuration.

Component is initialized from follow file when load at first time. Config file name should be "log.yaml" or "log.yml" at config directory like follows.

One of follows:

  • config/log.yaml
  • config/log.yml

Index

Constants

View Source
const (
	DefaultTimeFormat              = time.RFC3339
	DefaultServiceName             = "logger"
	DefaultServiceVersion          = "0.0.0"
	DefaultOpentracingTraceId      = "X-B3-TraceId"
	DefaultOpentracingSpanId       = "X-B3-SpanId"
	DefaultOpentracingSpanPosition = "X-B3-Version"
)
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 {
	// Level
	// logging filter name like follows.
	//
	//    - debug
	//    - info (default)
	//    - warn
	//    - error
	//    - fatal
	Level base.Level `yaml:"level"`

	// TimeFormat
	// logger time format.
	TimeFormat string `yaml:"time-format"`

	// OpentracingTraceId
	// trace id for opentracing.
	OpentracingTraceId string `yaml:"opentracing-trace-id"`

	// OpentracingSpanId
	// span id for opentracing.
	OpentracingSpanId string `yaml:"opentracing-span-id"`

	// OpentracingSpanPosition
	// Package tracing for items offset position.
	OpentracingSpanPosition string `yaml:"opentracing-span-position"`

	// Adapter
	// configured for logging like follows.
	//
	//   - elastic
	//   - file
	//   - kafka
	//   - term (default)
	Adapter base.Adapter `yaml:"adapter"`

	// ElasticAdapter
	// is a component that defines the Elasticsearch adapter configuration.
	ElasticAdapter *ElasticAdapterConfig `yaml:"elastic-adapter"`

	// FileAdapter
	// is a component that defines the file adapter configuration.
	FileAdapter *FileAdapterConfig `yaml:"file-adapter"`

	// KafkaAdapter
	// is a component that defines the Kafka adapter configuration.
	KafkaAdapter *KafkaAdapterConfig `yaml:"kafka-adapter"`

	// TermAdapter
	// is a component that defines the terminal adapter configuration.
	TermAdapter *TermAdapterConfig `yaml:"term-adapter"`

	// Tracer
	// is a tracer for follows.
	//
	//   - jaeger
	//   - zipkin
	Tracer base.Tracer `yaml:"tracer"`

	// JaegerTracer
	// is a component that defines the Jaeger configuration.
	JaegerTracer *JaegerTracerConfig `yaml:"jaeger-tracer"`

	// ZipkinTracer
	// is a component that defines the Zipkin configuration.
	ZipkinTracer *ZipkinTracerConfig `yaml:"zipkin-tracer"`

	Pid            int    `yaml:"-"`
	ServiceAddr    string `yaml:"-"`
	ServicePort    int    `yaml:"-"`
	ServiceName    string `yaml:"-"`
	ServiceVersion string `yaml:"-"`
	// contains filtered or unexported fields
}

Config is a component that defines the log configuration.

func Get

func Get() *Config

Get returns the singleton configuration instance.

func New

func New(m any) *Config

New creates a new configuration instance with manager.

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) SetAdapter

func (o *Config) SetAdapter(s string) *Config

SetAdapter sets the log adapter.

func (*Config) SetLevel

func (o *Config) SetLevel(s string) *Config

SetLevel sets the log level.

func (*Config) SetTracer

func (o *Config) SetTracer(s string) *Config

SetTracer sets the tracer.

func (*Config) WarnOn

func (o *Config) WarnOn() bool

type ConfigAdapterConfigured

type ConfigAdapterConfigured interface {
	// ConfigLoggerAdapter
	// configures the logger adapter.
	ConfigLoggerAdapter(adapter base.Adapter)
}

type ConfigReporterConfigured

type ConfigReporterConfigured interface {
	// ConfigTracerReporter
	// configures the tracer reporter.
	ConfigTracerReporter(adapter base.Tracer)
}

type ElasticAdapterConfig

type ElasticAdapterConfig struct {
	// Addresses
	// is elasticsearch clusters address.
	//
	//   Example:
	//     - http://127.0.0.1:9200
	Addresses []string `yaml:"addresses"`

	// Index
	// name of elasticsearch indices.
	//
	//   Default: log-2006.01.02
	Index string `yaml:"index"`

	// IndexType
	// type of elasticsearch indices if supported.
	//
	//   Default: _doc
	IndexType string `yaml:"index-type"`

	// Timeout
	// durations of elasticsearch request.
	//
	//   Default: 5
	//   Unit: Second
	Timeout int `yaml:"timeout"`

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

ElasticAdapterConfig is a component for elasticsearch.

type FileAdapterConfig

type FileAdapterConfig struct {
	// Json
	// converts as json string or not.
	//
	//   Default: false
	Json bool `yaml:"json"`

	// FileName
	// saved log file name.
	//
	//   Example: 2024-01-10.log
	FileName string `yaml:"name"`

	// FilePath
	// log file saved path.
	//
	//   Default: ./logs
	FilePath string `yaml:"path"`

	// FileSeparator
	// log files separated by month.
	//
	//   Default: 2006-01 (Month)
	FileSeparator string `yaml:"separator"`
}

FileAdapterConfig is a component for file.

  • /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
	// render with color around the log content or not.
	//
	//   Default: false
	Color bool
}

TermAdapterConfig is a component for terminal.

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