001: package org.jzonic.jlo;
002:
003: import java.io.PrintWriter;
004: import java.io.StringWriter;
005:
006: /**
007: *@author Andreas Mecky
008: *@author Terry Dye
009: *@created 9. März 2002
010: *@version 1.0
011: */
012: public class LogRecord {
013:
014: private String msg;
015: private long logdate;
016: private String loggername;
017: private String sourceClass = null;
018: private String sourceMethod = null;
019: private Throwable thrown;
020: private Target target;
021: private String configurationName;
022: private long elapsed;
023: private String ndc;
024:
025: /**
026: * Constructor for the LogRecord object
027: *
028: *@param msg Description of the Parameter
029: */
030: public LogRecord(String msg) {
031: this (msg, null);
032: }
033:
034: /**
035: * Constructor for the LogRecord object
036: *
037: *@param msg Description of the Parameter
038: *@param Target Description of the Parameter
039: */
040: public LogRecord(String msg, Target target) {
041: this .msg = msg;
042: this .target = target;
043: logdate = System.currentTimeMillis();
044:
045: }
046:
047: /**
048: * Get the logging message Target
049: *
050: *@return Target the current message Target
051: */
052: public Target getTarget() {
053: return target;
054: }
055:
056: /**
057: * Get the source Logger name's
058: *
059: *@return loggername the name of the logger
060: */
061: public String getLoggerName() {
062: return loggername;
063: }
064:
065: /**
066: * Get the "raw" log message, before localization or formatting.
067: *
068: *@return msg the raw message as string
069: */
070: public String getMessage() {
071: return msg;
072: }
073:
074: /**
075: * Get event time in milliseconds since 1970.
076: *
077: *@return logdate the event time in milliseconds
078: */
079: public long getMillis() {
080: return logdate;
081: }
082:
083: /**
084: * Get the name of the class that (allegedly) issued the logging request.
085: *
086: *@return
087: */
088: public String getSourceClassName() {
089: return sourceClass;
090: }
091:
092: /**
093: * Get the name of the method that (allegedly) issued the logging request.
094: *
095: *@return
096: */
097: public String getSourceMethodName() {
098: return sourceMethod;
099: }
100:
101: /**
102: * Get any throwable associated with the log record.
103: *
104: *@return
105: */
106: public Throwable getThrown() {
107: return thrown;
108: }
109:
110: /**
111: * Set the logging message Target, for example Target.SEVERE.
112: *
113: *@param Target the Target of the logging request
114: */
115: public void setTarget(Target target) {
116: this .target = target;
117: }
118:
119: /**
120: * Set the source Logger name.
121: *
122: *@param name the name of the logger
123: */
124: public void setLoggerName(String name) {
125: loggername = name;
126: }
127:
128: /**
129: * Set the "raw" log message, before localization or formatting.
130: *
131: *@param message the message that should be logged
132: */
133: public void setMessage(String message) {
134: msg = message;
135: }
136:
137: /**
138: * Set event time.
139: *
140: *@param millis the time in milliseconds
141: */
142: public void setMillis(long millis) {
143: logdate = millis;
144: }
145:
146: /**
147: * Set the name of the class that (allegedly) issued the logging request.
148: *
149: *@param sourceClassName the name of the class
150: */
151: public void setSourceClassName(String sourceClassName) {
152: sourceClass = sourceClassName;
153: }
154:
155: /**
156: * Set the name of the method that (allegedly) issued the logging request.
157: *
158: *@param sourceMethodName the name of the method
159: */
160: public void setSourceMethodName(String sourceMethodName) {
161: sourceMethod = sourceMethodName;
162: }
163:
164: /**
165: * Set a throwable associated with the log event.
166: *
167: *@param thrown the exception
168: */
169: public void setThrown(Throwable thrown) {
170: this .thrown = thrown;
171: }
172:
173: public String getStackTrace() {
174: if (thrown != null) {
175: StringWriter sw = new StringWriter();
176: PrintWriter pw = new PrintWriter(sw);
177: thrown.printStackTrace(pw);
178: pw.close();
179: return sw.getBuffer().toString();
180: } else {
181: return "";
182: }
183: }
184:
185: /** Getter for property configurationName.
186: * @return Value of property configurationName.
187: *
188: */
189: public String getConfigurationName() {
190: return configurationName;
191: }
192:
193: /** Setter for property configurationName.
194: * @param configurationName New value of property configurationName.
195: *
196: */
197: public void setConfigurationName(String configurationName) {
198: this .configurationName = configurationName;
199: }
200:
201: public String getNDC() {
202: return ndc;
203: }
204:
205: public void setNDC(String ndc) {
206: this .ndc = ndc;
207: }
208:
209: public void setElapsed(long elapsed) {
210: this .elapsed = elapsed;
211: }
212:
213: public long getElapsed() {
214: return elapsed;
215: }
216:
217: }
|