1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.resolver.dns;
17
18 import io.netty5.handler.codec.dns.DnsQuestion;
19 import io.netty5.handler.logging.LogLevel;
20 import io.netty5.util.internal.logging.InternalLogLevel;
21 import io.netty5.util.internal.logging.InternalLogger;
22 import io.netty5.util.internal.logging.InternalLoggerFactory;
23
24 import static java.util.Objects.requireNonNull;
25
26
27
28
29
30
31
32
33 public final class LoggingDnsQueryLifeCycleObserverFactory implements DnsQueryLifecycleObserverFactory {
34 private static final InternalLogger DEFAULT_LOGGER =
35 InternalLoggerFactory.getInstance(LoggingDnsQueryLifeCycleObserverFactory.class);
36 private final InternalLogger logger;
37 private final InternalLogLevel level;
38
39
40
41
42 public LoggingDnsQueryLifeCycleObserverFactory() {
43 this(LogLevel.DEBUG);
44 }
45
46
47
48
49
50 public LoggingDnsQueryLifeCycleObserverFactory(LogLevel level) {
51 this.level = checkAndConvertLevel(level);
52 logger = DEFAULT_LOGGER;
53 }
54
55
56
57
58
59
60
61 public LoggingDnsQueryLifeCycleObserverFactory(Class<?> classContext, LogLevel level) {
62 this.level = checkAndConvertLevel(level);
63 logger = InternalLoggerFactory.getInstance(requireNonNull(classContext, "classContext"));
64 }
65
66
67
68
69
70
71
72 public LoggingDnsQueryLifeCycleObserverFactory(String name, LogLevel level) {
73 this.level = checkAndConvertLevel(level);
74 logger = InternalLoggerFactory.getInstance(requireNonNull(name, "name"));
75 }
76
77 private static InternalLogLevel checkAndConvertLevel(LogLevel level) {
78 return requireNonNull(level, "level").toInternalLevel();
79 }
80
81 @Override
82 public DnsQueryLifecycleObserver newDnsQueryLifecycleObserver(DnsQuestion question) {
83 return new LoggingDnsQueryLifecycleObserver(question, logger, level);
84 }
85 }