/** * Constructs a {@code Handler} object with a default error manager instance * {@code ErrorManager}, the default encoding, and the default logging * level {@code Level.ALL}. It has no filter and no formatter. */ protected Handler() { this.errorMan = new ErrorManager(); this.level = DEFAULT_LEVEL; this.encoding = null; this.filter = null; this.formatter = null; this.prefix = this.getClass().getName(); }
void printInvalidPropMessage(String key, String value, Exception e) { String msg = "Invalid property value for " + prefix + ":" + key + "/" + value; errorMan.error(msg, e, ErrorManager.GENERIC_FAILURE); }
private static Properties getVersionPropertiesFromFile(String path) { Properties properties = new Properties(); try { InputStream inputStream = PlatformVersion.class.getClassLoader().getResourceAsStream(path); if (inputStream != null) { properties.load(inputStream); inputStream.close(); } } catch (Throwable t) { ErrorManager errorManager = new ErrorManager(); errorManager.error("Failed to load version properties from " + path, new Exception(t), ErrorManager.OPEN_FAILURE); } return properties; }
public class LogFilter implements Filter { private final ErrorManager error = new ErrorManager(); @Override public boolean isLoggable(LogRecord record) { try { //Insert code. return false; } catch (RuntimeException re) { error.error(new SimpleFormatter().format(record), re, ErrorManager.GENERIC_FAILURE); return true; } }
/** * Reports an error to the error manager associated with this handler, * {@code ErrorManager} is used for that purpose. No security checks are * done, therefore this is compatible with environments where the caller * is non-privileged. * * @param msg * the error message, may be {@code null}. * @param ex * the associated exception, may be {@code null}. * @param code * an {@code ErrorManager} error code. */ protected void reportError(String msg, Exception ex, int code) { this.errorMan.error(msg, ex, code); }
/** * Used to get or create the default ErrorManager used before init. * @return the super error manager or a new ErrorManager. * @since JavaMail 1.5.3 */ private ErrorManager defaultErrorManager() { ErrorManager em; try { //Try to share the super error manager. em = super.getErrorManager(); } catch (RuntimeException | LinkageError ignore) { em = null; } //Don't assume that the super call is not null. if (em == null) { em = new ErrorManager(); } return em; }
private void write(String s) { try { this.writer.write(s); } catch (Exception e) { getErrorManager().error("Exception occurred when writing to the output stream", e, ErrorManager.WRITE_FAILURE); } }
/** * Used to get or create the default ErrorManager used before init. * @return the super error manager or a new ErrorManager. * @since JavaMail 1.5.3 */ private ErrorManager defaultErrorManager() { ErrorManager em; try { //Try to share the super error manager. em = super.getErrorManager(); } catch (final RuntimeException ignore) { em = null; } catch (final LinkageError ignore) { em = null; } //Don't assume that the super call is not null. if (em == null) { em = new ErrorManager(); } return em; }
/** * Flushes any buffered output. */ @Override public void flush() { if (this.os != null) { try { if (this.writer != null) { this.writer.flush(); } else { this.os.flush(); } } catch (Exception e) { getErrorManager().error("Exception occurred when flushing the output stream", e, ErrorManager.FLUSH_FAILURE); } } }
setErrorManager(new ErrorManager());
void findNextGeneration() { super.close(); for (int i = count - 1; i > 0; i--) { if (files[i].exists()) { files[i].delete(); } files[i - 1].renameTo(files[i]); } try { output = new MeasureOutputStream(new BufferedOutputStream( new FileOutputStream(files[0]))); } catch (FileNotFoundException e1) { this.getErrorManager().error("Error opening log file", e1, ErrorManager.OPEN_FAILURE); } setOutputStream(output); }
/** * No argument constructor. */ public DOMConfigurator() { this(new ErrorManager()); }
private void initSocket(String host, String port) throws IOException { // check the validity of the host name if (host == null || host.isEmpty()) { throw new IllegalArgumentException("host == null || host.isEmpty()"); } // check the validity of the port number int p = 0; try { p = Integer.parseInt(port); } catch (NumberFormatException e) { throw new IllegalArgumentException("Illegal port argument"); } if (p <= 0) { throw new IllegalArgumentException("Illegal port argument"); } // establish the network connection try { this.socket = new Socket(host, p); } catch (IOException e) { getErrorManager().error("Failed to establish the network connection", e, ErrorManager.OPEN_FAILURE); throw e; } super.internalSetOutputStream(new BufferedOutputStream(this.socket.getOutputStream())); }
/** * No argument constructor. */ public DOMConfigurator() { this(new ErrorManager()); }
/** * Closes this handler. The network connection to the host is also closed. */ @Override public void close() { try { super.close(); if (this.socket != null) { this.socket.close(); this.socket = null; } } catch (Exception e) { getErrorManager().error("Exception occurred when closing the socket handler", e, ErrorManager.CLOSE_FAILURE); } }
/** * No argument constructor. */ public DOMConfigurator() { this(new ErrorManager()); }
@Override public void flush() { try { getLogging().flush(); } catch (Exception ex) { getErrorManager().error(null, ex, ErrorManager.FLUSH_FAILURE); } }
protected Handler() { this.errorMan = new ErrorManager(); this.level = DEFAULT_LEVEL; this.encoding = null; this.filter = null; this.formatter = null; this.prefix = this.getClass().getName(); }
@Override public void publish(LogRecord record) { // check that the log record should be logged if (!isLoggable(record)) { return; } // HACK warning: this logger doesn't work like normal loggers; the log calls are issued // from another class instead of by itself, so it can't be configured off like normal // loggers. We have to check the source class name instead. if ("io.netty.handler.codec.http2.Http2FrameLogger".equals(record.getSourceClassName())) { return; } LogEntry logEntry; try { logEntry = logEntryFor(record); } catch (Exception ex) { getErrorManager().error(null, ex, ErrorManager.FORMAT_FAILURE); return; } if (logEntry != null) { try { getLogging().write(ImmutableList.of(logEntry), defaultWriteOptions); } catch (Exception ex) { getErrorManager().error(null, ex, ErrorManager.WRITE_FAILURE); } } }
/** * Constructs a {@code Handler} object with a default error manager instance * {@code ErrorManager}, the default encoding, and the default logging * level {@code Level.ALL}. It has no filter and no formatter. */ protected Handler() { this.errorMan = new ErrorManager(); this.level = DEFAULT_LEVEL; this.encoding = null; this.filter = null; this.formatter = null; this.prefix = this.getClass().getName(); }