summaryrefslogtreecommitdiff
path: root/plugins/logger/std_log_adapter.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-03-13 21:06:20 +0300
committerValery Piashchynski <[email protected]>2021-03-13 21:06:20 +0300
commit594d801d14bb394b20eec14690d1b616e2c4d56d (patch)
tree7643d6e74c69f078e704730a8217f3204654060d /plugins/logger/std_log_adapter.go
parentd3e3fba7ce313b9e9563cca35ebd6432a0fba6e4 (diff)
- Add ability to print http/https/fcgi to the rr logger under the Info
level - Update tests and CHANGELOG Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/logger/std_log_adapter.go')
-rw-r--r--plugins/logger/std_log_adapter.go31
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..d9a29451
--- /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.Info("server internal stderr", "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))
+}