Files
reproxy/examples/plugin/vendor/github.com/go-pkgz/lgr/adaptor.go
Umputun 7139c57766 RPC plugins support (#85)
* wip

* resolve merge artifacts

* full coverage for conductor

* wire plugin conductor to main and proxy

* wip, with separate match handler

* split matching logic with another handler, add initial docs

* move parts of proxy to handlers, add tests

* add headers in to be sent to proxied url

* merged from master

* add example with docker compose

* supress excesive debug reporting 0-9 disabled in docker

* add plugin tests

* randomize test port

* lint: minor warns

* lint: err shadow
2021-06-01 02:56:39 -05:00

42 lines
988 B
Go

package lgr
import (
"log"
"strings"
)
// Writer holds lgr.L and wraps with io.Writer interface
type Writer struct {
L
level string // if defined added to each message
}
// Write to lgr.L
func (w *Writer) Write(p []byte) (n int, err error) {
w.Logf(w.level + string(p))
return len(p), nil
}
// ToWriter makes io.Writer for given lgr.L with optional level
func ToWriter(l L, level string) *Writer {
if level != "" && !strings.HasSuffix(level, " ") {
level += " "
}
return &Writer{l, level}
}
// ToStdLogger makes standard logger
func ToStdLogger(l L, level string) *log.Logger {
return log.New(ToWriter(l, level), "", 0)
}
// SetupStdLogger makes the default std logger with lgr.L
func SetupStdLogger(opts ...Option) {
logOpts := append([]Option{CallerDepth(3)}, opts...) // skip 3 more frames to compensate stdlog calls
l := New(logOpts...)
l.reTrace = reTraceStd // std logger split on log/ path
log.SetOutput(ToWriter(l, ""))
log.SetPrefix("")
log.SetFlags(0)
}