https://github.com/manigandand/log
Yet another Go Logger
https://github.com/manigandand/log
codecov godoc golang golangci goreportcard log logdna logging loggly pappertrail travis-ci
Last synced: 10 months ago
JSON representation
Yet another Go Logger
- Host: GitHub
- URL: https://github.com/manigandand/log
- Owner: manigandand
- License: mit
- Created: 2019-10-07T02:29:41.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-11T12:00:27.000Z (over 6 years ago)
- Last Synced: 2025-04-30T17:04:37.383Z (10 months ago)
- Topics: codecov, godoc, golang, golangci, goreportcard, log, logdna, logging, loggly, pappertrail, travis-ci
- Language: Go
- Size: 10.7 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# log
[](https://goreportcard.com/report/github.com/manigandand/log)
[](https://golangci.com/r/github.com/manigandand/log)
[](https://github.com/manigandand/log/blob/master/LICENSE)
[](https://travis-ci.org/manigandand/log)
[](https://codecov.io/gh/manigandand/log)
[](https://godoc.org/github.com/manigandand/log)
Yet another Go Logger
log is simple extended version of standard 'log' package based on logLevel
most of the concepts inspired from [glog](https://godoc.org/github.com/golang/glog) and [tracelog](https://github.com/goinggo/tracelog) these packages are huge and complex.
Hence we writing our own log package with as simple as possible and extensible to third party logging systems such as Papertrail, Loggly, LogDNA.
```golang
package main
import (
"flag"
"io"
"time"
syslog "log"
"github.com/manigandand/log"
)
var (
logLevel = flag.String("log", "INFO",
"log-level for the app valid choice INFO, WARNING, ERROR, FATAL, PANIC")
papertrailAddr = flag.String("papertrail", "",
"with valid papertrail address starts logging on papertrail.")
)
func main() {
flag.Parse()
// init log
var multiWriter io.Writer
if *papertrailAddr != "" {
multiWriter = &log.Papertrail{Address: *papertrailAddr}
}
l, ok := log.Levels[*logLevel]
if !ok {
syslog.Fatal("log: invalid log-level")
}
log.Init(l, multiWriter)
// ex
log.Info("log info level example")
log.Infof("%s---%d", "time", time.Now().Unix())
log.Infoln("log info level example")
log.Warning("log info level example")
log.Warningf("%s---%d", "time", time.Now().Unix())
log.Warningln("log info level example")
log.Error("log info level example")
log.Errorf("%s---%d", "time", time.Now().Unix())
log.Errorln("log info level example")
log.Fatal("log info level example")
log.Fatalf("%s---%d", "time", time.Now().Unix())
log.Fatalln("log info level example")
log.Panic("log info level example")
log.Panicf("%s---%d", "time", time.Now().Unix())
log.Panicln("log info level example")
}
```
```Shell
INFO: 2019/10/07 18:37:20 main.go:35: log info level example
INFO: 2019/10/07 18:37:20 main.go:36: time---1570453640
INFO: 2019/10/07 18:37:20 main.go:37: log info level example
```
```Shell
WARNING: 2019/10/07 18:37:20 main.go:39: log info level example
WARNING: 2019/10/07 18:37:20 main.go:40: time---1570453640
WARNING: 2019/10/07 18:37:20 main.go:41: log info level example
```
```Shell
ERROR: 2019/10/07 18:37:20 main.go:43: log info level example
ERROR: 2019/10/07 18:37:20 main.go:44: time---1570453640
ERROR: 2019/10/07 18:37:20 main.go:45: log info level example
```
```Shell
FATAL: 2019/10/07 18:37:20 main.go:47: log info level example
exit status 1
```
```Shell
PANIC: 2019/10/07 18:37:20 main.go:47: log info level example
exit status 1
```
> TODO:
- Context based logging.
- github.com/sirupsen/logrus
- github.com/uber-go/zap
## Licence
MIT