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 yıl önce
config 175c9c9308 Updated config 8 yıl önce
errors 8fbd65327a Cleared up code to go dir. 8 yıl önce
log 8fbd65327a Cleared up code to go dir. 8 yıl önce
.gitignore 90a3e47fc8 Initial commit 8 yıl önce
LICENSE 90a3e47fc8 Initial commit 8 yıl önce
README.md 9cfc338e67 Init commit 8 yıl önce
main.go 9cfc338e67 Init commit 8 yıl önce

README.md

go-log

Make logging a charm and log whatever you want, whenever you want.

Simple usage

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!

How to adjust output level?

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

Flags?

Yes, now you can specify to your program what log-level you want

  1. Printed to screen: -llo (log level output)
  2. Stored to file: -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.

Nah, I dont want flags in my application.

Okey, set the variables manually by including the ./config, and call config.LLO.Set(config.INFO) or config.LLF.Set(config.TRACE).

Enjoy!