44 |
|
* Creates a new ScreenLoggerServant. |
45 |
|
*/ |
46 |
|
public SimpleGUILogger() { |
47 |
– |
_verbosityLevel = Integer.parseInt(System.getProperty("uk.ac.ukc.iscream.Verbosity")); |
47 |
|
_maxMessages = Integer.parseInt(System.getProperty("uk.ac.ukc.iscream.LoggerClass.SimpleGUILogger.maxMessages")); |
48 |
|
|
49 |
|
getFrame().add(getTextArea()); |
51 |
|
getFrame().setVisible(true); |
52 |
|
|
53 |
|
write(toString(), Logger.SYSINIT, "started"); |
55 |
– |
write(toString(), Logger.SYSMSG, "using verbosity " + _verbosityLevel); |
54 |
|
} |
55 |
|
|
56 |
|
//---PUBLIC METHODS--- |
67 |
|
* @param verbosity the verbosity of this message |
68 |
|
* @param message The text to be logged. |
69 |
|
*/ |
70 |
< |
public synchronized void write(String source, int verbosity, String message) { |
71 |
< |
if (verbosity <= _verbosityLevel) { |
72 |
< |
String line = formatLogLine(source, message); |
75 |
< |
getTextArea().append(line + "\n"); |
76 |
< |
getTextArea().setRows(_maxMessages); |
77 |
< |
} |
70 |
> |
public synchronized void write(String line, int verbosity) { |
71 |
> |
getTextArea().append(line + "\n"); |
72 |
> |
getTextArea().setRows(_maxMessages); |
73 |
|
} |
74 |
|
|
75 |
|
/** |
90 |
|
|
91 |
|
//---PRIVATE METHODS--- |
92 |
|
|
93 |
< |
/** |
94 |
< |
* This method generates a nicely formatted line for the log, |
100 |
< |
* including the date/time and the source of the message. The date |
101 |
< |
* and time are formatted using the DateFormat class, and the source |
102 |
< |
* class is formatted using the toString() method found in every |
103 |
< |
* source file. This is then prepended to the message and returned. |
104 |
< |
* |
105 |
< |
* @param source A string representation of the calling object. |
106 |
< |
* @param message The message to be logged. |
107 |
< |
* @return The string to be written to the log. |
108 |
< |
*/ |
109 |
< |
private String formatLogLine(String source, String message){ |
110 |
< |
String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date()); |
111 |
< |
return "[" + date + "] " + source + ": " + message; |
93 |
> |
private void write(String source, int verbosity, String message) { |
94 |
> |
write(FormatName.formatLogLine(source, verbosity, message), verbosity); |
95 |
|
} |
96 |
|
|
97 |
|
//---ACCESSOR/MUTATOR METHODS--- |
115 |
|
} |
116 |
|
|
117 |
|
//---ATTRIBUTES--- |
118 |
< |
|
136 |
< |
/** |
137 |
< |
* The verbosity level of this instance |
138 |
< |
*/ |
139 |
< |
private int _verbosityLevel; |
140 |
< |
|
118 |
> |
|
119 |
|
/** |
120 |
|
* a frame |
121 |
|
*/ |