1 /**************************************************************************
2 Copyright 2005 Webstersmalley
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 *************************************************************************/
16
17
18
19 package com.webstersmalley.statuslog;
20
21 import java.util.Date;
22
23 import org.apache.log4j.spi.LoggingEvent;
24
25 /***
26 * @author Matthew Smalley
27 */
28 public class StatusBean
29 {
30 private static final String[] COLUMN_NAMES = {"Time", "Level", "Logger", "Message"};
31
32 public static int getColumnCount()
33 {
34 return 4;
35 }
36
37 public static String getColumnName(int col)
38 {
39 return COLUMN_NAMES[col];
40 }
41
42 public StatusBean()
43 {
44
45 }
46
47 /***
48 * @return Returns the level.
49 */
50 public String getLevel()
51 {
52 return level;
53 }
54 /***
55 * @param level The level to set.
56 */
57 public void setLevel(String level)
58 {
59 this.level = level;
60 }
61 /***
62 * @return Returns the loggerName.
63 */
64 public String getLoggerName()
65 {
66 return loggerName;
67 }
68 /***
69 * @param loggerName The loggerName to set.
70 */
71 public void setLoggerName(String loggerName)
72 {
73 this.loggerName = loggerName;
74 }
75 /***
76 * @return Returns the message.
77 */
78 public String getMessage()
79 {
80 return message;
81 }
82 /***
83 * @param message The message to set.
84 */
85 public void setMessage(String message)
86 {
87 this.message = message;
88 }
89 /***
90 * @return Returns the timestamp.
91 */
92 public Date getTimestamp()
93 {
94 return timestamp;
95 }
96 /***
97 * @param timestamp The timestamp to set.
98 */
99 public void setTimestamp(Date timestamp)
100 {
101 this.timestamp = timestamp;
102 }
103
104 public Object getColumnValue(int col)
105 {
106 if (col == 0)
107 {
108 return timestamp;
109 }
110 if (col == 1)
111 {
112 return level;
113 }
114 if (col == 2)
115 {
116 return loggerName;
117 }
118 if (col == 3)
119 {
120 return message;
121 }
122 throw new RuntimeException("Invalid column: " + col);
123 }
124
125 private Date timestamp;
126 private String level;
127 private String message;
128 private String loggerName;
129
130 public static StatusBean fromLoggingEvent(LoggingEvent le)
131 {
132 StatusBean bean = new StatusBean();
133 bean.setLevel(le.getLevel().toString());
134 bean.setTimestamp(new Date(le.timeStamp));
135 bean.setLoggerName(le.getLoggerName());
136 bean.setMessage(le.getMessage().toString());
137 return bean;
138 }
139 }