Enhance DNS and Dialer (#341)

This commit is contained in:
Jim Han 2021-03-07 00:29:17 +08:00 committed by GitHub
parent ad1807dd99
commit db32ce6fd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 682 additions and 290 deletions

View file

@ -17,6 +17,7 @@ type Instance struct {
accessLogger log.Handler
errorLogger log.Handler
active bool
dns bool
}
// New creates a new log.Instance based on the given config.
@ -24,6 +25,7 @@ func New(ctx context.Context, config *Config) (*Instance, error) {
g := &Instance{
config: config,
active: false,
dns: config.EnableDnsLog,
}
log.RegisterHandler(g)
@ -103,6 +105,10 @@ func (g *Instance) Handle(msg log.Message) {
if g.accessLogger != nil {
g.accessLogger.Handle(msg)
}
case *log.DNSLog:
if g.dns && g.accessLogger != nil {
g.accessLogger.Handle(msg)
}
case *log.GeneralMessage:
if g.errorLogger != nil && msg.Severity <= g.config.ErrorLogLevel {
g.errorLogger.Handle(msg)