equal
deleted
inserted
replaced
71 * <p> |
71 * <p> |
72 * @since 1.4 |
72 * @since 1.4 |
73 */ |
73 */ |
74 |
74 |
75 public class StreamHandler extends Handler { |
75 public class StreamHandler extends Handler { |
76 private LogManager manager = LogManager.getLogManager(); |
|
77 private OutputStream output; |
76 private OutputStream output; |
78 private boolean doneHeader; |
77 private boolean doneHeader; |
79 private Writer writer; |
78 private volatile Writer writer; |
80 |
79 |
81 // Private method to configure a StreamHandler from LogManager |
80 // Private method to configure a StreamHandler from LogManager |
82 // properties and/or default values as specified in the class |
81 // properties and/or default values as specified in the class |
83 // javadoc. |
82 // javadoc. |
84 private void configure() { |
83 private void configure() { |
167 * @exception SecurityException if a security manager exists and if |
166 * @exception SecurityException if a security manager exists and if |
168 * the caller does not have <tt>LoggingPermission("control")</tt>. |
167 * the caller does not have <tt>LoggingPermission("control")</tt>. |
169 * @exception UnsupportedEncodingException if the named encoding is |
168 * @exception UnsupportedEncodingException if the named encoding is |
170 * not supported. |
169 * not supported. |
171 */ |
170 */ |
172 public void setEncoding(String encoding) |
171 @Override |
|
172 public synchronized void setEncoding(String encoding) |
173 throws SecurityException, java.io.UnsupportedEncodingException { |
173 throws SecurityException, java.io.UnsupportedEncodingException { |
174 super.setEncoding(encoding); |
174 super.setEncoding(encoding); |
175 if (output == null) { |
175 if (output == null) { |
176 return; |
176 return; |
177 } |
177 } |
199 * written to the stream before the <tt>LogRecord</tt> is written. |
199 * written to the stream before the <tt>LogRecord</tt> is written. |
200 * |
200 * |
201 * @param record description of the log event. A null record is |
201 * @param record description of the log event. A null record is |
202 * silently ignored and is not published |
202 * silently ignored and is not published |
203 */ |
203 */ |
|
204 @Override |
204 public synchronized void publish(LogRecord record) { |
205 public synchronized void publish(LogRecord record) { |
205 if (!isLoggable(record)) { |
206 if (!isLoggable(record)) { |
206 return; |
207 return; |
207 } |
208 } |
208 String msg; |
209 String msg; |
238 * <p> |
239 * <p> |
239 * @param record a <tt>LogRecord</tt> |
240 * @param record a <tt>LogRecord</tt> |
240 * @return true if the <tt>LogRecord</tt> would be logged. |
241 * @return true if the <tt>LogRecord</tt> would be logged. |
241 * |
242 * |
242 */ |
243 */ |
|
244 @Override |
243 public boolean isLoggable(LogRecord record) { |
245 public boolean isLoggable(LogRecord record) { |
244 if (writer == null || record == null) { |
246 if (writer == null || record == null) { |
245 return false; |
247 return false; |
246 } |
248 } |
247 return super.isLoggable(record); |
249 return super.isLoggable(record); |
248 } |
250 } |
249 |
251 |
250 /** |
252 /** |
251 * Flush any buffered messages. |
253 * Flush any buffered messages. |
252 */ |
254 */ |
|
255 @Override |
253 public synchronized void flush() { |
256 public synchronized void flush() { |
254 if (writer != null) { |
257 if (writer != null) { |
255 try { |
258 try { |
256 writer.flush(); |
259 writer.flush(); |
257 } catch (Exception ex) { |
260 } catch (Exception ex) { |
292 * "tail" string. |
295 * "tail" string. |
293 * |
296 * |
294 * @exception SecurityException if a security manager exists and if |
297 * @exception SecurityException if a security manager exists and if |
295 * the caller does not have LoggingPermission("control"). |
298 * the caller does not have LoggingPermission("control"). |
296 */ |
299 */ |
|
300 @Override |
297 public synchronized void close() throws SecurityException { |
301 public synchronized void close() throws SecurityException { |
298 flushAndClose(); |
302 flushAndClose(); |
299 } |
303 } |
300 } |
304 } |