Update both github.com/gomiddleware/logit and github.com/gomiddleware/logger

parent af329ce4
......@@ -36,13 +36,13 @@
{
"importpath": "github.com/gomiddleware/logger",
"repository": "https://github.com/gomiddleware/logger",
"revision": "3e2e6ebe25c30b3c6f597d9dd83680326f53292a",
"revision": "a4a78606e8f0d2b3fd6ffca809ed68d870101741",
"branch": "master"
},
{
"importpath": "github.com/gomiddleware/logit",
"repository": "https://github.com/gomiddleware/logit",
"revision": "88a60009f3335763c0ef7410407a661ac1929618",
"revision": "9d0b354918cad6c85d6843a804fc54526e633b58",
"branch": "master"
},
{
......
......@@ -11,7 +11,8 @@ import (
func handler(lgr *logit.Logger) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
lgr := logger.LogFromRequest(r)
lgr.Log("inside handler")
lgr.Print("handler-start")
w.Write([]byte(r.URL.Path))
}
}
......
......@@ -82,7 +82,7 @@ func (l *Logger) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.WithField("method", r.Method)
log.WithField("uri", r.RequestURI)
log.WithField("id", sid.Id())
log.Log("request-start")
log.Print("request-start")
// continue to the next middleware
l.h.ServeHTTP(res, r.WithContext(ctx))
......@@ -91,7 +91,7 @@ func (l *Logger) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.WithField("status", res.status)
log.WithField("size", res.written)
log.WithField("duration", time.Since(start))
log.Log("request-end")
log.Print("request-end")
}
// LogFromRequest can be used to obtain the Log from the request.
......
......@@ -43,14 +43,14 @@ func (l *Logger) Clone(sys string) *Logger {
}
func (l *Logger) WithField(key string, value interface{}) {
if key == "time" {
panic("logit: key=time is not allowed")
if key == "ts" {
panic("logit: key=ts is not allowed")
}
if key == "sys" {
panic("logit: key=sys is not allowed")
}
if key == "msg" {
panic("logit: key=msg is not allowed")
if key == "evt" {
panic("logit: key=evt is not allowed")
}
if key == "err" {
panic("logit: key=err is not allowed")
......@@ -61,30 +61,39 @@ func (l *Logger) WithField(key string, value interface{}) {
l.fields[key] = value
}
// Log just logs a message to the output. It doesn't do anything special.
func (l *Logger) Log(msg string) error {
return l.Output(msg)
// Print just logs a message to the output. It doesn't do anything special.
func (l *Logger) Print(evt string) error {
return l.Output(evt)
}
// Fatal is equivalent to Log() followed by a call to os.Exit(1).
func (l *Logger) Fatal(msg string) {
l.Output(msg)
// Fatal is equivalent to Print() followed by a call to os.Exit(1).
func (l *Logger) Fatal(evt string) {
l.Output(evt)
os.Exit(1)
}
// Panic is equivalent to Print() followed by a call to panic(evt).
func (l *Logger) Panic(evt string) {
l.Output(evt)
panic(evt)
}
// Output writes the output for a logging event.
func (l *Logger) Output(msg string) error {
func (l *Logger) Output(evt string) error {
l.mu.Lock()
defer l.mu.Unlock()
// time
str := "time="
str := "ts="
str += time.Now().UTC().Format("20060102-150405.000000000")
str += " "
// sys
str += "sys=" + l.sys + " "
// message
str += "evt=" + evt
// now do all of the fields
for k, v := range l.fields {
switch vv := v.(type) {
......@@ -100,9 +109,6 @@ func (l *Logger) Output(msg string) error {
}
}
// message
str += "msg=" + msg
// newline
str += "\n"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment