glogp

package module
Version: v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: MIT Imports: 16 Imported by: 0

README

glogp

glogp is a Golang logging tool.

Usage

package main

import (
	"time"

	"github.com/nikchis/glogp"
)

func main() {
	glogp.SetLevel("INFO")

	glogp.Infof("Info message")
	glogp.Debugf("Debug message")

	time.Sleep(time.Millisecond * 10)
	glogp.Warnf("Warn message")

	glogp.SetFormat("JSON")
	glogp.Infof("Info message in JSON")
}

Documentation

Index

Constants

View Source
const (
	LogTextColorNone       = "\033[0m"
	LogTextColorBlack      = "\033[0;30m"
	LogTextColorRed        = "\033[0;31m"
	LogTextColorGreen      = "\033[0;32m"
	LogTextColorYellow     = "\033[0;33m"
	LogTextColorBlue       = "\033[0;34m"
	LogTextColorPurple     = "\033[0;35m"
	LogTextColorCyan       = "\033[0;36m"
	LogTextColorWhite      = "\033[0;37m"
	LogTextColorNoneBold   = "\033[1m"
	LogTextColorBlackBold  = "\033[1;30m"
	LogTextColorRedBold    = "\033[1;31m"
	LogTextColorGreenBold  = "\033[1;32m"
	LogTextColorYellowBold = "\033[1;33m"
	LogTextColorBlueBold   = "\033[1;34m"
	LogTextColorPurpleBold = "\033[1;35m"
	LogTextColorCyanBold   = "\033[1;36m"
	LogTextColorWhiteBold  = "\033[1;37m"
)
View Source
const LogPrinterDefFileDir = "../var/log"
View Source
const LogTimeLayout = "2006-01-02T15:04:05.000"

Variables

View Source
var LogArchivesMax int = 9
View Source
var LogExecId int64 = time.Now().UTC().UnixNano()
View Source
var LogSizeMax int64 = 16777216 // 16MB

Functions

func Debugf

func Debugf(format string, a ...interface{})

func Errorf

func Errorf(format string, a ...interface{})

func Infof

func Infof(format string, a ...interface{})

func SetFormat added in v0.2.0

func SetFormat(format string)

Sets logging format {text,json,cbor}

func SetLevel

func SetLevel(level string)

Sets logging level {error,warn,info,debug}

func Warnf

func Warnf(format string, a ...interface{})

Types

type CustomLogger

type CustomLogger interface {
	Debug() *log.Logger
	Info() *log.Logger
	Warn() *log.Logger
	Error() *log.Logger
	Close()
}

type LogField

type LogField string
const (
	LogFieldLevel     LogField = "level"
	LogFieldMemory    LogField = "mem"
	LogFieldMessage   LogField = "msg"
	LogFieldTimedelta LogField = "td"
	LogFieldTrace     LogField = "trace"
	LogFieldExecId    LogField = "eid"
	LogFieldBinary    LogField = "bin"
)

type LogFormat

type LogFormat uint8
const (
	LogFormatNone LogFormat = iota
	LogFormatText
	LogFormatJson
	LogFormatCbor
)

func LogFormatValue added in v0.2.0

func LogFormatValue(FormatName string) LogFormat

type LogLevel

type LogLevel uint8
const (
	LogLevelNone LogLevel = iota
	LogLevelError
	LogLevelWarn
	LogLevelInfo
	LogLevelDebug
)

func LogLevelValue

func LogLevelValue(LevelName string) LogLevel

type LogRow

type LogRow struct {
	Level string `json:"level" cbor:"level"`
	Mem   string `json:"mem" cbor:"mem"`
	Msg   string `json:"msg" cbor:"msg"`
	Td    string `json:"td" cbor:"td"`
	Trace string `json:"trace" cbor:"trace"`
	Eid   string `json:"eid" cbor:"eid"`
	Bin   string `json:"bin" cbor:"bin"`
	Ts    string `json:"ts" cbor:"ts"`
}

func NewLogRow

func NewLogRow(e *logrus.Entry) *LogRow

type Printer

type Printer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}
var Print *Printer = New(LogLevelDebug)

Printer for general purpose tasks {Debug, Info, Warn, Error, ...}

func New

func New(level LogLevel) *Printer

func NewCustom

func NewCustom(format LogFormat, level LogLevel, clc CustomLogger) (*Printer, error)

func NewCustomAndStd

func NewCustomAndStd(format LogFormat, level LogLevel, clc CustomLogger) (*Printer, error)

func NewFile

func NewFile(format LogFormat, level LogLevel, dir string) (*Printer, error)

func NewStd

func NewStd(format LogFormat, level LogLevel) (*Printer, error)

func (*Printer) Close

func (p *Printer) Close()

func (*Printer) Debugf

func (p *Printer) Debugf(format string, a ...interface{})

func (*Printer) Errorf

func (p *Printer) Errorf(format string, a ...interface{})

func (*Printer) FileFormat

func (p *Printer) FileFormat() LogFormat

func (*Printer) Infof

func (p *Printer) Infof(format string, a ...interface{})

func (*Printer) Level

func (p *Printer) Level() LogLevel

func (*Printer) Warnf

func (p *Printer) Warnf(format string, a ...interface{})

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL