Easier and better logging in you Go-project. Take control of what to log and where to log and when to log. 3xWTL
Joachim M. Giæver 175c9c9308 Updated config | 8 年 前 | |
---|---|---|
config | 8 年 前 | |
errors | 8 年 前 | |
log | 8 年 前 | |
.gitignore | 8 年 前 | |
LICENSE | 8 年 前 | |
README.md | 8 年 前 | |
main.go | 8 年 前 |
Make logging a charm and log whatever you want, whenever you want.
Just include the package git.giaever.org/joachimmg/go-log.git/log
in the top of your file and start your logging, e.g:
log.Tracef("This is a %s-log", "trace")
log.Infof("This is a %s-log", "info")
log.Warningf("This is a %s-log", "warning")
log.Errorf("This is a %s-log", "error")
log.Panicf("This is a %s-log", "panic")
which gives you an output like
TRACE 2016/11/25 01:21:24.243863 This is a trace-log
INFO 2016/11/25 01:21:24.243993 This is a info-log
WARNING 2016/11/25 01:21:24.244005 This is a warning-log
ERROR 2016/11/25 01:21:24.244023 This is a error-log
Yes, Panic wont appear here as Error and Panic functions will end the program!
Well, you can parse the flags, e.g by importing flags into your application where log
is used. E.g:
import (
"flag"
"git.giaever.org/joachimmg/go-log.git/log"
)
func main() {
flag.Parse()
log.Trace("Will be shown if flag -llo TRACE is set and be stored into file if -llf TRACE is set")
}
Yes, now you can specify to your program what log-level you want
-llo
(log level output)-llf
(log level file)Example: `./my_app -llo INFO -llf TRACE" will print info, warning, error and panic logs, but not trace. Everyone (including trace logs) will be written to file.
Okey, set the variables manually by including the ./config, and call config.LLO.Set(config.INFO)
or config.LLF.Set(config.TRACE)
.
Enjoy!