glog

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2020 License: GPL-3.0 Imports: 8 Imported by: 7

README

Golang log library

godoc build status

Package glog implements a log infrastructure for Go.

Example

Let's have a look at an example which demonstrates most of the features found in this library.

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")
}

Installing

Using go get

$ go get github.com/CodyGuo/glog

You can use go get -u to update the package.

Go test

$ go test -bench . -benchmem

image

Documentation

For docs, see http://godoc.org/github.com/CodyGuo/glog or run:

$ godoc github.com/CodyGuo/glog

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

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

Functions

func AddFile

func AddFile(name string, flag int, perm os.FileMode) error

func AddOutput

func AddOutput(writers ...io.Writer)

func AddWriteCloser

func AddWriteCloser(writeClosers ...io.WriteCloser)

func AutoCallDepth

func AutoCallDepth()

func CallDepth

func CallDepth() int

func Close

func Close() error

func Critical

func Critical(v ...interface{})

func Criticalf

func Criticalf(format string, v ...interface{})

func Debug

func Debug(v ...interface{})

func Debugf

func Debugf(format string, v ...interface{})

func Error

func Error(v ...interface{})

func Errorf

func Errorf(format string, v ...interface{})

func Fatal

func Fatal(v ...interface{})

func Fatalf

func Fatalf(format string, v ...interface{})

func Flags

func Flags() int

Flags returns the output flags for the standard logger. The flag bits are Ldate, Ltime, and so on.

func Info

func Info(v ...interface{})

func Infof

func Infof(format string, v ...interface{})

func LevelLength

func LevelLength() uint8

func Notice

func Notice(v ...interface{})

func Noticef

func Noticef(format string, v ...interface{})

func Output

func Output(level Level, format string, v ...interface{}) error

func Panic added in v1.0.5

func Panic(v ...interface{})

func Panicf added in v1.0.5

func Panicf(format string, v ...interface{})

func Prefix

func Prefix() string

Prefix returns the output prefix for the standard logger.

func ResetCallDepth

func ResetCallDepth()

func SetCallDepth

func SetCallDepth(calldepth int)

func SetFile

func SetFile(name string, flag int, perm os.FileMode) error

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 SetLevel

func SetLevel(level Level)

func SetLevelLength

func SetLevelLength(length uint8)

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output destination for the standard logger.

func SetPrefix

func SetPrefix(prefix string)

SetPrefix sets the output prefix for the standard logger.

func SetWriteCloser

func SetWriteCloser(writeCloser io.WriteCloser)

func Trace

func Trace(v ...interface{})

func Tracef

func Tracef(format string, v ...interface{})

func Warn

func Warn(v ...interface{})

func Warnf

func Warnf(format string, v ...interface{})

func Warning

func Warning(v ...interface{})

func Warningf

func Warningf(format string, v ...interface{})

func Writer

func Writer() io.Writer

Writer returns the output destination for the standard logger.

Types

type Fields added in v1.0.6

type Fields map[string]interface{}

type Level

type Level uint32
const (
	TRACE Level = iota
	DEBUG
	INFO
	NOTICE
	WARNING
	ERROR
	CRITICAL
	FATAL
	PANIC
)

func GetLevel

func GetLevel() Level

func (Level) Len

func (l Level) Len() uint8

func (Level) String

func (l Level) String() string

type Logger

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

func New

func New(out io.Writer, options ...Option) *Logger

func (*Logger) AddFile

func (l *Logger) AddFile(name string, flag int, perm os.FileMode) error

func (*Logger) AddOutput

func (l *Logger) AddOutput(writers ...io.Writer)

func (*Logger) AddWriteCloser

func (l *Logger) AddWriteCloser(writeClosers ...io.WriteCloser)

func (*Logger) AutoCallDepth

func (l *Logger) AutoCallDepth()

func (*Logger) CallDepth

func (l *Logger) CallDepth() int

func (*Logger) Close

func (l *Logger) Close() error

func (*Logger) Critical

func (l *Logger) Critical(v ...interface{})

func (*Logger) Criticalf

func (l *Logger) Criticalf(format string, v ...interface{})

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{})

func (*Logger) Debugf

func (l *Logger) Debugf(format string, v ...interface{})

func (*Logger) Error

func (l *Logger) Error(v ...interface{})

func (*Logger) Errorf

func (l *Logger) Errorf(format string, v ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(v ...interface{})

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, v ...interface{})

func (*Logger) Flags

func (l *Logger) Flags() int

func (*Logger) Info

func (l *Logger) Info(v ...interface{})

func (*Logger) Infof

func (l *Logger) Infof(format string, v ...interface{})

func (*Logger) Level

func (l *Logger) Level() Level

func (*Logger) LevelLength

func (l *Logger) LevelLength() uint8

func (*Logger) Notice

func (l *Logger) Notice(v ...interface{})

func (*Logger) Noticef

func (l *Logger) Noticef(format string, v ...interface{})

func (*Logger) Output

func (l *Logger) Output(level Level, format string, v ...interface{}) error

func (*Logger) Panic added in v1.0.5

func (l *Logger) Panic(v ...interface{})

func (*Logger) Panicf added in v1.0.5

func (l *Logger) Panicf(format string, v ...interface{})

func (*Logger) Prefix

func (l *Logger) Prefix() string

func (*Logger) SetCallDepth

func (l *Logger) SetCallDepth(calldepath int)

func (*Logger) SetFile

func (l *Logger) SetFile(name string, flag int, perm os.FileMode) error

func (*Logger) SetFlags

func (l *Logger) SetFlags(flag int)

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

func (*Logger) SetLevelLength

func (l *Logger) SetLevelLength(length uint8)

func (*Logger) SetOutput

func (l *Logger) SetOutput(w io.Writer)

func (*Logger) SetPrefix

func (l *Logger) SetPrefix(prefix string)

func (*Logger) SetWriteCloser

func (l *Logger) SetWriteCloser(writeCloser io.WriteCloser)

func (*Logger) Trace

func (l *Logger) Trace(v ...interface{})

func (*Logger) Tracef

func (l *Logger) Tracef(format string, v ...interface{})

func (*Logger) Warn

func (l *Logger) Warn(v ...interface{})

func (*Logger) Warnf

func (l *Logger) Warnf(format string, v ...interface{})

func (*Logger) Warning

func (l *Logger) Warning(v ...interface{})

func (*Logger) Warningf

func (l *Logger) Warningf(format string, v ...interface{})

func (*Logger) Writer

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

type Option

type Option func(*Logger)

func WithAutoCallDepth

func WithAutoCallDepth() Option

func WithCallDepth

func WithCallDepth(calldepth int) Option

func WithFile

func WithFile(name string, flag int, perm os.FileMode) Option

func WithFlags

func WithFlags(flag int) Option

func WithLevel

func WithLevel(level Level) Option

func WithLevelLength

func WithLevelLength(levelLength uint8) Option

func WithMultiWriteCloser

func WithMultiWriteCloser(writeClosers ...io.WriteCloser) Option

func WithMultiWriter

func WithMultiWriter(writers ...io.Writer) Option

func WithPrefix

func WithPrefix(prefix string) Option

func WithWriteCloser

func WithWriteCloser(writeCloser io.WriteCloser) Option

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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