View Javadoc
1   package org.kuali.common.util.log;
2   
3   import static com.google.common.base.Preconditions.checkNotNull;
4   
5   import org.kuali.common.util.execute.Executable;
6   
7   public class LoggerExecutable implements Executable {
8   
9   	private static final Object[] EMPTY_OBJECT_ARRAY = {};
10  
11  	private final LoggerContext context;
12  	private final boolean skip;
13  
14  	@Override
15  	public void execute() {
16  		if (!skip) {
17  			LoggerUtils.logMsg(context.getMsg(), context.getArgs().toArray(EMPTY_OBJECT_ARRAY), context.getLogger(), context.getLevel());
18  		}
19  	}
20  
21  	private LoggerExecutable(Builder builder) {
22  		this.context = builder.context;
23  		this.skip = builder.skip;
24  	}
25  
26  	public static LoggerExecutable create(LoggerContext context) {
27  		return builder(context).build();
28  	}
29  
30  	public static Builder builder(LoggerContext context) {
31  		return new Builder(context);
32  	}
33  
34  	public static class Builder {
35  
36  		// Required
37  		private final LoggerContext context;
38  
39  		// Optional
40  		private boolean skip = false;
41  
42  		public Builder(LoggerContext context) {
43  			this.context = context;
44  		}
45  
46  		public Builder skip(boolean skip) {
47  			this.skip = skip;
48  			return this;
49  		}
50  
51  		public LoggerExecutable build() {
52  			LoggerExecutable instance = new LoggerExecutable(this);
53  			validate(instance);
54  			return instance;
55  		}
56  
57  		private static void validate(LoggerExecutable instance) {
58  			checkNotNull(instance.context, "context may not be null");
59  		}
60  	}
61  
62  	public LoggerContext getContext() {
63  		return context;
64  	}
65  
66  	public boolean isSkip() {
67  		return skip;
68  	}
69  
70  }