Documentation
¶
Overview ¶
Package golog provides a logging framework making your logging easier and happier.
Index ¶
- Constants
- Variables
- type LogLevel
- type Logger
- func (logger *Logger) Color() bool
- func (logger *Logger) Debugf(format string, a ...interface{})
- func (logger *Logger) Errorf(format string, a ...interface{})
- func (logger *Logger) Fatalf(format string, a ...interface{})
- func (logger *Logger) Infof(format string, a ...interface{})
- func (logger *Logger) Log(level LogLevel, msg string)
- func (logger *Logger) MinLevel() LogLevel
- func (logger *Logger) Name() string
- func (logger *Logger) SetMinLevel(level LogLevel)
- func (logger *Logger) TimeFormat() string
- func (logger *Logger) Warnf(format string, a ...interface{})
- func (logger *Logger) Writer() io.Writer
- type Parameters
- type Style
- func (style Style) Bold(bold bool) Style
- func (style Style) FgColor() Style
- func (style Style) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)
- func (style Style) IsBold() bool
- func (style Style) IsUnderline() bool
- func (style Style) SetFgColor(color Style) Style
- func (style Style) Sprintf(format string, a ...interface{}) string
- func (style Style) Underline(underline bool) Style
Constants ¶
const ( DEBUG = LogLevel(1) INFO = LogLevel(2) WARN = LogLevel(3) ERROR = LogLevel(4) )
The logging levels equal to the priorities.
const ( Normal = Style(0x00) Bold = Style(1 << 0) Underline = Style(1 << 1) )
The font decoration styles.
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 ¶
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.
var DefaultName = ""
DefaultName is the default value of Parameters.Name.
var DefaultTimeFormat = "2006/01/02T15:04:05"
DefaultTimeFormat is the default value of Parameters.TimeFormat.
var ExitHandler = os.Exit
ExitHandler is the exit handler used in FATAL logging.
var Null = New(ioutil.Discard, &Parameters{})
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 ¶
ParseLogLevel parses LogLevel from the given str.
This function returns error in parsing.
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) SetMinLevel ¶
SetMinLevel sets the minimum logging level.
func (*Logger) TimeFormat ¶
TimeFormat returns the time format.
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) Fprintf ¶
Fprintf prints the result of Sprintf to the given writer. If the writer is not terminal, any style will be ignored.
func (Style) IsUnderline ¶
IsUnderline returns true for underline Styles.
func (Style) SetFgColor ¶
SetFgColor returns the given Style with the specified color. If the specified color is illegal, then nothing are affected.