Documentation ¶
Index ¶
- Constants
- Variables
- func Debug(args ...interface{})
- func Debugf(format string, args ...interface{})
- func Debugln(args ...interface{})
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Errorln(args ...interface{})
- func ExportConfiguration(file string, config LoggerConfiguration) error
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Fatalln(args ...interface{})
- func FillConfiguration(defaultCfg interface{}, config interface{}, cfgType configType, ...) error
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func Infoln(args ...interface{})
- func Panic(args ...interface{})
- func Panicf(format string, args ...interface{})
- func Panicln(args ...interface{})
- func Print(args ...interface{})
- func Printf(format string, args ...interface{})
- func Println(args ...interface{})
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- func Warnln(args ...interface{})
- type CloudEvents
- type CloudEventsConfiguration
- type ConsoleType
- type FilterFunc
- type FormatType
- type KafkaProducer
- type KeyFunc
- type LevelType
- type LogFields
- type Logger
- type LoggerConfiguration
- type LogrusConsoleHook
- type LogrusDebugHook
- type LogrusKafkaHook
- type PackageType
- type ProducerConfiguration
- type RotationConfiguration
- type ZapKafkaWriter
Constants ¶
const ( CEHMAC ceSetIDType = "hmac" // message signature CEUUID ceSetIDType = "uuid" // completely unique CEIncrID ceSetIDType = "incr" // incremental CEFuncID ceSetIDType = "func" // set by WithFields or FilterFunc )
Types of cloudevents id fields
const ( CEIDKey = "id" // Required - unique per producer CESourceKey = "source" // Required - URI-reference CESpecVersionKey = "specversion" // Required - current spec is "1.0" CETypeKey = "type" // Required - reverse-DNS name prefix CEDataContentType = "datacontenttype" // Optional - adheres to RFC2046 CEDataSchemaKey = "dataschema" // Optional - URI-reference CESubjectKey = "subject" // Optional - possibly pass log level CETimeKey = "time" // Optional - adheres to RFC3339 CEDataKey = "data" // Optional - no specific format )
Keys for cloudevents fields, values must be non-empty strings
const ( EnvConfig configType = "env" FileConfig configType = "file" BothConfig configType = "both" )
Supported configuration types
const ( LogTestInitEnvName = "PRTEST_INIT" LogAutoInitEnvName = "PRLOG_AUTOINIT" ConfigTypeEnvName = "PRLOG_CFGTYPE" ConfigFileEnvName = "PRLOG_CFGFILE" )
Supported auto init/config environment names
const ( LogEnvPrefix = "PRLOG" KafkaEnvPrefix = "PRKAFKA" CloudEventsEnvPrefix = "PRCE" RotationEnvPrefix = "PRROT" )
Supported environment name prefixes
const ( ConfigFileName = "pr_log_config" ExportConfigFileName = "pr_export_config.yaml" )
Default config file name without extension Config file name exported on SIGUSR1
const ( RandomPartition kafkaPartitionType = "random" // default HashPartition kafkaPartitionType = "hash" RoundRobinPartition kafkaPartitionType = "roundrobin" )
Types of kafka partitioning to map to sarama
const ( LevelKey kafkaKeyType = "level" // default TimeSecondKey kafkaKeyType = "second" TimeNanoSecondKey kafkaKeyType = "nanosecond" FixedKey kafkaKeyType = "fixed" ExtractedKey kafkaKeyType = "extracted" FunctionKey kafkaKeyType = "function" )
Types of kafka keys to generate
const ( CompressionNone compressionType = "none" // default CompressionGZIP compressionType = "gzip" CompressionSnappy compressionType = "snappy" CompressionLZ4 compressionType = "lz4" CompressionZSTD compressionType = "zstd" )
Types of compression to map to sarama
const ( // WaitForNone does not wait for any response WaitForNone ackWaitType = "none" // WaitForLocal waits for only the local commit to succeed WaitForLocal ackWaitType = "local" // default // WaitForAll waits for all in-sync replicas to commit WaitForAll ackWaitType = "all" )
Types of ack waiting to map to sarama
const TopicKey string = "topic"
TopicKey is LogFields key to pass topic through WithFields Example: log.WithFields(LogFields{TopicKey: "mytopic"}).Infof(...)
Variables ¶
var ErrFatal = errors.New("fatal")
var ErrNonFatal = errors.New("nonfatal")
Functions ¶
func Debugf ¶
func Debugf(format string, args ...interface{})
Debugf emulates function from go log pkg
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf emulates function from go log pkg
func ExportConfiguration ¶
func ExportConfiguration(file string, config LoggerConfiguration) error
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf emulates function from go log pkg
func FillConfiguration ¶
func FillConfiguration(defaultCfg interface{}, config interface{}, cfgType configType, filename string, prefix string) error
FillConfiguration fills config from defaults, config file and environment
func Panicf ¶
func Panicf(format string, args ...interface{})
Panicf emulates function from go log pkg
Types ¶
type CloudEvents ¶
type CloudEvents struct {
// contains filtered or unexported fields
}
CloudEvents provides the cloudevents object type
type CloudEventsConfiguration ¶
type CloudEventsConfiguration struct { SetID ceSetIDType HMACKey string Source string SpecVersion string Type string SetSubjectLevel bool }
CloudEventsConfiguration provides cloudevents configuration type
func DefaultCloudEventsCfg ¶
func DefaultCloudEventsCfg() CloudEventsConfiguration
DefaultCloudEventsCfg returns default cloudevents configuration
type ConsoleType ¶
type ConsoleType string
ConsoleType provided to select logger format
const ( Stdout ConsoleType = "stdout" // default Stderr ConsoleType = "stderr" )
Types of logger formats
type FilterFunc ¶
type FilterFunc func(*map[string]interface{})
FilterFunc func to add/modify/remove message map entries and return kafka key
type FormatType ¶
type FormatType string
FormatType provided to select logger format
const ( JSONFormat FormatType = "json" TextFormat FormatType = "text" // default CEFormat FormatType = "cloudevents" )
Types of logger formats
type KafkaProducer ¶
type KafkaProducer struct {
// contains filtered or unexported fields
}
KafkaProducer wraps sarama producer with config
type LogFields ¶
type LogFields map[string]interface{}
LogFields provided for calls to WithFields for structured logging
type Logger ¶
type Logger interface { Print(args ...interface{}) Printf(format string, args ...interface{}) Println(args ...interface{}) Debug(args ...interface{}) Debugf(format string, args ...interface{}) Debugln(args ...interface{}) Info(args ...interface{}) Infof(format string, args ...interface{}) Infoln(args ...interface{}) Warn(args ...interface{}) Warnf(format string, args ...interface{}) Warnln(args ...interface{}) Error(args ...interface{}) Errorf(format string, args ...interface{}) Errorln(args ...interface{}) Fatal(args ...interface{}) Fatalf(format string, args ...interface{}) Fatalln(args ...interface{}) Panic(args ...interface{}) Panicf(format string, args ...interface{}) Panicln(args ...interface{}) WithFields(keyValues LogFields) Logger WithKafkaFilterFn(filter FilterFunc) Logger WithKafkaKeyFn(filter KeyFunc) Logger }
Logger is the contract for the logger interface
func NewLogger ¶
func NewLogger(config LoggerConfiguration) (Logger, error)
NewLogger returns a Logger instance
type LoggerConfiguration ¶
type LoggerConfiguration struct { LogPackage PackageType LogLevel LevelType EnableTimeStamps bool EnableColorLevels bool EnableCloudEvents bool CloudEventsCfg CloudEventsConfiguration EnableKafka bool KafkaFormat FormatType KafkaProducerCfg ProducerConfiguration EnableConsole bool ConsoleFormat FormatType ConsoleWriter ConsoleType EnableFile bool FileFormat FormatType FileLocation string EnableRotation bool RotationCfg RotationConfiguration EnableDebug bool }
LoggerConfiguration stores the config for the logger
func DefaultCompleteCfg ¶
func DefaultCompleteCfg() *LoggerConfiguration
DefaultLoggerCfg returns default log configuration
func DefaultLoggerCfg ¶
func DefaultLoggerCfg() LoggerConfiguration
DefaultLoggerCfg returns default log configuration
func GetLoggerConfiguration ¶
func GetLoggerConfiguration(cfgType configType, cfgFileName string) (LoggerConfiguration, error)
GetLoggerConfiguration generates config from defaults/config-file/environment
type LogrusConsoleHook ¶
type LogrusConsoleHook struct {
// contains filtered or unexported fields
}
LogrusConsoleHook provides a console hook
func (*LogrusConsoleHook) Fire ¶
func (h *LogrusConsoleHook) Fire(entry *logrus.Entry) error
Fire writes the log message exactly the same as logrus console
func (*LogrusConsoleHook) Levels ¶
func (h *LogrusConsoleHook) Levels() []logrus.Level
Levels returns all log levels that are enabled
type LogrusDebugHook ¶
type LogrusDebugHook struct{}
LogrusDebugHook provides a debug hook
func (*LogrusDebugHook) Fire ¶
func (h *LogrusDebugHook) Fire(entry *logrus.Entry) error
Fire prints the entry
func (*LogrusDebugHook) Levels ¶
func (h *LogrusDebugHook) Levels() []logrus.Level
Levels returns all log levels that are enabled
type LogrusKafkaHook ¶
type LogrusKafkaHook struct {
// contains filtered or unexported fields
}
LogrusKafkaHook provides a kafka producer hook
func (*LogrusKafkaHook) Fire ¶
func (h *LogrusKafkaHook) Fire(entry *logrus.Entry) error
Fire writes the entry as a message on Kafka
func (*LogrusKafkaHook) Levels ¶
func (h *LogrusKafkaHook) Levels() []logrus.Level
Levels returns all log levels that are enabled
type PackageType ¶
type PackageType string
PackageType provided to select underlying log package
const ( ZapType PackageType = "zap" LogrusType PackageType = "logrus" )
Supported log packages
type ProducerConfiguration ¶
type ProducerConfiguration struct { Brokers []string Topic string Partition kafkaPartitionType Key kafkaKeyType KeyName string Compression compressionType AckWait ackWaitType ProdFlushFreq time.Duration ProdRetryMax int ProdRetryFreq time.Duration MetaRetryMax int MetaRetryFreq time.Duration EnableTLS bool TLSCfg *tls.Config EnableDebug bool // contains filtered or unexported fields }
ProducerConfiguration provides kafka producer configuration type
func DefaultProducerCfg ¶
func DefaultProducerCfg() ProducerConfiguration
DefaultProducerCfg returns default kafka configuration
type RotationConfiguration ¶
type RotationConfiguration struct { MaxSize int MaxAge int MaxBackups int LocalTime bool Compress bool }
RotationConfiguration stores the config for log rotation
func DefaultRotationCfg ¶
func DefaultRotationCfg() RotationConfiguration
DefaultRotationCfg returns default cloudevents configuration
type ZapKafkaWriter ¶
type ZapKafkaWriter struct {
// contains filtered or unexported fields
}
ZapKafkaWriter is a zap WriteSyncer (io.Writer) that writes messages to Kafka
func (*ZapKafkaWriter) Close ¶
func (zw *ZapKafkaWriter) Close() (err error)
Close must be called when the writer is no longer needed (Thread-safe)
func (*ZapKafkaWriter) Closed ¶
func (zw *ZapKafkaWriter) Closed() bool
Closed returns true if the writer is closed, false otherwise (Thread-safe)
func (*ZapKafkaWriter) Sync ¶
func (zw *ZapKafkaWriter) Sync() error
Sync satisfies zapcore.WriteSyncer interface, zapcore.AddSync works as well