diff options
author | Valery Piashchynski <[email protected]> | 2021-03-15 13:43:45 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-15 13:43:45 +0300 |
commit | 102e473110b9be0924193aeecd4b946a7053737e (patch) | |
tree | b2b0db47390741ff15884ec81b06626e4020fdb5 /plugins/logger/std_log_adapter.go | |
parent | c07594a931bd322fd5e7310357f1ab3f4be9c0c5 (diff) | |
parent | bb6acdaf8cf55a4df746c9d03f2c677fa85ea6ee (diff) |
Merge pull request #592 from spiral/missed_logger_for_the_http_server
🆕 new(http plugin): HTTP/HTTPS/FCGI servers errors redirected to the RR logger under the Error log level
Diffstat (limited to 'plugins/logger/std_log_adapter.go')
-rw-r--r-- | plugins/logger/std_log_adapter.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/plugins/logger/std_log_adapter.go b/plugins/logger/std_log_adapter.go new file mode 100644 index 00000000..484cc23e --- /dev/null +++ b/plugins/logger/std_log_adapter.go @@ -0,0 +1,31 @@ +package logger + +import ( + "unsafe" +) + +// StdLogAdapter can be passed to the http.Server or any place which required standard logger to redirect output +// to the logger plugin +type StdLogAdapter struct { + log Logger +} + +// Write io.Writer interface implementation +func (s *StdLogAdapter) Write(p []byte) (n int, err error) { + s.log.Error("server internal error", "message", toString(p)) + return len(p), nil +} + +// NewStdAdapter constructs StdLogAdapter +func NewStdAdapter(log Logger) *StdLogAdapter { + logAdapter := &StdLogAdapter{ + log: log, + } + + return logAdapter +} + +// unsafe, but lightning fast []byte to string conversion +func toString(data []byte) string { + return *(*string)(unsafe.Pointer(&data)) +} |