logger

package module
v0.0.0-...-dfb136a Latest Latest
Warning

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

Go to latest
Published: May 6, 2020 License: MIT Imports: 6 Imported by: 0

README

go-microservice-logger

Documentation

Index

Constants

View Source
const (
	// XTransactionID is a key of transaction ID for microservice.
	// This is supposed to be set in HTTP header and SQS attributes and so on.
	// This variable is used in each service.
	XTransactionID = "X-Transaction-ID"
)

Variables

Formatters is a struct variable for Config.

View Source
var Levels = func() levels {
	const (
		Debug Level = iota + 1
		Info
		Warn
		Error
		Panic
	)
	return levels{
		Debug: Debug,
		Info:  Info,
		Warn:  Warn,
		Error: Error,
		Panic: Panic,
	}
}()

Levels provides levels of logging Debug Info Warn Error Panic Fatal

View Source
var (
	// ServiceName is supposed to be embedded by using
	// ldflags at build time of a service application.
	ServiceName = "not-set"
)

Functions

func AlterDefaultLogger

func AlterDefaultLogger(conf *Config)

AlterDefaultLogger changes default logger by the given config. This affects logger.Debug, Info, Warn, Error methods.

func Debug

func Debug(xTxID interface{}, msg string, fields ...Field)

Debug logs a message at level Debug as microservice default logger

func Error

func Error(xTxID interface{}, msg string, fields ...Field)

Error logs a message at level Error as microservice default logger

func Info

func Info(xTxID interface{}, msg string, fields ...Field)

Info logs a message at level Info as microservice default logger

func Panic

func Panic(xTxID interface{}, msg string, fields ...Field)

Panic logs a message at level Panic as microservice default logger

func Warn

func Warn(xTxID interface{}, msg string, fields ...Field)

Warn logs a message at level Warn as microservice default logger

Types

type Config

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

Config is a configuration structure for Logger.

formatter: Format type of logging, TEXT or JSON, or LTSV out: io.Writer of the logger output minLevel: Minimum level to out

func NewConfig

func NewConfig(options ...ConfigOption) *Config

NewConfig is a constructor of *Config.

Default setting as Microservice rule Formatter: LTSV Out: stdout MinLevel: Info

func (*Config) Formatter

func (c *Config) Formatter() Formatter

Formatter is a getter method to get formatter of the config.

func (*Config) MinLevel

func (c *Config) MinLevel() Level

MinLevel is a getter method to get minLevel of the config.

func (*Config) Out

func (c *Config) Out() io.Writer

Out is a getter method to get out as io.Writer of the config.

type ConfigOption

type ConfigOption func(*Config)

ConfigOption is a type of function to set the fields of Config for Functional Options Pattern.

func WithFormatter

func WithFormatter(formatter Formatter) ConfigOption

WithFormatter - specify format type of logger.

func WithMinLevel

func WithMinLevel(minLevel Level) ConfigOption

WithMinLevel - specify Logging minimum level.

func WithOut

func WithOut(out io.Writer) ConfigOption

WithOut - specify output destination of logger.

type Field

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

Field is a struct type for additional fields of Logging.

func E

func E(err error) Field

E is a function to make error Field with key and value.

func F

func F(key string, value interface{}) Field

F is a function to make normal Field with key and value.

type Formatter

type Formatter struct {
	logrus.Formatter
}

Formatter is a type for Logger format.

type Level

type Level int8

Level is a type of Log level

func ParseLevel

func ParseLevel(level string) Level

ParseLevel parses string to Level type

func (Level) String

func (l Level) String() string

String returns string of Level type

type Logger

type Logger interface {
	Debug(xTxID interface{}, msg string, fields ...Field)
	Info(xTxID interface{}, msg string, fields ...Field)
	Warn(xTxID interface{}, msg string, fields ...Field)
	Error(xTxID interface{}, msg string, fields ...Field)
	Panic(xTxID interface{}, msg string, fields ...Field)
}

Logger is public interface of this package.

func NewLogger

func NewLogger(config *Config) Logger

NewLogger is a constructor of Logger interface. Basically, the rule is that microservice applications should use Log global instances without using this method. You should call this method with setting up Config when you do development or research.

Jump to

Keyboard shortcuts

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