Documentation
¶
Overview ¶
Package glog implements a log infrastructure for Go:
package main import ( "os" "github.com/CodyGuo/glog" ) func main() { glog.Debug("hello debug") glog.Info("hello info") customLog := glog.New(os.Stdout, glog.WithLevel(glog.TRACE), glog.WithLevelLength(4), glog.WithFlags(glog.LglogFlags), glog.WithPrefix("[customLog] ")) customLog.Trace("hello trace") customLog.Debug("hello debug") customLog.Info("hello info") customLog.Notice("hello notice") customLog.Warning("hello warning") customLog.Error("hello error") customLog.Critical("hello critical") }
Output:
2020/04/27 23:15:24 [INFO] hello info [customLog] 2020/04/27 23:15:24.391850 main.go:19: [TRAC] hello trace [customLog] 2020/04/27 23:15:24.391870 main.go:20: [DEBU] hello debug [customLog] 2020/04/27 23:15:24.391880 main.go:21: [INFO] hello info [customLog] 2020/04/27 23:15:24.391887 main.go:22: [NOTI] hello notice [customLog] 2020/04/27 23:15:24.391894 main.go:23: [WARN] hello warning [customLog] 2020/04/27 23:15:24.391904 main.go:24: [ERRO] hello error [customLog] 2020/04/27 23:15:24.391915 main.go:25: [CRIT] hello critical
For a full guide visit https://github.com/CodyGuo/glog
Index ¶
- Constants
- Variables
- func AddFile(name string, flag int, perm os.FileMode) error
- func AddOutput(writers ...io.Writer)
- func AddWriteCloser(writeClosers ...io.WriteCloser)
- func AutoCallDepth()
- func CallDepth() int
- func Close() error
- func Critical(v ...interface{})
- func Criticalf(format string, v ...interface{})
- func Debug(v ...interface{})
- func Debugf(format string, v ...interface{})
- func Error(v ...interface{})
- func Errorf(format string, v ...interface{})
- func Fatal(v ...interface{})
- func Fatalf(format string, v ...interface{})
- func Flags() int
- func Info(v ...interface{})
- func Infof(format string, v ...interface{})
- func LevelLength() uint8
- func Notice(v ...interface{})
- func Noticef(format string, v ...interface{})
- func Output(level Level, format string, v ...interface{}) error
- func Panic(v ...interface{})
- func Panicf(format string, v ...interface{})
- func Prefix() string
- func ResetCallDepth()
- func SetCallDepth(calldepth int)
- func SetFile(name string, flag int, perm os.FileMode) error
- func SetFlags(flag int)
- func SetLevel(level Level)
- func SetLevelLength(length uint8)
- func SetOutput(w io.Writer)
- func SetPrefix(prefix string)
- func SetWriteCloser(writeCloser io.WriteCloser)
- func Trace(v ...interface{})
- func Tracef(format string, v ...interface{})
- func Warn(v ...interface{})
- func Warnf(format string, v ...interface{})
- func Warning(v ...interface{})
- func Warningf(format string, v ...interface{})
- func Writer() io.Writer
- type Fields
- type Level
- type Logger
- func (l *Logger) AddFile(name string, flag int, perm os.FileMode) error
- func (l *Logger) AddOutput(writers ...io.Writer)
- func (l *Logger) AddWriteCloser(writeClosers ...io.WriteCloser)
- func (l *Logger) AutoCallDepth()
- func (l *Logger) CallDepth() int
- func (l *Logger) Close() error
- func (l *Logger) Critical(v ...interface{})
- func (l *Logger) Criticalf(format string, v ...interface{})
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Error(v ...interface{})
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Fatal(v ...interface{})
- func (l *Logger) Fatalf(format string, v ...interface{})
- func (l *Logger) Flags() int
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Level() Level
- func (l *Logger) LevelLength() uint8
- func (l *Logger) Notice(v ...interface{})
- func (l *Logger) Noticef(format string, v ...interface{})
- func (l *Logger) Output(level Level, format string, v ...interface{}) error
- func (l *Logger) Panic(v ...interface{})
- func (l *Logger) Panicf(format string, v ...interface{})
- func (l *Logger) Prefix() string
- func (l *Logger) SetCallDepth(calldepath int)
- func (l *Logger) SetFile(name string, flag int, perm os.FileMode) error
- func (l *Logger) SetFlags(flag int)
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) SetLevelLength(length uint8)
- func (l *Logger) SetOutput(w io.Writer)
- func (l *Logger) SetPrefix(prefix string)
- func (l *Logger) SetWriteCloser(writeCloser io.WriteCloser)
- func (l *Logger) Trace(v ...interface{})
- func (l *Logger) Tracef(format string, v ...interface{})
- func (l *Logger) Warn(v ...interface{})
- func (l *Logger) Warnf(format string, v ...interface{})
- func (l *Logger) Warning(v ...interface{})
- func (l *Logger) Warningf(format string, v ...interface{})
- func (l *Logger) Writer() io.Writer
- type Option
- func WithAutoCallDepth() Option
- func WithCallDepth(calldepth int) Option
- func WithFile(name string, flag int, perm os.FileMode) Option
- func WithFlags(flag int) Option
- func WithLevel(level Level) Option
- func WithLevelLength(levelLength uint8) Option
- func WithMultiWriteCloser(writeClosers ...io.WriteCloser) Option
- func WithMultiWriter(writers ...io.Writer) Option
- func WithPrefix(prefix string) Option
- func WithWriteCloser(writeCloser io.WriteCloser) Option
Constants ¶
View Source
const ( Ldate = 1 << iota // the date in the local time zone: 2009/01/23 Ltime // the time in the local time zone: 01:23:23 Lmicroseconds // microsecond resolution: 01:23:23.123123. assumes Ltime. Llongfile // full file name and line number: /a/b/c/d.go:23 Lshortfile // final file name element and line number: d.go:23. overrides Llongfile LUTC // if Ldate or Ltime is set, use UTC rather than the local time zone Lmsgprefix // move the "prefix" from the beginning of the line to before the message Lmsglevel // log level: [INFO] Lmsgjson // log json format: {"message":"hello json"} LstdFlags = Ldate | Ltime // initial values for the standard logger LglogFlags = LstdFlags | Lmicroseconds | Lshortfile | Lmsgprefix | Lmsglevel )
Variables ¶
View Source
var Discard io.Writer = ioutil.Discard
Functions ¶
func AddWriteCloser ¶
func AddWriteCloser(writeClosers ...io.WriteCloser)
func AutoCallDepth ¶
func AutoCallDepth()
func Flags ¶
func Flags() int
Flags returns the output flags for the standard logger. The flag bits are Ldate, Ltime, and so on.
func LevelLength ¶
func LevelLength() uint8
func ResetCallDepth ¶
func ResetCallDepth()
func SetCallDepth ¶
func SetCallDepth(calldepth int)
func SetFlags ¶
func SetFlags(flag int)
SetFlags sets the output flags for the standard logger. The flag bits are Ldate, Ltime, and so on.
func SetLevelLength ¶
func SetLevelLength(length uint8)
func SetPrefix ¶
func SetPrefix(prefix string)
SetPrefix sets the output prefix for the standard logger.
func SetWriteCloser ¶
func SetWriteCloser(writeCloser io.WriteCloser)
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func (*Logger) AddWriteCloser ¶
func (l *Logger) AddWriteCloser(writeClosers ...io.WriteCloser)
func (*Logger) AutoCallDepth ¶
func (l *Logger) AutoCallDepth()
func (*Logger) LevelLength ¶
func (*Logger) SetCallDepth ¶
func (*Logger) SetLevelLength ¶
func (*Logger) SetWriteCloser ¶
func (l *Logger) SetWriteCloser(writeCloser io.WriteCloser)
type Option ¶
type Option func(*Logger)
func WithAutoCallDepth ¶
func WithAutoCallDepth() Option
func WithCallDepth ¶
func WithLevelLength ¶
func WithMultiWriteCloser ¶
func WithMultiWriteCloser(writeClosers ...io.WriteCloser) Option
func WithMultiWriter ¶
func WithPrefix ¶
func WithWriteCloser ¶
func WithWriteCloser(writeCloser io.WriteCloser) Option
Click to show internal directories.
Click to hide internal directories.