A small logging package with env + programmatic configuration.
- DEBUG / INFO / WARN / ERROR
- Default is INFO (DEBUG is hidden)
GOLOG_LOG_LEVEL=DEBUGshows all logs.
GOLOG_OUTPUT supports: stdout, stderr, file, combined with +.
Examples:
export GOLOG_OUTPUT="stderr"export GOLOG_OUTPUT="stderr+file"export GOLOG_FILE="/path/to/app.log"
Special rule:
- If you set only
GOLOG_FILE(and do NOT setGOLOG_OUTPUT), logs go to file only (not stderr).
export GOLOG_LOG_FMT="text"-> text logs- default -> json
import "github.com/Brian44913/logging"
func main() {
logging.SetLogLevel("DEBUG")
logging.SetLogFmt("json")
logging.SetLogFile("/tmp/app.log")
logging.SetOutput("stderr+file")
name := "Jack"
age := 18
err := fmt.Errorf("boom")
logging.Info("msg", "name", name, "age", age, err)
a := `{"a":"b"}`
logging.Info("This is test information.", a)
}