golog

package module
v0.0.0-...-e50dfe9 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2018 License: MIT Imports: 7 Imported by: 2

README

Package golog provides a logging framework making your logging easier and happier.

Build Status Report Status

Copyright 2018- Tatsuhiro Aoshima (hiro4bbh@gmail.com).

Introduction

Package golog provides a logging framework making your logging easier and happier.

See golog's document on GoDoc. You can test the examples:

GOLOG_MINLEVEL=debug go run example/main.go
GOLOG_MINLEVEL=debug go run example/main.go | cat

Documentation

Overview

Package golog provides a logging framework making your logging easier and happier.

Index

Constants

View Source
const (
	DEBUG = LogLevel(1)
	INFO  = LogLevel(2)
	WARN  = LogLevel(3)
	ERROR = LogLevel(4)
)

The logging levels equal to the priorities.

View Source
const (
	Normal    = Style(0x00)
	Bold      = Style(1 << 0)
	Underline = Style(1 << 1)
)

The font decoration styles.

View Source
const (
	FgBlack   = Style(0 << 8)
	FgRed     = Style(1 << 8)
	FgGreen   = Style(2 << 8)
	FgYellow  = Style(3 << 8)
	FgBlue    = Style(4 << 8)
	FgMagenta = Style(5 << 8)
	FgCyan    = Style(6 << 8)
	FgGray    = Style(7 << 8)
)

The foreground basic colors supported by ANSI escape codes.

Variables

View Source
var DefaultMinLevel = WARN

DefaultMinLevel is the default value of Parameters.MinLevel. This is WARN, but, if the environment variable GOLOG_MINLEVEL is defined and legal, its value is used. Do not assign illegal LogLevel, because there is no check for this.

View Source
var DefaultName = ""

DefaultName is the default value of Parameters.Name.

View Source
var DefaultTimeFormat = "2006/01/02T15:04:05"

DefaultTimeFormat is the default value of Parameters.TimeFormat.

View Source
var ExitHandler = os.Exit

ExitHandler is the exit handler used in FATAL logging.

Null is the logger writing to ioutil.Discard.

Functions

This section is empty.

Types

type LogLevel

type LogLevel int

LogLevel is the level used in each logged line.

func ParseLogLevel

func ParseLogLevel(str string) (LogLevel, error)

ParseLogLevel parses LogLevel from the given str.

This function returns error in parsing.

func (LogLevel) String

func (level LogLevel) String() string

String returns the string representation of LogLevel.

type Logger

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

Logger is the logging manager.

func New

func New(out io.Writer, params *Parameters) *Logger

New returns a new Logger with the specified params. If params is nil, then it is filled with default values. If params has some zero-value fields, then those are replaced with the corresponding default values.

func (*Logger) Color

func (logger *Logger) Color() bool

Color returns true if the coloring is enabled.

func (*Logger) Debugf

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

Debugf writes the formatted message with DEBUG level.

func (*Logger) Errorf

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

Errorf writes the formatted message with ERROR level.

func (*Logger) Fatalf

func (logger *Logger) Fatalf(format string, a ...interface{})

Fatalf is Errorf followed by ExitHandler(1).

func (*Logger) Infof

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

Infof writes the formatted message with INFO level.

func (*Logger) Log

func (logger *Logger) Log(level LogLevel, msg string)

Log writes the given string with the given logging level.

func (*Logger) MinLevel

func (logger *Logger) MinLevel() LogLevel

MinLevel returns the minimum logging level.

func (*Logger) Name

func (logger *Logger) Name() string

Name returns the name.

func (*Logger) SetMinLevel

func (logger *Logger) SetMinLevel(level LogLevel)

SetMinLevel sets the minimum logging level.

func (*Logger) TimeFormat

func (logger *Logger) TimeFormat() string

TimeFormat returns the time format.

func (*Logger) Warnf

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

Warnf writes the formatted message with WARN level.

func (*Logger) Writer

func (logger *Logger) Writer() io.Writer

Writer returns the underlying writer.

type Parameters

type Parameters struct {
	// Name is logging title.
	Name string
	// MinLevel is the minimum logged priority.
	MinLevel LogLevel
	// TimeFormat is used in logging timestamp.
	// This format is based on time.Time.Format.
	TimeFormat string
	// ColorMode specifies the coloring.
	// If this is "always", then the coloring will be enabled always.
	// If this is "never", then the coloring will be disabled always.
	// Otherwise, the coloring will be enabled if IsTerminal(out) is true.
	ColorMode string
}

Parameters has the parameter for Logger.

type Style

type Style uint64

Style has the font color and decoration information.

func (Style) Bold

func (style Style) Bold(bold bool) Style

Bold returns the bolded Style if bold is true, otherwise un-bolded Style.

func (Style) FgColor

func (style Style) FgColor() Style

FgColor returns the foreground color information.

func (Style) Fprintf

func (style Style) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)

Fprintf prints the result of Sprintf to the given writer. If the writer is not terminal, any style will be ignored.

func (Style) IsBold

func (style Style) IsBold() bool

IsBold returns true for bold Styles.

func (Style) IsUnderline

func (style Style) IsUnderline() bool

IsUnderline returns true for underline Styles.

func (Style) SetFgColor

func (style Style) SetFgColor(color Style) Style

SetFgColor returns the given Style with the specified color. If the specified color is illegal, then nothing are affected.

func (Style) Sprintf

func (style Style) Sprintf(format string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string with the specified style.

func (Style) Underline

func (style Style) Underline(underline bool) Style

Underline returns the underlined Style if bold is true, otherwise un-underlined Style.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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