Documentation ¶
Overview ¶
log ¶
The log module implements methods for logging code including various levels of logging:
FATAL Fatal represents truly catastrophic situations, as far as application is concerned. An application is about to abort to prevent some kind of corruption or serious problem, if possible. Exit code - 1.
ERROR An error is a serious issue and represents the failure of something important going on in an application. Unlike FATAL, the application itself isn't going down the tubes.
WARN It's log level to indicate that an application might have a problem and that theare detected an unusual situation. It's unexpected and unusual problem, but no real harm done, and it's not known whether the issue will persist or recur.
INFO This level's messages correspond to normal application behavior and milestones. They provide the skeleton of what happened.
DEBUG This level must to include more granular, diagnostic information then INFO level.
TRACE This is really fine-grained information-finer even than DEBUG. At this level should capture every detail you possibly can about the application's behavior.
## Installation
To install this module use `go get` as:
$ go get -u github.com/goloop/log
## Quick Start
To use this module import it as:
package main import "github.com/goloop/log" var Log = log.New() func main() { Log.Debugln("The log was created successfully!") // Disable some logging levels. Log.Levels.Delete(log.DEBUG) Log.Debugln("This message will not be shown!") }
Index ¶
- Constants
- type Level
- type Levels
- type Log
- func (l *Log) Copy() *Log
- func (l *Log) Debug(a ...interface{}) (n int, err error)
- func (l *Log) Debugf(format string, a ...interface{}) (n int, err error)
- func (l *Log) Debugln(a ...interface{}) (n int, err error)
- func (l *Log) Error(a ...interface{}) (n int, err error)
- func (l *Log) Errorf(format string, a ...interface{}) (n int, err error)
- func (l *Log) Errorln(a ...interface{}) (n int, err error)
- func (l *Log) Fatal(a ...interface{}) (n int, err error)
- func (l *Log) Fatalf(format string, a ...interface{}) (n int, err error)
- func (l *Log) Fatalln(a ...interface{}) (n int, err error)
- func (l *Log) Fdebug(w io.Writer, a ...interface{}) (n int, err error)
- func (l *Log) Fdebugf(w io.Writer, format string, a ...interface{}) (n int, err error)
- func (l *Log) Fdebugln(w io.Writer, a ...interface{}) (n int, err error)
- func (l *Log) Ferror(w io.Writer, a ...interface{}) (n int, err error)
- func (l *Log) Ferrorf(w io.Writer, format string, a ...interface{}) (n int, err error)
- func (l *Log) Ferrorln(w io.Writer, a ...interface{}) (n int, err error)
- func (l *Log) Ffatal(w io.Writer, a ...interface{}) (n int, err error)
- func (l *Log) Ffatalf(w io.Writer, format string, a ...interface{}) (n int, err error)
- func (l *Log) Ffatalln(w io.Writer, a ...interface{}) (n int, err error)
- func (l *Log) Finfo(w io.Writer, a ...interface{}) (n int, err error)
- func (l *Log) Finfof(w io.Writer, format string, a ...interface{}) (n int, err error)
- func (l *Log) Finfoln(w io.Writer, a ...interface{}) (n int, err error)
- func (l *Log) Format(showFilePath, showFuncName, showFileLine bool)
- func (l *Log) Ftrace(w io.Writer, a ...interface{}) (n int, err error)
- func (l *Log) Ftracef(w io.Writer, format string, a ...interface{}) (n int, err error)
- func (l *Log) Ftraceln(w io.Writer, a ...interface{}) (n int, err error)
- func (l *Log) Fwarn(w io.Writer, a ...interface{}) (n int, err error)
- func (l *Log) Fwarnf(w io.Writer, format string, a ...interface{}) (n int, err error)
- func (l *Log) Fwarnln(w io.Writer, a ...interface{}) (n int, err error)
- func (l *Log) Info(a ...interface{}) (n int, err error)
- func (l *Log) Infof(format string, a ...interface{}) (n int, err error)
- func (l *Log) Infoln(a ...interface{}) (n int, err error)
- func (l *Log) Trace(a ...interface{}) (n int, err error)
- func (l *Log) Tracef(format string, a ...interface{}) (n int, err error)
- func (l *Log) Traceln(a ...interface{}) (n int, err error)
- func (l *Log) Warn(a ...interface{}) (n int, err error)
- func (l *Log) Warnf(format string, a ...interface{}) (n int, err error)
- func (l *Log) Warnln(a ...interface{}) (n int, err error)
- type Trace
Constants ¶
const SKIP = 5
SKIP default stack offset values.
const Timestamp = "01.02.2006 15:04:05"
Timestamp is the format for displaying the time stamp in the log message.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Levels ¶
Levels contains active log levels.
type Log ¶
type Log struct { // Writer is the message receiver object (os.Stdout by default). Writer io.Writer // Timestamp is the format for displaying the // time stamp in the log message. Timestamp string // Levels map of available levels. Levels Levels // ShowFilePath if true appends the full path to the go-file, // the logging method was called. ShowFilePath bool // ShowFuncName if true, appends the function name where the // logging method was called. ShowFuncName bool // ShowFileLine if true appends the line number in the go-file // where the logging method was called. ShowFileLine bool }
Log this is the logging object.
func New ¶
New returns new Log object. Takes zero or more log levels as arguments. If logging levels are not specified, all possible logging levels will be activated, otherwise only the specified logging levels will be activated.
func (*Log) Debug ¶
Debug creates message with DEBUG level, using the default formats for its operands and writes to log.Writer. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
func (*Log) Debugf ¶
Debugf creates message with DEBUG level, according to a format specifier and writes to log.Writer. It returns the number of bytes written and any write error encountered.
func (*Log) Debugln ¶
Debugln creates message with DEBUG, level using the default formats for its operands and writes to log.Writer. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
func (*Log) Error ¶
Error creates message with ERROR level, using the default formats for its operands and writes to log.Writer. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
func (*Log) Errorf ¶
Errorf creates message with ERROR level, according to a format specifier and writes to log.Writer. It returns the number of bytes written and any write error encountered.
func (*Log) Errorln ¶
Errorln creates message with ERROR, level using the default formats for its operands and writes to log.Writer. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
func (*Log) Fatal ¶
Fatal creates message with FATAL level, using the default formats for its operands and writes to log.Writer. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
func (*Log) Fatalf ¶
Fatalf creates message with FATAL level, according to a format specifier and writes to log.Writer. It returns the number of bytes written and any write error encountered.
func (*Log) Fatalln ¶
Fatalln creates message with FATAL, level using the default formats for its operands and writes to log.Writer. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
func (*Log) Fdebug ¶
Fdebug creates message with DEBUG level, using the default formats for its operands and writes to w. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
func (*Log) Fdebugf ¶
Fdebugf creates message with DEBUG level, according to a format specifier and writes to w. It returns the number of bytes written and any write error encountered.
func (*Log) Fdebugln ¶
Fdebugln creates message with DEBUG level, using the default formats for its operands and writes to w. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
func (*Log) Ferror ¶
Ferror creates message with ERROR level, using the default formats for its operands and writes to w. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
func (*Log) Ferrorf ¶
Ferrorf creates message with ERROR level, according to a format specifier and writes to w. It returns the number of bytes written and any write error encountered.
func (*Log) Ferrorln ¶
Ferrorln creates message with ERROR level, using the default formats for its operands and writes to w. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
func (*Log) Ffatal ¶
Ffatal creates message with FATAL level, using the default formats for its operands and writes to w. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
func (*Log) Ffatalf ¶
Ffatalf creates message with FATAL level, according to a format specifier and writes to w. It returns the number of bytes written and any write error encountered.
func (*Log) Ffatalln ¶
Ffatalln creates message with FATAL level, using the default formats for its operands and writes to w. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
func (*Log) Finfo ¶
Finfo creates message with INFO level, using the default formats for its operands and writes to w. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
func (*Log) Finfof ¶
Finfof creates message with INFO level, according to a format specifier and writes to w. It returns the number of bytes written and any write error encountered.
func (*Log) Finfoln ¶
Finfoln creates message with INFO level, using the default formats for its operands and writes to w. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
func (*Log) Format ¶
Format sets the message prefix display configuration flags for display: file path, function name and file line.
func (*Log) Ftrace ¶
Ftrace creates message with TRACE level, using the default formats for its operands and writes to w. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
func (*Log) Ftracef ¶
Ftracef creates message with TRACE level, according to a format specifier and writes to w. It returns the number of bytes written and any write error encountered.
func (*Log) Ftraceln ¶
Ftraceln creates message with TRACE level, using the default formats for its operands and writes to w. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
func (*Log) Fwarn ¶
Fwarn creates message with WARN level, using the default formats for its operands and writes to w. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
func (*Log) Fwarnf ¶
Fwarnf creates message with WARN level, according to a format specifier and writes to w. It returns the number of bytes written and any write error encountered.
func (*Log) Fwarnln ¶
Fwarnln creates message with WARN level, using the default formats for its operands and writes to w. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
func (*Log) Info ¶
Info creates message with INFO level, using the default formats for its operands and writes to log.Writer. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
func (*Log) Infof ¶
Infof creates message with INFO level, according to a format specifier and writes to log.Writer. It returns the number of bytes written and any write error encountered.
func (*Log) Infoln ¶
Infoln creates message with INFO, level using the default formats for its operands and writes to log.Writer. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
func (*Log) Trace ¶
Trace creates message with TRACE level, using the default formats for its operands and writes to log.Writer. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
func (*Log) Tracef ¶
Tracef creates message with TRACE level, according to a format specifier and writes to log.Writer. It returns the number of bytes written and any write error encountered.
func (*Log) Traceln ¶
Traceln creates message with TRACE, level using the default formats for its operands and writes to log.Writer. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
func (*Log) Warn ¶
Warn creates message with WARN level, using the default formats for its operands and writes to log.Writer. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
func (*Log) Warnf ¶
Warnf creates message with WARN level, according to a format specifier and writes to log.Writer. It returns the number of bytes written and any write error encountered.