logger

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

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

Go to latest
Published: Feb 18, 2021 License: MIT Imports: 8 Imported by: 0

README

logger

golang logger based on linux syslog

Create logger with options:

package main

import (
	"context"

	"github.com/primalcs/logger"
)

func main() {
	ctx := context.Background()
	lg, err := logger.NewLogger(ctx,
		logger.WithNSQWriter("127.0.0.1:4151", "new_topic"),
		logger.WithLogLevel(logger.DEBUG),
		logger.WithDelimiter(logger.DefaultDelimiter),
	)
	if err != nil {
		panic(err)
	}
	lg.Log(logger.DEBUG, "prefix_tag", "message", "key1", "value1", "key2", "value2")
}

For more Options - options.go

Documentation

Index

Constants

View Source
const (
	ConnectionTCP   = types.ConnectionTCP
	ConnectionUDP   = types.ConnectionUDP
	ConnectionLOCAL = types.ConnectionLOCAL
	ConnectionFILE  = types.ConnectionFILE
	ConnectionNSQ   = types.ConnectionNSQ
)

Contains aliases for connection constants for easier access and usage

View Source
const (
	EMERG  = types.EMERG
	ALERT  = types.ALERT
	CRIT   = types.CRIT
	ERR    = types.ERR
	WARN   = types.WARN
	NOTIFY = types.NOTIFY
	INFO   = types.INFO
	DEBUG  = types.DEBUG
	FORCE  = types.FORCE // force one of levels above =  types.FORCE // force one of levels above
)

Contains aliases for priority constants for easier access and usage

View Source
const (
	DelimiterV       = types.DelimiterV
	DelimiterH       = types.DelimiterH
	DelimiterA       = types.DelimiterA
	DefaultDelimiter = DelimiterV
)

Contains aliases for delimiter constants for easier access and usage

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

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

Logger is the main logging structure of this package

func NewDefaultLogger

func NewDefaultLogger() (*Logger, error)

NewDefaultLogger creates new logger with default options: delimiter: " | " fileWriter in "/var/log/logger/" httpListener on 8080 port localWriter with ring buffer length=1 loglevel Debug and time format RFC3339 in UTC location mostly for testing purposes

func NewLogger

func NewLogger(ctx context.Context, opts ...Option) (*Logger, error)

NewLogger creates a new logging instance with options

func (*Logger) AddOptions

func (lg *Logger) AddOptions(opts ...Option) error

AddOptions options add new options to existing logger should be used before first call of logger

func (*Logger) Log

func (lg *Logger) Log(level types.LogLevel, tag, msg string, kvs ...string)

Log logs message to all defined writers

type Option

type Option func(*Logger) error

Option implements options pattern for Logger

func WithCaller

func WithCaller() Option

WithCaller adds runtime.Caller() info to logs

func WithDelimiter

func WithDelimiter(delimiter string) Option

WithDelimiter specifies message delimiter

func WithFileWriter

func WithFileWriter(addr string) Option

WithFileWriter creates a log file at specified address

func WithHttpListener

func WithHttpListener(port int) Option

WithHttpListener creates new http-server for configuring logger and run it in a new goroutine

func WithLocalWriter

func WithLocalWriter(tag string, priority syslog.Priority, bufferLen int) Option

WithLocalWriter adds a local syslog writer to Logger

func WithLogLevel

func WithLogLevel(level types.LogLevel) Option

WithLogLevel specifies the maximum allowed log level

func WithNSQWriter

func WithNSQWriter(addr, topic string) Option

WithNSQWriter creates a simple connection to NSQ

func WithTCPConnection

func WithTCPConnection(addr, tag string, priority syslog.Priority, bufferLen int) Option

WithTCPConnection adds a tcp syslog writer to Logger

func WithTimeLog

func WithTimeLog(format string, loc *time.Location) Option

WithTimeLog specifies time format and location for logs

func WithUDPConnection

func WithUDPConnection(addr, tag string, priority syslog.Priority, bufferLen int) Option

WithUDPConnection adds a udp syslog writer to Logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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