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 org.kuali.common.util.base.Precondition.checkNotNull;
19
20 import org.kuali.common.util.execute.Executable;
21
22 public class LoggerExecutable implements Executable {
23
24 private static final Object[] EMPTY_OBJECT_ARRAY = {};
25
26 private final LoggerContext context;
27 private final boolean skip;
28
29 @Override
30 public void execute() {
31 if (!skip) {
32 LoggerUtils.logMsg(context.getMsg(), context.getArgs().toArray(EMPTY_OBJECT_ARRAY), context.getLogger(), context.getLevel());
33 }
34 }
35
36 private LoggerExecutable(Builder builder) {
37 this.context = builder.context;
38 this.skip = builder.skip;
39 }
40
41 public static LoggerExecutable create(LoggerContext context) {
42 return builder(context).build();
43 }
44
45 public static Builder builder(LoggerContext context) {
46 return new Builder(context);
47 }
48
49 public static class Builder implements org.apache.commons.lang3.builder.Builder<LoggerExecutable> {
50
51
52 private final LoggerContext context;
53
54
55 private boolean skip = false;
56
57 public Builder(LoggerContext context) {
58 this.context = context;
59 }
60
61 public Builder skip(boolean skip) {
62 this.skip = skip;
63 return this;
64 }
65
66 @Override
67 public LoggerExecutable build() {
68 LoggerExecutable instance = new LoggerExecutable(this);
69 validate(instance);
70 return instance;
71 }
72
73 private static void validate(LoggerExecutable instance) {
74 checkNotNull(instance.context, "context");
75 }
76 }
77
78 public LoggerContext getContext() {
79 return context;
80 }
81
82 public boolean isSkip() {
83 return skip;
84 }
85
86 }