logger

package module
v0.0.0-...-2897ae0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2018 License: MIT Imports: 10 Imported by: 7

README

Logger

A very simple logger for debugging purposes.

Installation

Make sure you have setup Go in your environtment

go get github.com/gujarats/logger

Usage

It is very simple you can just call it :

logger.Debug("prefix :: ", "Hello World logger")
logger.Debug("prefix2 :: ", "testing")
logger.Debug("prefix3 :: ", "foo bar")

This will output

Example Output

That's it. it would print the log message with specific format time. And save it to a logger,log file.

Output to file

If you want to ouput the log to a file simple just add this function to your func init :

func init(
...
	logger.DebugToFile()
...
)

Customize color

You can also set color as you like :

func init() {
	debugStyle := logger.DebugStyle{
		PrefixColor:  logger.Yellow,
		MessageColor: logger.Blue,
		Style:        logger.Underline,
	}

	timeStyle := logger.TimeStyle{
		YearColor: logger.White,
		SepColor:  logger.Yellow,
		DateColor: logger.Cyan,
		Style:     logger.Italic,
	}
	logger.NewCustomColor(debugStyle, timeStyle)
}

// you can call it anywhere direcly 
logger.Debug("prefix :: ", "Hello World logger")

Example Output Custom

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EnableCustomColor bool

Enable custome color

View Source
var FileSave bool

setup log output to a file

Functions

func Debug

func Debug(prefix string, message ...interface{})

Print debug message to os.StdOut without save it to a file

func DebugToFile

func DebugToFile()

Set the output to a file

func Debugf

func Debugf(prefix string, format string, message ...interface{})

Print debug message to os.StdOut without save it to a file with specific format

func GetColorFormat

func GetColorFormat(color, style Attribute, text string) string

return a formatted color based on the chosen Attribute for specific text

func NewCustomColor

func NewCustomColor(debugStyle DebugStyle, timeStyle TimeStyle)

func NewDebugStyle

func NewDebugStyle(prefix, message string) string

func NewTimeStyle

func NewTimeStyle() string

Types

type Attribute

type Attribute int

Attribute defines a single SGR Code

const (
	Reset Attribute = iota
	Bold
	Faint
	Italic
	Underline
	BlinkSlow
	BlinkRapid
	ReverseVideo
	Concealed
	CrossedOut
)

Base attributes

const (
	Black Attribute = iota + 30
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	White
)

Text colors

type CustomColor

type CustomColor struct {
	DebugStyle
	TimeStyle
}
var CustomColorStyle CustomColor

type CustomFile

type CustomFile struct {
	*os.File
}

func (*CustomFile) Write

func (c *CustomFile) Write(bytes []byte) (int, error)

type DebugStyle

type DebugStyle struct {
	PrefixColor  Attribute
	MessageColor Attribute
	Style        Attribute
}

type TimeStyle

type TimeStyle struct {
	YearColor Attribute
	SepColor  Attribute // separator ::
	DateColor Attribute
	Style     Attribute
}

Jump to

Keyboard shortcuts

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