|
4 | 4 | import java.util.Map; |
5 | 5 |
|
6 | 6 | /** |
7 | | - * A factory class that allows you to set SplunkLogEvent templates and generate clones. |
8 | | - * Useful for reuse when you log many events with the same key=value pair signatures. |
| 7 | + * A factory class that allows you to set SplunkLogEvent templates and generate |
| 8 | + * clones. Useful for reuse when you log many events with the same key=value |
| 9 | + * pair signatures. |
9 | 10 | * |
10 | 11 | * <code> |
11 | 12 | * |
|
16 | 17 | * event.addPair("someparam", "helloworld"); |
17 | 18 | * |
18 | 19 | * </code> |
19 | | - * |
| 20 | + * |
20 | 21 | * @author Damien Dallimore damien@dtdsoftware.com |
21 | | - * |
| 22 | + * |
22 | 23 | */ |
23 | 24 | public abstract class SplunkLogEventFactory { |
24 | | - |
25 | | - //map to hold the templates |
26 | | - private static Map<String,SplunkLogEvent>templates = new HashMap<String,SplunkLogEvent>(); |
27 | | - |
| 25 | + |
| 26 | + // map to hold the templates |
| 27 | + private static Map<String, SplunkLogEvent> templates = new HashMap<String, SplunkLogEvent>(); |
| 28 | + |
28 | 29 | /** |
29 | 30 | * Add a template SplunkLogEvent object |
| 31 | + * |
30 | 32 | * @param name |
31 | 33 | * @param template |
32 | 34 | */ |
33 | | - public static void addTemplate(String name, SplunkLogEvent template){ |
34 | | - |
| 35 | + public static void addTemplate(String name, SplunkLogEvent template) { |
| 36 | + |
35 | 37 | templates.put(name, template); |
36 | 38 | } |
37 | | - |
| 39 | + |
38 | 40 | /** |
39 | 41 | * Remove a template SplunkLogEvent object |
| 42 | + * |
40 | 43 | * @param name |
41 | 44 | */ |
42 | | - public static void removeTemplate(String name){ |
43 | | - |
| 45 | + public static void removeTemplate(String name) { |
| 46 | + |
44 | 47 | templates.remove(name); |
45 | 48 | } |
46 | | - |
| 49 | + |
47 | 50 | /** |
48 | 51 | * Get a new SplunkLogEvent object that is a clone of a template |
| 52 | + * |
49 | 53 | * @param name |
50 | 54 | * @return |
51 | 55 | * @throws Exception |
52 | 56 | */ |
53 | | - public static SplunkLogEvent getInstanceFromTemplate(String name) throws Exception{ |
54 | | - |
55 | | - SplunkLogEvent template = templates.get(name); |
56 | | - if(template != null){ |
57 | | - return template.clone(); |
58 | | - } |
59 | | - else |
60 | | - throw new Exception("SplunkLogEvent template "+name+" does not exist"); |
| 57 | + public static SplunkLogEvent getInstanceFromTemplate(String name) |
| 58 | + throws Exception { |
| 59 | + |
| 60 | + SplunkLogEvent template = templates.get(name); |
| 61 | + if (template != null) { |
| 62 | + return template.clone(); |
| 63 | + } else |
| 64 | + throw new Exception("SplunkLogEvent template " + name |
| 65 | + + " does not exist"); |
61 | 66 | } |
62 | 67 | } |
63 | | - |
|
0 commit comments