elogger

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: MIT Imports: 6 Imported by: 0

README

elogger

Simple Structured logger

Currently only JSON output format

What's new

  • EventTag func to log with event name only. mostly for the event dashboard
  • Error func to log error with the event name in pointer receiver fashion
  • Fatal func to log and kill if err != nill. mostly for critical env missing or in case of resource connection fail

Example:

logData.ID = sessionID
logData.Account = userID
logData.RawInterface = anyInterface

elogger.Event(logData, "error", "eventName", err.Error())

logData.EventTag("AwesomeThingDone")

logData.Error("testEventLog", "test event logger")

logData.Fatal("dbConFail", "Can't connect to database")

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ServiceName = ""

ServiceName name of service

Functions

func Event

func Event(thelog StructuredLog, level, event, msg string)

Event in json format

func LogNew

func LogNew(level, event, msg string)

LogNew is to log with a new StructuredLog struct

Types

type StructuredLog

type StructuredLog struct {
	Timestamp string `json:"@timestamp,omitempty"`
	Service   string `json:"service,omitempty"`
	Thread    string `json:"thread,omitempty"`
	IP        string `json:"ip,omitempty"`
	Env       string `json:"env,omitempty"`
	Server    string `json:"server,omitempty"`
	Path      string `json:"path,omitempty"`

	Level        string      `json:"level,omitempty"`
	Event        string      `json:"event,omitempty"`
	Message      string      `json:"message,omitempty"`
	Account      string      `json:"account,omitempty"`
	ID           string      `json:"id,omitempty"`
	Raw          string      `json:"raw,omitempty"`
	RawInterface interface{} `json:"rawInterface,omitempty"`
}

StructuredLog struct for structured loggin

func (*StructuredLog) Error added in v1.0.4

func (thelog *StructuredLog) Error(event, msg string)

Error log error with event name

func (*StructuredLog) EventTag added in v1.0.5

func (thelog *StructuredLog) EventTag(event string)

EventTag log info only with event name

func (*StructuredLog) Fatal added in v1.0.4

func (thelog *StructuredLog) Fatal(event string, err error)

Fatal log error with event name and call log.Fatal()

Jump to

Keyboard shortcuts

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