logger

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2020 License: MIT Imports: 14 Imported by: 5

README

Logger

This logger basically configure zerolog so that you can log via github.com/rs/zerolog/log

Usage

Import shared/logger package. It will be self-initialized.

import  "github.com/xmlking/micro-starter-kit/shared/logger"

Your can set Logger config via Environment Variables: CONFIGOR_LOG_LEVEL , CONFIGOR_LOG_FORMAT

Test

CONFIGOR_LOG_LEVEL=info CONFIGOR_LOG_FORMAT=json go test github.com/xmlking/micro-starter-kit/shared/logger  -count=1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init added in v0.3.2

func Init(options ...Option) error

Helper functions on DefaultLogger

Types

type Format added in v0.3.2

type Format string

Log format enum.

const (
	PRETTY Format = "pretty"
	JSON   Format = "json"
	GCP    Format = "gcp"
	AZURE  Format = "azure"
	AWS    Format = "aws"
)

func ParseFormat added in v0.3.2

func ParseFormat(formatStr string) (Format, error)

type Logger added in v0.3.2

type Logger interface {
	Init(options ...Option) error
	Options() Options
	String() string
}
var (
	// Default Logger
	DefaultLogger Logger
)

func NewLogger

func NewLogger(opts ...Option) Logger

type Option added in v0.3.2

type Option func(*Options)

func ReportCaller added in v0.3.2

func ReportCaller() Option

ReportCaller set value to `true`

func SetOption added in v0.3.2

func SetOption(k, v interface{}) Option

func WithFields added in v0.3.2

func WithFields(fields map[string]interface{}) Option

WithFields set default fields for the logger

func WithFormat added in v0.3.2

func WithFormat(format Format) Option

WithFormat set default log format for the logger

func WithLevel added in v0.3.2

func WithLevel(level zerolog.Level) Option

WithLevel set default level for the logger

func WithOutput added in v0.3.2

func WithOutput(out io.Writer) Option

WithOutput set default output writer for the logger

func WithTimeFormat added in v0.3.2

func WithTimeFormat(timeFormat string) Option

WithTimeFormat set default timeFormat for the logger

type Options added in v0.3.2

type Options struct {
	// The logging level the logger should log at. default is `InfoLevel`
	Level zerolog.Level
	// Log format. default `json`
	Format Format
	// TimeFormat is one of time.RFC3339, time.RFC3339Nano, time.*
	TimeFormat string
	// Flag for whether to log caller info (off by default)
	ReportCaller bool
	// fields to always be logged
	Fields map[string]interface{}
	// It's common to set this to a file, or leave it default which is `os.Stderr`
	Out io.Writer
	// Alternative options
	Context context.Context
}

Directories

Path Synopsis
Package gormlog provides gorm logger implementation using Go-Micro's meta logger.
Package gormlog provides gorm logger implementation using Go-Micro's meta logger.

Jump to

Keyboard shortcuts

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