mirror of
https://github.com/go-micro/go-micro.git
synced 2025-11-29 21:47:44 +02:00
feat(logger): add logger option to all micro components (override DefaultLogger) closes #2556 (#2559)
* feat(logger): add logger option to all components * fix: refactor api/rpc.go * fix: refactor api/stream.go * fix: api/options.go comment * fix(logger): do not use logger.Helper internally * fix(logger): fix comments * fix(logger): use level.Enabled method * fix: rename mlogger to log * fix: run go fmt * fix: log level * fix: factories Co-authored-by: Mohamed MHAMDI <mmhamdi@hubside.com> Co-authored-by: Davincible <david.brouwer.99@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package router
|
||||
import (
|
||||
"go-micro.dev/v4/api/resolver"
|
||||
"go-micro.dev/v4/api/resolver/vpath"
|
||||
"go-micro.dev/v4/logger"
|
||||
"go-micro.dev/v4/registry"
|
||||
)
|
||||
|
||||
@@ -10,6 +11,7 @@ type Options struct {
|
||||
Handler string
|
||||
Registry registry.Registry
|
||||
Resolver resolver.Resolver
|
||||
Logger logger.Logger
|
||||
}
|
||||
|
||||
type Option func(o *Options)
|
||||
@@ -18,6 +20,7 @@ func NewOptions(opts ...Option) Options {
|
||||
options := Options{
|
||||
Handler: "meta",
|
||||
Registry: registry.DefaultRegistry,
|
||||
Logger: logger.DefaultLogger,
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
@@ -50,3 +53,10 @@ func WithResolver(r resolver.Resolver) Option {
|
||||
o.Resolver = r
|
||||
}
|
||||
}
|
||||
|
||||
// WithLogger sets the underline logger
|
||||
func WithLogger(l logger.Logger) Option {
|
||||
return func(o *Options) {
|
||||
o.Logger = l
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
"go-micro.dev/v4/api/router"
|
||||
"go-micro.dev/v4/api/router/util"
|
||||
"go-micro.dev/v4/logger"
|
||||
log "go-micro.dev/v4/logger"
|
||||
"go-micro.dev/v4/metadata"
|
||||
"go-micro.dev/v4/registry"
|
||||
"go-micro.dev/v4/registry/cache"
|
||||
@@ -51,14 +51,13 @@ func (r *registryRouter) isStopped() bool {
|
||||
// refresh list of api services
|
||||
func (r *registryRouter) refresh() {
|
||||
var attempts int
|
||||
logger := r.Options().Logger
|
||||
|
||||
for {
|
||||
services, err := r.opts.Registry.ListServices()
|
||||
if err != nil {
|
||||
attempts++
|
||||
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
|
||||
logger.Errorf("unable to list services: %v", err)
|
||||
}
|
||||
logger.Logf(log.ErrorLevel, "unable to list services: %v", err)
|
||||
time.Sleep(time.Duration(attempts) * time.Second)
|
||||
continue
|
||||
}
|
||||
@@ -69,9 +68,7 @@ func (r *registryRouter) refresh() {
|
||||
for _, s := range services {
|
||||
service, err := r.rc.GetService(s.Name)
|
||||
if err != nil {
|
||||
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
|
||||
logger.Errorf("unable to get service: %v", err)
|
||||
}
|
||||
logger.Logf(log.ErrorLevel, "unable to get service: %v", err)
|
||||
continue
|
||||
}
|
||||
r.store(service)
|
||||
@@ -89,6 +86,7 @@ func (r *registryRouter) refresh() {
|
||||
|
||||
// process watch event
|
||||
func (r *registryRouter) process(res *registry.Result) {
|
||||
logger := r.Options().Logger
|
||||
// skip these things
|
||||
if res == nil || res.Service == nil {
|
||||
return
|
||||
@@ -97,9 +95,7 @@ func (r *registryRouter) process(res *registry.Result) {
|
||||
// get entry from cache
|
||||
service, err := r.rc.GetService(res.Service.Name)
|
||||
if err != nil {
|
||||
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
|
||||
logger.Errorf("unable to get service: %v", err)
|
||||
}
|
||||
logger.Logf(log.ErrorLevel, "unable to get service: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -109,6 +105,7 @@ func (r *registryRouter) process(res *registry.Result) {
|
||||
|
||||
// store local endpoint cache
|
||||
func (r *registryRouter) store(services []*registry.Service) {
|
||||
logger := r.Options().Logger
|
||||
// endpoints
|
||||
eps := map[string]*router.Route{}
|
||||
|
||||
@@ -129,9 +126,7 @@ func (r *registryRouter) store(services []*registry.Service) {
|
||||
|
||||
// if we got nothing skip
|
||||
if err := router.Validate(end); err != nil {
|
||||
if logger.V(logger.TraceLevel, logger.DefaultLogger) {
|
||||
logger.Tracef("endpoint validation failed: %v", err)
|
||||
}
|
||||
logger.Logf(log.TraceLevel, "endpoint validation failed: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -176,9 +171,7 @@ func (r *registryRouter) store(services []*registry.Service) {
|
||||
}
|
||||
hostreg, err := regexp.CompilePOSIX(h)
|
||||
if err != nil {
|
||||
if logger.V(logger.TraceLevel, logger.DefaultLogger) {
|
||||
logger.Tracef("endpoint have invalid host regexp: %v", err)
|
||||
}
|
||||
logger.Logf(log.TraceLevel, "endpoint have invalid host regexp: %v", err)
|
||||
continue
|
||||
}
|
||||
cep.hostregs = append(cep.hostregs, hostreg)
|
||||
@@ -197,20 +190,16 @@ func (r *registryRouter) store(services []*registry.Service) {
|
||||
|
||||
rule, err := util.Parse(p)
|
||||
if err != nil && !pcreok {
|
||||
if logger.V(logger.TraceLevel, logger.DefaultLogger) {
|
||||
logger.Tracef("endpoint have invalid path pattern: %v", err)
|
||||
}
|
||||
logger.Logf(log.TraceLevel, "endpoint have invalid path pattern: %v", err)
|
||||
continue
|
||||
} else if err != nil && pcreok {
|
||||
continue
|
||||
}
|
||||
|
||||
tpl := rule.Compile()
|
||||
pathreg, err := util.NewPattern(tpl.Version, tpl.OpCodes, tpl.Pool, "")
|
||||
pathreg, err := util.NewPattern(tpl.Version, tpl.OpCodes, tpl.Pool, "", util.PatternLogger(logger))
|
||||
if err != nil {
|
||||
if logger.V(logger.TraceLevel, logger.DefaultLogger) {
|
||||
logger.Tracef("endpoint have invalid path pattern: %v", err)
|
||||
}
|
||||
logger.Logf(log.TraceLevel, "endpoint have invalid path pattern: %v", err)
|
||||
continue
|
||||
}
|
||||
cep.pathregs = append(cep.pathregs, pathreg)
|
||||
@@ -223,6 +212,7 @@ func (r *registryRouter) store(services []*registry.Service) {
|
||||
// watch for endpoint changes
|
||||
func (r *registryRouter) watch() {
|
||||
var attempts int
|
||||
logger := r.Options().Logger
|
||||
|
||||
for {
|
||||
if r.isStopped() {
|
||||
@@ -233,9 +223,7 @@ func (r *registryRouter) watch() {
|
||||
w, err := r.opts.Registry.Watch()
|
||||
if err != nil {
|
||||
attempts++
|
||||
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
|
||||
logger.Errorf("error watching endpoints: %v", err)
|
||||
}
|
||||
logger.Logf(log.ErrorLevel, "error watching endpoints: %v", err)
|
||||
time.Sleep(time.Duration(attempts) * time.Second)
|
||||
continue
|
||||
}
|
||||
@@ -258,9 +246,7 @@ func (r *registryRouter) watch() {
|
||||
// process next event
|
||||
res, err := w.Next()
|
||||
if err != nil {
|
||||
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
|
||||
logger.Errorf("error getting next endoint: %v", err)
|
||||
}
|
||||
logger.Logf(log.ErrorLevel, "error getting next endoint: %v", err)
|
||||
close(ch)
|
||||
break
|
||||
}
|
||||
@@ -293,6 +279,7 @@ func (r *registryRouter) Deregister(ep *router.Route) error {
|
||||
}
|
||||
|
||||
func (r *registryRouter) Endpoint(req *http.Request) (*router.Route, error) {
|
||||
logger := r.Options().Logger
|
||||
if r.isStopped() {
|
||||
return nil, errors.New("router closed")
|
||||
}
|
||||
@@ -325,9 +312,8 @@ func (r *registryRouter) Endpoint(req *http.Request) (*router.Route, error) {
|
||||
if !mMatch {
|
||||
continue
|
||||
}
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("api method match %s", req.Method)
|
||||
}
|
||||
|
||||
logger.Logf(log.DebugLevel, "api method match %s", req.Method)
|
||||
|
||||
// 2. try host
|
||||
if len(ep.Host) == 0 {
|
||||
@@ -348,22 +334,17 @@ func (r *registryRouter) Endpoint(req *http.Request) (*router.Route, error) {
|
||||
if !hMatch {
|
||||
continue
|
||||
}
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("api host match %s", req.URL.Host)
|
||||
}
|
||||
|
||||
logger.Logf(log.DebugLevel, "api host match %s", req.URL.Host)
|
||||
|
||||
// 3. try path via google.api path matching
|
||||
for _, pathreg := range cep.pathregs {
|
||||
matches, err := pathreg.Match(path, "")
|
||||
if err != nil {
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("api gpath not match %s != %v", path, pathreg)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "api gpath not match %s != %v", path, pathreg)
|
||||
continue
|
||||
}
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("api gpath match %s = %v", path, pathreg)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "api gpath match %s = %v", path, pathreg)
|
||||
pMatch = true
|
||||
ctx := req.Context()
|
||||
md, ok := metadata.FromContext(ctx)
|
||||
@@ -381,14 +362,10 @@ func (r *registryRouter) Endpoint(req *http.Request) (*router.Route, error) {
|
||||
// 4. try path via pcre path matching
|
||||
for _, pathreg := range cep.pcreregs {
|
||||
if !pathreg.MatchString(req.URL.Path) {
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("api pcre path not match %s != %v", path, pathreg)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "api pcre path not match %s != %v", path, pathreg)
|
||||
continue
|
||||
}
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("api pcre path match %s != %v", path, pathreg)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "api pcre path match %s != %v", path, pathreg)
|
||||
pMatch = true
|
||||
break
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
"go-micro.dev/v4/api/router"
|
||||
"go-micro.dev/v4/api/router/util"
|
||||
"go-micro.dev/v4/logger"
|
||||
log "go-micro.dev/v4/logger"
|
||||
"go-micro.dev/v4/metadata"
|
||||
"go-micro.dev/v4/registry"
|
||||
rutil "go-micro.dev/v4/util/registry"
|
||||
@@ -129,7 +129,7 @@ func (r *staticRouter) Register(route *router.Route) error {
|
||||
}
|
||||
|
||||
tpl := rule.Compile()
|
||||
pathreg, err := util.NewPattern(tpl.Version, tpl.OpCodes, tpl.Pool, "")
|
||||
pathreg, err := util.NewPattern(tpl.Version, tpl.OpCodes, tpl.Pool, "", util.PatternLogger(r.Options().Logger))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -222,6 +222,7 @@ func (r *staticRouter) Endpoint(req *http.Request) (*router.Route, error) {
|
||||
}
|
||||
|
||||
func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) {
|
||||
logger := r.Options().Logger
|
||||
if r.isStopd() {
|
||||
return nil, errors.New("router closed")
|
||||
}
|
||||
@@ -250,9 +251,7 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) {
|
||||
if !mMatch {
|
||||
continue
|
||||
}
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("api method match %s", req.Method)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "api method match %s", req.Method)
|
||||
|
||||
// 2. try host
|
||||
if len(ep.apiep.Host) == 0 {
|
||||
@@ -273,22 +272,16 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) {
|
||||
if !hMatch {
|
||||
continue
|
||||
}
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("api host match %s", req.URL.Host)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "api host match %s", req.URL.Host)
|
||||
|
||||
// 3. try google.api path
|
||||
for _, pathreg := range ep.pathregs {
|
||||
matches, err := pathreg.Match(path, "")
|
||||
if err != nil {
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("api gpath not match %s != %v", path, pathreg)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "api gpath not match %s != %v", path, pathreg)
|
||||
continue
|
||||
}
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("api gpath match %s = %v", path, pathreg)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "api gpath match %s = %v", path, pathreg)
|
||||
pMatch = true
|
||||
ctx := req.Context()
|
||||
md, ok := metadata.FromContext(ctx)
|
||||
@@ -306,9 +299,7 @@ func (r *staticRouter) endpoint(req *http.Request) (*endpoint, error) {
|
||||
// 4. try path via pcre path matching
|
||||
for _, pathreg := range ep.pcreregs {
|
||||
if !pathreg.MatchString(req.URL.Path) {
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("api pcre path not match %s != %v", req.URL.Path, pathreg)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "api pcre path not match %s != %v", req.URL.Path, pathreg)
|
||||
continue
|
||||
}
|
||||
pMatch = true
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"go-micro.dev/v4/logger"
|
||||
log "go-micro.dev/v4/logger"
|
||||
)
|
||||
|
||||
// InvalidTemplateError indicates that the path template is not valid.
|
||||
@@ -98,38 +98,36 @@ func tokenize(path string) (tokens []string, verb string) {
|
||||
type parser struct {
|
||||
tokens []string
|
||||
accepted []string
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
// topLevelSegments is the target of this parser.
|
||||
func (p *parser) topLevelSegments() ([]segment, error) {
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("Parsing %q", p.tokens)
|
||||
}
|
||||
logger := log.LoggerOrDefault(p.logger)
|
||||
|
||||
logger.Logf(log.DebugLevel, "Parsing %q", p.tokens)
|
||||
|
||||
segs, err := p.segments()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("accept segments: %q; %q", p.accepted, p.tokens)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "accept segments: %q; %q", p.accepted, p.tokens)
|
||||
if _, err := p.accept(typeEOF); err != nil {
|
||||
return nil, fmt.Errorf("unexpected token %q after segments %q", p.tokens[0], strings.Join(p.accepted, ""))
|
||||
}
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("accept eof: %q; %q", p.accepted, p.tokens)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "accept eof: %q; %q", p.accepted, p.tokens)
|
||||
return segs, nil
|
||||
}
|
||||
|
||||
func (p *parser) segments() ([]segment, error) {
|
||||
logger := log.LoggerOrDefault(p.logger)
|
||||
s, err := p.segment()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("accept segment: %q; %q", p.accepted, p.tokens)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "accept segment: %q; %q", p.accepted, p.tokens)
|
||||
|
||||
segs := []segment{s}
|
||||
for {
|
||||
if _, err := p.accept("/"); err != nil {
|
||||
@@ -140,9 +138,7 @@ func (p *parser) segments() ([]segment, error) {
|
||||
return segs, err
|
||||
}
|
||||
segs = append(segs, s)
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("accept segment: %q; %q", p.accepted, p.tokens)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "accept segment: %q; %q", p.accepted, p.tokens)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,11 +266,12 @@ func (p *parser) accept(term termType) (string, error) {
|
||||
// expectPChars determines if "t" consists of only pchars defined in RFC3986.
|
||||
//
|
||||
// https://www.ietf.org/rfc/rfc3986.txt, P.49
|
||||
// pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
||||
// unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
||||
// sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
||||
// / "*" / "+" / "," / ";" / "="
|
||||
// pct-encoded = "%" HEXDIG HEXDIG
|
||||
//
|
||||
// pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
||||
// unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
||||
// sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
||||
// / "*" / "+" / "," / ";" / "="
|
||||
// pct-encoded = "%" HEXDIG HEXDIG
|
||||
func expectPChars(t string) error {
|
||||
const (
|
||||
init = iota
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"go-micro.dev/v4/logger"
|
||||
log "go-micro.dev/v4/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -43,11 +43,19 @@ type Pattern struct {
|
||||
|
||||
type patternOptions struct {
|
||||
assumeColonVerb bool
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
// PatternOpt is an option for creating Patterns.
|
||||
type PatternOpt func(*patternOptions)
|
||||
|
||||
// Logger sets the logger
|
||||
func PatternLogger(l log.Logger) PatternOpt {
|
||||
return func(po *patternOptions) {
|
||||
po.logger = l
|
||||
}
|
||||
}
|
||||
|
||||
// NewPattern returns a new Pattern from the given definition values.
|
||||
// "ops" is a sequence of op codes. "pool" is a constant pool.
|
||||
// "verb" is the verb part of the pattern. It is empty if the pattern does not have the part.
|
||||
@@ -61,18 +69,16 @@ func NewPattern(version int, ops []int, pool []string, verb string, opts ...Patt
|
||||
o(&options)
|
||||
}
|
||||
|
||||
logger := log.LoggerOrDefault(options.logger)
|
||||
|
||||
if version != 1 {
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("unsupported version: %d", version)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "unsupported version: %d", version)
|
||||
return Pattern{}, ErrInvalidPattern
|
||||
}
|
||||
|
||||
l := len(ops)
|
||||
if l%2 != 0 {
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("odd number of ops codes: %d", l)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "odd number of ops codes: %d", l)
|
||||
return Pattern{}, ErrInvalidPattern
|
||||
}
|
||||
|
||||
@@ -95,18 +101,14 @@ func NewPattern(version int, ops []int, pool []string, verb string, opts ...Patt
|
||||
stack++
|
||||
case OpPushM:
|
||||
if pushMSeen {
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debug("pushM appears twice")
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "pushM appears twice")
|
||||
return Pattern{}, ErrInvalidPattern
|
||||
}
|
||||
pushMSeen = true
|
||||
stack++
|
||||
case OpLitPush:
|
||||
if op.operand < 0 || len(pool) <= op.operand {
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("negative literal index: %d", op.operand)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "negative literal index: %d", op.operand)
|
||||
return Pattern{}, ErrInvalidPattern
|
||||
}
|
||||
if pushMSeen {
|
||||
@@ -115,24 +117,18 @@ func NewPattern(version int, ops []int, pool []string, verb string, opts ...Patt
|
||||
stack++
|
||||
case OpConcatN:
|
||||
if op.operand <= 0 {
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("negative concat size: %d", op.operand)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "negative concat size: %d", op.operand)
|
||||
return Pattern{}, ErrInvalidPattern
|
||||
}
|
||||
stack -= op.operand
|
||||
if stack < 0 {
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debug("stack underflow")
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "stack underflow")
|
||||
return Pattern{}, ErrInvalidPattern
|
||||
}
|
||||
stack++
|
||||
case OpCapture:
|
||||
if op.operand < 0 || len(pool) <= op.operand {
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("variable name index out of bound: %d", op.operand)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "variable name index out of bound: %d", op.operand)
|
||||
return Pattern{}, ErrInvalidPattern
|
||||
}
|
||||
v := pool[op.operand]
|
||||
@@ -140,15 +136,11 @@ func NewPattern(version int, ops []int, pool []string, verb string, opts ...Patt
|
||||
vars = append(vars, v)
|
||||
stack--
|
||||
if stack < 0 {
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debug("stack underflow")
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "stack underflow")
|
||||
return Pattern{}, ErrInvalidPattern
|
||||
}
|
||||
default:
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Debugf("invalid opcode: %d", op.code)
|
||||
}
|
||||
logger.Logf(log.DebugLevel, "invalid opcode: %d", op.code)
|
||||
return Pattern{}, ErrInvalidPattern
|
||||
}
|
||||
|
||||
@@ -171,9 +163,7 @@ func NewPattern(version int, ops []int, pool []string, verb string, opts ...Patt
|
||||
// MustPattern is a helper function which makes it easier to call NewPattern in variable initialization.
|
||||
func MustPattern(p Pattern, err error) Pattern {
|
||||
if err != nil {
|
||||
if logger.V(logger.DebugLevel, logger.DefaultLogger) {
|
||||
logger.Fatalf("Pattern initialization failed: %v", err)
|
||||
}
|
||||
log.Logf(log.FatalLevel, "Pattern initialization failed: %v", err)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user