summaryrefslogtreecommitdiff
path: root/plugins/logger
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
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')
-rw-r--r--plugins/logger/interface.go16
-rw-r--r--plugins/logger/std_log_adapter.go31
2 files changed, 38 insertions, 9 deletions
diff --git a/plugins/logger/interface.go b/plugins/logger/interface.go
index 876629a9..5bb2143b 100644
--- a/plugins/logger/interface.go
+++ b/plugins/logger/interface.go
@@ -1,14 +1,12 @@
package logger
-type (
- // Logger is an general RR log interface
- Logger interface {
- Debug(msg string, keyvals ...interface{})
- Info(msg string, keyvals ...interface{})
- Warn(msg string, keyvals ...interface{})
- Error(msg string, keyvals ...interface{})
- }
-)
+// Logger is an general RR log interface
+type Logger interface {
+ Debug(msg string, keyvals ...interface{})
+ Info(msg string, keyvals ...interface{})
+ Warn(msg string, keyvals ...interface{})
+ Error(msg string, keyvals ...interface{})
+}
// With creates a child logger and adds structured context to it
type WithLogger interface {
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))
+}