From 76a01f2e7d705c5a238e0938174469ee8dc20afc Mon Sep 17 00:00:00 2001 From: Christian Arnheiter Date: Thu, 28 Jan 2021 12:33:38 +0100 Subject: [PATCH] Initial commit --- .gitignore | 3 ++ go.mod | 1 + log.go | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 .gitignore create mode 100644 go.mod create mode 100644 log.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e0471e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/bin/ +.idea/ +/config/ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..964d024 --- /dev/null +++ b/go.mod @@ -0,0 +1 @@ +module "github.com/z26100/log-go" \ No newline at end of file diff --git a/log.go b/log.go new file mode 100644 index 0000000..135795e --- /dev/null +++ b/log.go @@ -0,0 +1,89 @@ +package log + +import ( + "log" + "net/http" +) + +type LogLevelType int + +const ( + TRACE LogLevelType = iota + DEBUG + INFO + WARN + ERROR + FATAL +) + +var ( + LogLevel = INFO +) + +func Println(args ...interface{}) { + Infoln(args) +} +func Printf(format string, args ...interface{}) { + Infof(format, args) +} + + +func Fatalln (args ...interface{}) { + if LogLevel <= FATAL { log.Fatal(args)} +} +func Fatalf (format string, args ...interface{}) { + if LogLevel <= FATAL { log.Fatal(format, args)} +} + + +func Errorln (args ...interface{}) { + if LogLevel <= ERROR { log.Println(args)} +} +func Errorf (format string, args ...interface{}) { + if LogLevel <= ERROR { log.Printf(format, args)} +} + + +func Warnln (args ...interface{}) { + if LogLevel <= WARN { log.Println(args)} +} +func Warnf (format string, args ...interface{}) { + if LogLevel <= WARN { log.Printf(format, args)} +} + + +func Infoln (args ...interface{}) { + if LogLevel <= INFO { log.Println(args)} +} +func Infof (format string, args ...interface{}) { + if LogLevel <= INFO { log.Printf(format, args)} +} + +func Debugln( args ...interface{}) { + if LogLevel <= DEBUG { log.Println(args)} +} +func Debugf(format string, args ...interface{}) { + if LogLevel <= DEBUG { log.Printf(format, args)} +} + +func Traceln( args ...interface{}) { + if LogLevel <= TRACE { log.Println(args)} +} +func Tracef(format string, args ...interface{}) { + if LogLevel <= TRACE { log.Printf(format, args)} +} + + +func Error(args ...interface{}) { + log.Println(args) +} + +func Fatal(err error) { + log.Fatal(err) +} +func Handler (handler http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + Debugln("http request", r.Method, r.URL) + handler.ServeHTTP(w, r) + }) +}