View Javadoc

1   /**
2    *  MicroEmulator
3    *  Copyright (C) 2001-2007 Bartek Teodorczyk <barteo@barteo.net>
4    *  Copyright (C) 2006-2007 Vlad Skarzhevskyy
5    *
6    *  This library is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public
8    *  License as published by the Free Software Foundation; either
9    *  version 2.1 of the License, or (at your option) any later version.
10   *
11   *  This library is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this library; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   *
20   *  @version $Id: LoggingEvent.java 905 2007-02-13 23:53:20Z vlads $
21   */
22  package org.microemu.log;
23  
24  /**
25   * @author vlads
26   *
27   */
28  public class LoggingEvent {
29  
30  	public final static int DEBUG = 1;
31  
32  	public final static int INFO = 2;
33  
34  	public final static int WARN = 3;
35  
36  	public final static int ERROR = 4;
37  	
38  	protected int level;
39  
40  	protected String message;
41      
42  	protected StackTraceElement location; 
43  
44  	protected boolean hasData = false;
45  
46  	protected Object data;
47  
48  	protected Throwable throwable;
49  
50  	protected long eventTime;
51  
52  
53      public LoggingEvent() {
54      	this.eventTime = System.currentTimeMillis();
55      }
56      
57  	public LoggingEvent(int level, String message, StackTraceElement location, Throwable throwable) {
58  		this();
59  		this.level = level;
60  		this.message = message;
61  		this.location = location;
62  		this.throwable = throwable;
63  	}
64  	
65  	public LoggingEvent(int level, String message, StackTraceElement location, Throwable throwable, Object data) {
66  		this(level, message, location, throwable);
67  		setData(data);
68  	}
69  
70  	public Object getData() {
71  		return this.data;
72  	}
73  
74  	public void setData(Object data) {
75  		this.data = data;
76  		this.hasData = true;
77  	}
78  
79  	public boolean hasData() {
80  		return this.hasData;
81  	}
82  
83  	public String getFormatedData() {
84  		if (hasData()) {
85  			if (getData() == null) {
86  				return "{null}";
87  			} else {
88  				return getData().toString();
89  			}
90  		} else {
91  			return "";
92  		}
93  	}
94  	
95  	public long getEventTime() {
96  		return this.eventTime;
97  	}
98  
99  	public int getLevel() {
100 		return this.level;
101 	}
102 
103 	public StackTraceElement getLocation() {
104 		return this.location;
105 	}
106 
107 	public String getMessage() {
108 		return this.message;
109 	}
110 
111 	public Throwable getThrowable() {
112 		return this.throwable;
113 	}
114 
115 }