protected void closeWriter() { writerLock.writeLock().lock(); try { if (writer == null) return; writer.write(getFormatter().getTail(this)); writer.flush(); writer.close(); writer = null; date = ""; } catch (Exception e) { reportError(null, e, ErrorManager.CLOSE_FAILURE); } finally { writerLock.writeLock().unlock(); } }
/** * Flush the writer. */ @Override public void flush() { writerLock.readLock().lock(); try { if (writer == null) return; writer.flush(); } catch (Exception e) { reportError(null, e, ErrorManager.FLUSH_FAILURE); } finally { writerLock.readLock().unlock(); } }
/** * Close the currently open log file (if any). */ public void close() { try { if (writer == null) return; writer.write(getFormatter().getTail(this)); writer.flush(); writer.close(); writer = null; date = ""; } catch (Exception e) { reportError(null, e, ErrorManager.CLOSE_FAILURE); } }
/** * Open the new log file for the date specified by <code>date</code>. */ private void open() { // Create the directory if necessary File dir = new File(directory); dir.mkdirs(); // Open the current log file try { String pathname = dir.getAbsolutePath() + File.separator + prefix + date + suffix; writer = new PrintWriter(new FileWriter(pathname, true), true); writer.write(getFormatter().getHead(this)); } catch (Exception e) { reportError(null, e, ErrorManager.OPEN_FAILURE); writer = null; } }
@Override public void publish(LogRecord record) { if (isLoggable(record)) { try { if (this.logWriter instanceof LogWriterLogger) { ((LogWriterLogger) this.logWriter).log(record.getLevel().intValue(), getMessage(record), record.getThrown()); } else { ((LogWriterImpl) this.logWriter).put(record.getLevel().intValue(), getMessage(record), record.getThrown()); } } catch (GemFireException ex) { reportError(null, ex, ErrorManager.WRITE_FAILURE); } } }
private synchronized void rotate() { Level oldLevel = getLevel(); setLevel(Level.OFF); super.close(); if (desc) rotateDesc(); else rotateAsc(); try { open(files[0], false); } catch (IOException ix) { // We don't want to throw an exception here, but we // report the exception to any registered ErrorManager. reportError(null, ix, ErrorManager.OPEN_FAILURE); } setLevel(oldLevel); }
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); }
private 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 { // $ANALYSIS-IGNORE output = new MeasureOutputStream( new BufferedOutputStream( new FileOutputStream( files[0] ) ) ); } catch ( FileNotFoundException e1 ) { // logging.1A=Error happened when open log file. this.getErrorManager().error( "BatchedAsynchronousFileHandler Output stream open failure. ", //$NON-NLS-1$ e1, ErrorManager.OPEN_FAILURE ); } setOutputStream( output ); }
@Override public void publish(LogRecord record) { // first check if this record should be logged (log level and filters are checked) if (!isLoggable(record)) { return; } JSONObject obj = new JSONObject(); try { obj.put("@timestamp", Utils.iso8601(record.getMillis())); obj.put("level", record.getLevel().toString()); obj.put("message", getFormatter().formatMessage(record)); obj.put("logger", record.getLoggerName()); obj.put("seqNum", record.getSequenceNumber()); obj.put("threadId", record.getThreadID()); obj.put("sourceClass", record.getSourceClassName()); obj.put("sourceMethod", record.getSourceMethodName()); if (record.getThrown() != null) { obj.put("stacktrace", Utils.getStackTrace(record.getThrown())); } logsene.event(obj); } catch (JSONException e) { // should never happen, as exception is thrown when key in put() is null reportError("Unable to construct json object", e, ErrorManager.GENERIC_FAILURE); } }
public void testConstructor_Properties() throws Exception { Properties p = new Properties(); p.put("java.util.logging.MockHandler.level", "FINE"); p .put("java.util.logging.MockHandler.filter", className + "$MockFilter"); p.put("java.util.logging.Handler.formatter", className + "$MockFormatter"); p.put("java.util.logging.MockHandler.encoding", "utf-8"); LogManager.getLogManager().readConfiguration( EnvironmentHelper.PropertiesToInputStream(p)); assertEquals(LogManager.getLogManager().getProperty( "java.util.logging.MockHandler.level"), "FINE"); assertEquals(LogManager.getLogManager().getProperty( "java.util.logging.MockHandler.encoding"), "utf-8"); MockHandler h = new MockHandler(); assertSame(h.getLevel(), Level.ALL); assertNull(h.getFormatter()); assertNull(h.getFilter()); assertNull(h.getEncoding()); assertTrue(h.getErrorManager() instanceof ErrorManager); LogManager.getLogManager().reset(); }
private String createFormattedMessage(final ExtLogRecord record) { final Formatter formatter = getFormatter(); try { return formatter.format(record); } catch (Exception e) { reportError("Could not format message", e, ErrorManager.FORMAT_FAILURE); return null; } }
private OutputStream createOutputStream() { if (address != null || port >= 0) { try { switch (protocol) { case SSL_TCP: SslTcpOutputStream sos = new SslTcpOutputStream(address, port); if (sos.isConnected()) { return sos; } break; case UDP: return new UdpOutputStream(address, port); case TCP: default: TcpOutputStream tos = new TcpOutputStream(address, port); if (tos.isConnected()) { return tos; } break; } } catch (IOException e) { reportError("Failed to create socket output stream", e, ErrorManager.OPEN_FAILURE); } } return null; }
@Override public void publish(LogRecord record) { if (!isLoggable(record)) { return; } // The formatter isn't necessarily thread-safe, so we synchronize around it. String message; synchronized (this) { try { message = getFormatter().format(record); } catch (Exception ex) { // We don't want to throw an exception here, but we // report the exception to any registered ErrorManager. reportError(null, ex, ErrorManager.FORMAT_FAILURE); return; } } VmApiProxyEnvironment environment = getThreadLocalEnvironment(); if (environment != null) { environment.addLogRecord(convertLogRecord(record, message)); } }
@Override public void close() { closed = true; writerLock.writeLock().lock(); try { if (writer == null) { return; } writer.write(getFormatter().getTail(this)); writer.flush(); writer.close(); writer = null; } catch (final Exception e) { reportError(null, e, ErrorManager.CLOSE_FAILURE); } finally { writerLock.writeLock().unlock(); } // wait for bg tasks if running backgroundTaskLock.lock(); backgroundTaskLock.unlock(); }
protected void closeWriter() { writerLock.writeLock().lock(); try { if (writer == null) { return; } writer.write(getFormatter().getTail(this)); writer.flush(); writer.close(); writer = null; date = ""; } catch (final Exception e) { reportError(null, e, ErrorManager.CLOSE_FAILURE); } finally { writerLock.writeLock().unlock(); } }
/** * Flush the writer. */ @Override public void flush() { writerLock.readLock().lock(); try { if (writer == null) { return; } writer.flush(); } catch (final Exception e) { reportError(null, e, ErrorManager.FLUSH_FAILURE); } finally { writerLock.readLock().unlock(); } }
public static void disableCoS(Project p, final boolean enable) { final AntProjectHelper helper = getAntProjectHelper(p); if (helper == null) { if (enable) { StatusDisplayer.getDefault().setStatusText( NbBundle.getMessage(ProjectHelper.class, "WARN_couldNotEnableCoS"), StatusDisplayer.IMPORTANCE_ERROR_HIGHLIGHT); } return; } try { ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() { @Override public Void run() throws Exception { EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); if (enable) { ep.setProperty(JAXB_COMPILE_ON_SAVE, Boolean.TRUE.toString()); } else { ep.remove(JAXB_COMPILE_ON_SAVE); } helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); return null; } }); } catch (MutexException ex) { org.openide.ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, ex); } }
/** * Flush the writer. */ public void flush() { try { writer.flush(); } catch (Exception e) { reportError(null, e, ErrorManager.FLUSH_FAILURE); } }
/** * */ public void publish(LogRecord record) { if (!isLoggable(record)) { return; } String message; try { message = getFormatter().format(record); } catch (Exception exception) { reportError(null, exception, ErrorManager.FORMAT_FAILURE); return; } synchronized (textPane) { if (textPane.getDocument().getLength() >= MAXIMUM_DOCUMENT_SIZE) { // Delete the contents of the text pane. textPane.setText(""); } try { if (record.getLevel() == Level.SEVERE) { textPane.getDocument().insertString(textPane.getDocument().getLength(), message, severStyle); } else { textPane.getDocument().insertString(textPane.getDocument().getLength(), message, infoStyle); } textPane.setCaretPosition(textPane.getDocument().getLength()); } catch (Exception ex) { reportError(null, ex, ErrorManager.WRITE_FAILURE); } } }
private void printInvalidPropertyMessage( String key, String value, Exception e ) { // logging.12=Invalid property value for String msg = new StringBuilder().append( "Invalid property." ) //$NON-NLS-1$ .append( prefix ).append( ":" ).append( key ).append( "/" ).append( //$NON-NLS-1$//$NON-NLS-2$ value ).toString(); reportError( msg, e, ErrorManager.GENERIC_FAILURE ); }
@Override protected void doPublish(ExtLogRecord record) { synchronized (this) { if (!initialized) { try { initialize(); } catch (Exception e) { reportError("Error creating fluentd connection", e, ErrorManager.OPEN_FAILURE); setEnabled(false); } } } if (initialized) { Map<String, Object> entries = new HashMap<>(); entries.put(Key.SEQUENCE.getKey(), record.getSequenceNumber()); entries.put(Key.LEVEL.getKey(), record.getLevel().getName()); entries.put(Key.THREAD_NAME.getKey(), record.getThreadName()); entries.put(Key.MESSAGE.getKey(), record.getFormattedMessage()); entries.put(Key.THREAD_ID.getKey(), record.getThreadID()); entries.put(Key.MDC.getKey(), record.getMdcCopy()); entries.put(Key.NDC.getKey(), record.getNdc()); this.sender.emit(this.tag, record.getMillis(), entries); } }
private void safeClose(RawSocketSender c) { try { if (c != null) { c.close(); } } catch (Exception e) { reportError("Error closing resource", e, ErrorManager.CLOSE_FAILURE); } catch (Throwable ignored) { } }
@Override public void publish(LogRecord record) { try { String message = this.formatter.format(record); if (record.getLevel().intValue() >= Level.WARNING.intValue()) { System.err.write(message.getBytes()); } else { System.out.write(message.getBytes()); } } catch (Exception exception) { super.reportError(null, exception, ErrorManager.FORMAT_FAILURE); } }
private Optional<String> formatRecord(final LogRecord record) { try { return Optional.of(getFormatter().format(record)); } catch (final RuntimeException e) { reportError(null, e, ErrorManager.FORMAT_FAILURE); return Optional.empty(); } }
private void writeMessage(final Level level, final String message) { final PrintStream stream = getStreamFor(level); try { stream.print(message); stream.flush(); } catch (final RuntimeException e) { reportError(null, e, ErrorManager.WRITE_FAILURE); } }