MCPcopy
hub / github.com/caddyserver/caddy / loggerAllowed

Method loggerAllowed

logging.go:533–592  ·  view source on GitHub ↗

loggerAllowed returns true if name is allowed to emit to cl. isModule should be true if name is the name of a module and you want to see if ANY of that module's logs would be permitted.

(name string, isModule bool)

Source from the content-addressed store, hash-verified

531// a module and you want to see if ANY of that module's
532// logs would be permitted.
533func (cl *CustomLog) loggerAllowed(name string, isModule bool) bool {
534 // accept all loggers by default
535 if len(cl.Include) == 0 && len(cl.Exclude) == 0 {
536 return true
537 }
538
539 // append a dot so that partial names don't match
540 // (i.e. we don't want "foo.b" to match "foo.bar"); we
541 // will also have to append a dot when we do HasPrefix
542 // below to compensate for when namespaces are equal
543 if name != "" && name != "*" && name != "." {
544 name += "."
545 }
546
547 var longestAccept, longestReject int
548
549 if len(cl.Include) > 0 {
550 for _, namespace := range cl.Include {
551 var hasPrefix bool
552 if isModule {
553 hasPrefix = strings.HasPrefix(namespace+".", name)
554 } else {
555 hasPrefix = strings.HasPrefix(name, namespace+".")
556 }
557 if hasPrefix && len(namespace) > longestAccept {
558 longestAccept = len(namespace)
559 }
560 }
561 // the include list was populated, meaning that
562 // a match in this list is absolutely required
563 // if we are to accept the entry
564 if longestAccept == 0 {
565 return false
566 }
567 }
568
569 if len(cl.Exclude) > 0 {
570 for _, namespace := range cl.Exclude {
571 // * == all logs emitted by modules
572 // . == all logs emitted by core
573 if (namespace == "*" && name != ".") ||
574 (namespace == "." && name == ".") {
575 return false
576 }
577 if strings.HasPrefix(name, namespace+".") &&
578 len(namespace) > longestReject {
579 longestReject = len(namespace)
580 }
581 }
582 // the reject list is populated, so we have to
583 // reject this entry if its match is better
584 // than the best from the accept list
585 if longestReject > longestAccept {
586 return false
587 }
588 }
589
590 return (longestAccept > longestReject) ||

Callers 3

matchesModuleMethod · 0.95
CheckMethod · 0.80

Calls

no outgoing calls

Tested by 1