-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* catch error log of http and reverse proxy handler, so logging ends up in the log instead of stderr * update change log * better description * add proper comments
- Loading branch information
Showing
5 changed files
with
43 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
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,30 @@ | ||
package logging | ||
|
||
import ( | ||
stdlog "log" | ||
) | ||
|
||
// StandardLogWriterInterface is an interface to wrap log.Logger | ||
type StandardLogWriterInterface interface { | ||
Write(p []byte) (n int, err error) | ||
} | ||
|
||
// StandardLogWrite implements StandardLogWriterInterface | ||
type StandardLogWrite struct { | ||
//buf bytes.Buffer | ||
name string | ||
} | ||
|
||
// Write is the write handler for StandardLog | ||
func (s StandardLogWrite) Write(p []byte) (n int, err error) { | ||
str := string(p) | ||
For(s.name).Warn(str) | ||
return len(p), nil | ||
} | ||
|
||
// StandardLog returns a log.Logger wrapper | ||
func StandardLog(name string) *stdlog.Logger { | ||
w := StandardLogWrite{name: name} | ||
std := stdlog.New(w, "", stdlog.Lshortfile) | ||
return std | ||
} |
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,9 @@ | ||
package logging | ||
|
||
import "testing" | ||
|
||
func TestStandardLogger(t *testing.T) { | ||
Configure("stdout", "debug") | ||
l := StandardLog("test/log") | ||
l.Print("log entry\n") | ||
} |
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
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