83 |
|
* @param message The message to be logged. |
84 |
|
*/ |
85 |
|
public synchronized void write(String source, int verbosity, String message) { |
86 |
< |
// Check to make sure file is open |
87 |
< |
if(open){ |
88 |
< |
// Produce a nicely formatted line for the logfile |
89 |
< |
String line = formatLogLine(source, message); |
90 |
< |
try{ |
91 |
< |
// We have to synchronize here due to problems with two write()'s being called before a newLine() |
92 |
< |
synchronized(writer){ |
93 |
< |
// Attempt to write the line |
94 |
< |
writer.write(line); |
95 |
< |
// Best to use newLine() as it will use the correct platform encoding |
96 |
< |
writer.newLine(); |
97 |
< |
} |
98 |
< |
// Make sure the line is written immeidiately |
99 |
< |
writer.flush(); |
100 |
< |
} |
101 |
< |
catch(IOException e){ |
102 |
< |
// We'd best log the error |
103 |
< |
System.out.println(formatLogLine(this.toString(), "Writing to logfile failed - " + e.getMessage())); |
104 |
< |
// As it's an IOException we should suspend logging |
105 |
< |
open = false; |
106 |
< |
} |
107 |
< |
} |
108 |
< |
else{ |
109 |
< |
// If file is not open we should print this to the screen |
110 |
< |
System.out.println(formatLogLine(this.toString(), "Write failed - file not open")); |
111 |
< |
} |
86 |
> |
if (verbosity <= _verbosityLevel) { |
87 |
> |
// Check to make sure file is open |
88 |
> |
if(open){ |
89 |
> |
// Produce a nicely formatted line for the logfile |
90 |
> |
String line = formatLogLine(source, message); |
91 |
> |
try{ |
92 |
> |
// We have to synchronize here due to problems with two write()'s being called before a newLine() |
93 |
> |
synchronized(writer){ |
94 |
> |
// Attempt to write the line |
95 |
> |
writer.write(line); |
96 |
> |
// Best to use newLine() as it will use the correct platform encoding |
97 |
> |
writer.newLine(); |
98 |
> |
} |
99 |
> |
// Make sure the line is written immeidiately |
100 |
> |
writer.flush(); |
101 |
> |
} |
102 |
> |
catch(IOException e){ |
103 |
> |
// We'd best log the error |
104 |
> |
System.out.println(formatLogLine(this.toString(), "Writing to logfile failed - " + e.getMessage())); |
105 |
> |
// As it's an IOException we should suspend logging |
106 |
> |
open = false; |
107 |
> |
} |
108 |
> |
} |
109 |
> |
else{ |
110 |
> |
// If file is not open we should print this to the screen |
111 |
> |
System.out.println(formatLogLine(this.toString(), "Write failed - file not open")); |
112 |
> |
} |
113 |
> |
} |
114 |
|
} |
115 |
|
|
116 |
|
/** |