logger

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

Logger

Colorful logging with additional time and level output.

Feel free to add new functions or improve the existing code.

Install

go get github.com/iconimpact/go-core/logger

Usage and Examples

// init logger
log := logging.Logger{MinLevel: "verbose"}

// set settings from a config
log.MinLevel = cfg.MinLevel
log.TimeFormat = cfg.TimeFormat
log.UseColor = cfg.UseColor
log.ReportCaller = cfg.ReportCaller

// disable colors for tests
if test {
    log.UseColor = false
}

// use JSON output for production
if cfg.Env == "prod" {
    log.UseJSON = true
}

Documentation

Overview

Package logger Colorful logging with additional time and level output

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Colors

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

Colors ANSI CLI colors

type LogRow

type LogRow struct {
	Level    string `json:"level"`
	Time     string `json:"time"`
	Message  string `json:"message"`
	LevelInt int    `json:"level_int"`
	Caller   string `json:"caller,omitempty"`
}

LogRow represents a log entry and is serialized to JSON.

type Logger

type Logger struct {
	MinLevel     string
	TimeFormat   string // use example date: "2006-01-02 15:04:05.000" or "15:04:05.000"
	UseColor     bool
	UseJSON      bool
	ReportCaller bool
	Output       io.Writer
}

Logger settings

func (*Logger) Debug

func (l *Logger) Debug(text ...interface{})

Debug logging

func (*Logger) Error

func (l *Logger) Error(text ...interface{})

Error logging

func (*Logger) Info

func (l *Logger) Info(text ...interface{})

Info logging

func (*Logger) Verbose

func (l *Logger) Verbose(text ...interface{})

Verbose logging - note: Its just debug.

func (*Logger) Warning

func (l *Logger) Warning(text ...interface{})

Warning logging

Jump to

Keyboard shortcuts

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