} catch (Exception ex) { if (!ignoreExceptions()) { throw new AppenderLoggingException(ex);
@Override public void reportError(String message, Exception e) { if (e != null) { throw new AppenderLoggingException(e); } LOGGER.error(message, null, 0); } };
@Override public void reportError(String message, Exception e) { if (e != null) { throw new AppenderLoggingException(e); } LOGGER.error(message, null, 0); } };
@Override public void reportError(String message, Exception e) { if (e != null) { throw new AppenderLoggingException(e); } LOGGER.error(message, null, 0); } };
@Override protected void connectAndStart() { try { this.entityManager = this.entityManagerFactory.createEntityManager(); this.transaction = this.entityManager.getTransaction(); this.transaction.begin(); } catch (final Exception e) { throw new AppenderLoggingException( "Cannot write logging event or flush buffer; manager cannot create EntityManager or transaction.", e ); } }
@Override protected void writeToDestination(final byte[] bytes, final int offset, final int length) { try { randomAccessFile.write(bytes, offset, length); } catch (final IOException ex) { final String msg = "Error writing to RandomAccessFile " + getName(); throw new AppenderLoggingException(msg, ex); } }
/** * Flushes any buffers. */ public synchronized void flush() { try { writer.flush(); } catch (final IOException ex) { final String msg = "Error flushing stream " + getName(); throw new AppenderLoggingException(msg, ex); } }
@Override protected void connectAndStart() { try { this.connection = this.connectionSource.getConnection(); this.connection.setAutoCommit(false); this.statement = this.connection.prepareStatement(this.sqlStatement); } catch (final SQLException e) { throw new AppenderLoggingException( "Cannot write logging event or flush buffer; JDBC manager cannot connect to the database.", e ); } }
/** * The Constructor. * @param host The host to connect to. * @param port The port on the host. */ public DatagramOutputStream(final String host, final int port, final byte[] header, final byte[] footer) { this.port = port; this.header = header; this.footer = footer; try { inetAddress = InetAddress.getByName(host); } catch (final UnknownHostException ex) { final String msg = "Could not find host " + host; LOGGER.error(msg, ex); throw new AppenderLoggingException(msg, ex); } try { datagramSocket = new DatagramSocket(); } catch (final SocketException ex) { final String msg = "Could not instantiate DatagramSocket to " + host; LOGGER.error(msg, ex); throw new AppenderLoggingException(msg, ex); } }
@Override protected void writeInternal(final LogEvent event) { if (!this.isRunning() || this.entityManagerFactory == null || this.entityManager == null || this.transaction == null) { throw new AppenderLoggingException( "Cannot write logging event; JPA manager not connected to the database."); } AbstractLogEventWrapperEntity entity; try { entity = this.entityConstructor.newInstance(event); } catch (final Exception e) { throw new AppenderLoggingException("Failed to instantiate entity class [" + this.entityClassName + "].", e); } try { this.entityManager.persist(entity); } catch (final Exception e) { if (this.transaction != null && this.transaction.isActive()) { this.transaction.rollback(); this.transaction = null; } throw new AppenderLoggingException("Failed to insert record for log event in JPA manager: " + e.getMessage(), e); } }
/** * Calls {@code flush()} on the underlying output stream. * @since 2.6 */ protected synchronized void flushDestination() { final OutputStream stream = outputStream; // access volatile field only once per method if (stream != null) { try { stream.flush(); } catch (final IOException ex) { throw new AppenderLoggingException("Error flushing stream " + getName(), ex); } } }
/** * Some output streams synchronize writes while others do not. Synchronizing here insures that * log events won't be intertwined. * @param str the string to write * @throws AppenderLoggingException if an error occurs. */ protected synchronized void write(final String str) { try { writer.write(str); } catch (final IOException ex) { final String msg = "Error writing to stream " + getName(); throw new AppenderLoggingException(msg, ex); } }
/** * Handle an error with a message and an exception. * @param msg The message. * @param t The Throwable. */ @Override public void error(final String msg, final Throwable t) { final long current = System.nanoTime(); if (current - lastException > EXCEPTION_INTERVAL || exceptionCount++ < MAX_EXCEPTIONS) { LOGGER.error(msg, t); } lastException = current; if (!appender.ignoreExceptions() && t != null && !(t instanceof AppenderLoggingException)) { throw new AppenderLoggingException(msg, t); } }
/** * Handle an error with a message, and exception and a logging event. * @param msg The message. * @param event The LogEvent. * @param t The Throwable. */ @Override public void error(final String msg, final LogEvent event, final Throwable t) { final long current = System.nanoTime(); if (current - lastException > EXCEPTION_INTERVAL || exceptionCount++ < MAX_EXCEPTIONS) { LOGGER.error(msg, t); } lastException = current; if (!appender.ignoreExceptions() && t != null && !(t instanceof AppenderLoggingException)) { throw new AppenderLoggingException(msg, t); } }
@Override public void start() { super.start(); try { this.eventHubsManager.startup(); } catch (Throwable exception) { final String errMsg = String.format(Locale.US, "[%s] Appender initialization failed with error: [%s]", this.getName(), exception.getMessage()); LOGGER.error(errMsg); throw new AppenderLoggingException(errMsg, exception); } }
/** * Writes the specified section of the specified byte array to the stream. * * @param bytes the array containing data * @param offset from where to write * @param length how many bytes to write * @since 2.6 */ protected synchronized void writeToDestination(final byte[] bytes, final int offset, final int length) { try { getOutputStream().write(bytes, offset, length); } catch (final IOException ex) { throw new AppenderLoggingException("Error writing to stream " + getName(), ex); } }
private void handleError(final String prefix) { final String msg = appenderErrorHandlerMessage(prefix); if (!appender.ignoreExceptions()) { throw new AppenderLoggingException(msg); } }
@Override public void append(LogEvent event) { readLock.lock(); try{ final byte[] bytes = getLayout().toByteArray(event); LoggingConsoleRT.instance.addMessage(new String(bytes)); }catch(Exception e){ if(!ignoreExceptions()) throw new AppenderLoggingException(e); }finally{ readLock.unlock(); } }
private void tryCallAppender(final LogEvent event) { try { appender.append(event); } catch (final RuntimeException ex) { handleAppenderError(ex); } catch (final Exception ex) { handleAppenderError(new AppenderLoggingException(ex)); } }
@Override protected synchronized void writeToDestination(final byte[] bytes, final int offset, final int length) { try { if (randomAccessFile == null) { String fileName = getFileName(); File file = new File(fileName); FileUtils.makeParentDirs(file); createFileAfterRollover(fileName); } randomAccessFile.write(bytes, offset, length); size += length; } catch (final IOException ex) { final String msg = "Error writing to RandomAccessFile " + getName(); throw new AppenderLoggingException(msg, ex); } }