1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.log;
17
18 import static com.google.common.base.Preconditions.checkNotNull;
19
20 import java.util.List;
21
22 import org.slf4j.Logger;
23
24 import com.google.common.collect.ImmutableList;
25
26 public final class LoggerContext {
27
28 private final LoggerLevel level;
29 private final String msg;
30 private final ImmutableList<Object> args;
31 private final Logger logger;
32
33 private LoggerContext(Builder builder) {
34 this.logger = builder.logger;
35 this.level = builder.level;
36 this.msg = builder.msg;
37 this.args = ImmutableList.copyOf(builder.args);
38 }
39
40 public static Builder builder(Logger logger, String msg) {
41 return new Builder(logger, msg);
42 }
43
44 public static class Builder {
45
46 public Builder(Logger logger, String msg) {
47 this.logger = logger;
48 this.msg = msg;
49 }
50
51
52 private Logger logger;
53 private final String msg;
54
55
56 private LoggerLevel level = LoggerLevel.INFO;
57 private List<Object> args = ImmutableList.of();
58
59 public Builder level(LoggerLevel level) {
60 this.level = level;
61 return this;
62 }
63
64 public Builder args(List<Object> args) {
65 this.args = args;
66 return this;
67 }
68
69 public LoggerContext build() {
70 LoggerContext instance = new LoggerContext(this);
71 validate(instance);
72 return instance;
73 }
74
75 private static void validate(LoggerContext instance) {
76 checkNotNull(instance.logger, "logger cannot be null");
77 checkNotNull(instance.level, "level cannot be null");
78 checkNotNull(instance.msg, "msg cannot be null");
79 checkNotNull(instance.args, "args cannot be null");
80 }
81 }
82
83 public LoggerLevel getLevel() {
84 return level;
85 }
86
87 public String getMsg() {
88 return msg;
89 }
90
91 public ImmutableList<Object> getArgs() {
92 return args;
93 }
94
95 public Logger getLogger() {
96 return logger;
97 }
98
99 }