8000 GitHub - nordborn/golog at v2.0.0
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
/ golog Public

Package golog is a logging package that I'd like to be initially in Go's (Golang) standard library: it's a simple logging tool with levels and different outputs for info and error messages.

License

Notifications You must be signed in to change notification settings

nordborn/golog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Package golog is a logging package that I'd like to be initially in Go's (Golang) standard library: it's a simple logging tool with levels and different outputs for info and error messages.

So, you can use "golog" for all

Package "golog" provides loggerGlobal and Logger (custom logger) which support:

  1. Levels:
  • trace (Trace(), Tracef(), Traceln());
  • debug (Debug(), Debugf(), Debugln());
  • info (Info(), Infof(), Infoln(), Print(), Printf(), Println();
  • warning (Warning(), Warningf(), Warningln());
  • error (Error(), Errorf(), Errorln());
  • critical (Critical(), Criticalf(), Criticalln());
  • panic (Panic(), Panicf(), Panicln());
  • fatal (Fatal(), Fatalf(), Fatalln()).
  1. Different outputs:
  • for info-like messages (Trace, Debug, Info, Warning) - os.Stdout by default;
  • for error-like messages (Error, Critical, Panic, Fatal) - os.Stderr by default.

You can set:

  1. logging level (Level 5F9F Trace, LevelDebug, LevelInfo, LevelWarning, LevelError, LevelCritical). In this case, messages from the lower level will be omitted - LevelTrace by default;
  2. custom prefix (e.g. "myapp: ") additionally to level prefixes ("main: " by default);
  3. output io.Writer interfaces:
  • l.outWriter for Trace-Warning (os.Stdout by default);
  • l.errWriter for Error-Fatal (os.Stderr by default).

You can use SetFlags() similar to "log" from standard library for time and file information ("2018/11/26 16:57:49 golog.go:61" by default).

You can change level prefixes (defaults are TRC, DBG, INF, ERR, CRT, PNC, FTL) but don't do it if you don't need it really.

Also, "golog" uses same position conventions as "log": all prefixes are placed before time info.

So, common message using golog.Infoln("Started") will be:

[INF] main: 2018/11/26 16:57:49 main.go:61: Started

Tip: in common usage if you don't know which messages you should use, use Infoln() and Errorln().

Enjoy!

About

Package golog is a logging package that I'd like to be initially in Go's (Golang) standard library: it's a simple logging tool with levels and different outputs for info and error messages.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0