logger

package module
v1.0.0-...-6e06feb Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2016 License: MIT Imports: 11 Imported by: 0

README

gologger

logger package for golang with echo middle ware support

Documentation

Index

Constants

View Source
const (
	//MONITOR monitoring logs flag
	MONITOR string = "MONITOR"
	//ERROR error logs flag
	ERROR string = "ERROR"
	//WARNING Warning logs flag string
	WARNING string = "WARNING"
	//INFO informative log message flag string
	INFO string = "INFO"
	//DEBUG debug logs flag string
	DEBUG string = "DEBUG"
)

Variables

View Source
var LogLevels = map[string]int{MONITOR: 0, ERROR: 1, WARNING: 2, INFO: 3, DEBUG: 4}

LogLevels defines loglevel priorities 0 highest and 3 lowest

Functions

func Debug

func Debug(message ...interface{})

Debug Debug log without formatting

func Debugf

func Debugf(message ...interface{})

Debugf Prints log with formatting

func Error

func Error(message ...interface{})

Error function for error logs without formatting

func Errorf

func Errorf(message ...interface{})

Errorf Prints log with formatting

func Flush

func Flush()

Flush flushes the data logs to log writer

func GetEchoLoggerConfiguration

func GetEchoLoggerConfiguration() (*middleware.LoggerConfig, error)

GetEchoLoggerConfiguration creates a LoggerConfig for echo middleware and returns it Uses the same writer as other logs uses

func GetLogWriter

func GetLogWriter() (io.Writer, error)

GetLogWriter returns an io.Writer for log if already created returns the same otherwise creates a new buffered Writer and returns

func Info

func Info(message ...interface{})

Info info level logs without formatting

func Infof

func Infof(message ...interface{})

Infof Prints log with formatting

func InitLogger

func InitLogger() error

InitLogger initialise logger object with logWriter and log level

func Warning

func Warning(message ...interface{})

Warning Warning level logs without formatting

func Warningf

func Warningf(message ...interface{})

Warningf Prints log with formatting

Types

type ILogger

type ILogger interface {
	Log(depth int, level string, message ...interface{})
}

ILogger interface defining the log functions

type Log

type Log struct {
	LogTime     time.Time `json:"time"`
	ProcessName string    `json:"process_name"`
	HostName    string    `json:"host_name"`
	ProcessID   int       `json:"process_id"`
	Level       string    `json:"level"`
	FileName    string    `json:"file_name"`
	LineNum     int       `json:"line_num"`
	Msg         string    `json:"log_msg"`
}

Log defines the structure of the log message or the log format

func GetLog

func GetLog() Log

GetLog returns log struct GetLog returns the log struct with essential common data filled in

func (Log) String

func (log Log) String() string

String implements Stringer interface json encode the object and returns

type Logger

type Logger struct {
	LogLevel int
	Writer   io.Writer
}

Logger struct to hold the log level and the Writer

func (Logger) Log

func (l Logger) Log(depth int, level string, message string)

Log given the stack depth and level with an array of messages decides if to be Written to logs ans writes to log with FileName and LineNum taken from runtime Info

Jump to

Keyboard shortcuts

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