-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christian Arnheiter
committed
Jan 28, 2021
0 parents
commit 76a01f2
Showing
3 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/bin/ | ||
.idea/ | ||
/config/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module "github.com/z26100/log-go" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) | ||
} |