java.util.logging.ErrorManager Java Examples

The following examples show how to use java.util.logging.ErrorManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileHandler.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * 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();
    }

}
 
Example #2
Source File: SocketHandler.java    From jboss-logmanager-ext with Apache License 2.0 6 votes vote down vote up
private OutputStream createOutputStream() {
    if (address != null || port >= 0) {
        try {
            if (protocol == Protocol.SSL_TCP) {
                return new SslTcpOutputStream(address, port);
            } else if (protocol == Protocol.UDP) {
                return new UdpOutputStream(address, port);
            } else {
                return new TcpOutputStream(address, port);
            }
        } catch (IOException e) {
            reportError("Failed to create socket output stream", e, ErrorManager.OPEN_FAILURE);
        }
    }
    return null;
}
 
Example #3
Source File: VmRuntimeLogHandler.java    From appengine-java-vm-runtime with Apache License 2.0 6 votes vote down vote up
@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));
  }
}
 
Example #4
Source File: DataflowWorkerLoggingHandler.java    From beam with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void close() {
  // Flush any in-flight content, though there should not actually be any because
  // the generator is currently flushed in the synchronized publish() method.
  flush();
  // Close the generator and log file.
  try {
    if (generator != null) {
      generator.close();
    }
  } catch (IOException | RuntimeException e) {
    reportFailure("Unable to close", e, ErrorManager.CLOSE_FAILURE);
  } finally {
    generator = null;
    counter = null;
  }
}
 
Example #5
Source File: WriterHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
private synchronized void flushAndClose() throws SecurityException {

        if (writer != null) {
            try {
                if (!doneHeader) {
                    writer.write(getFormatter().getHead(this));
                    doneHeader = true;
                }
                writer.write(getFormatter().getTail(this));
                writer.flush();
                writer.close();
            } 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.CLOSE_FAILURE);
            }
            writer = null;

        }
    }
 
Example #6
Source File: FileHandler.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
    }
    
}
 
Example #7
Source File: FileHandler.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #8
Source File: FileHandler.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
    }
    
}
 
Example #9
Source File: FileHandler.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #10
Source File: LocalFileHandler.java    From tomee with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #11
Source File: FileHandler.java    From tomee with Apache License 2.0 6 votes vote down vote up
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();
        }
    }
 
Example #12
Source File: FileHandler.java    From tomee with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
    }

}
 
Example #13
Source File: FileHandler.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
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();
        }
    }
 
Example #14
Source File: LoggingSetupRecorder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static Map<String, Handler> createNamedHandlers(LogConfig config,
        List<RuntimeValue<Optional<Formatter>>> possibleFormatters, ErrorManager errorManager,
        List<LogCleanupFilterElement> filterElements) {
    Map<String, Handler> namedHandlers = new HashMap<>();
    for (Entry<String, ConsoleConfig> consoleConfigEntry : config.consoleHandlers.entrySet()) {
        final Handler consoleHandler = configureConsoleHandler(consoleConfigEntry.getValue(), errorManager, filterElements,
                possibleFormatters, null);
        addToNamedHandlers(namedHandlers, consoleHandler, consoleConfigEntry.getKey());
    }
    for (Entry<String, FileConfig> fileConfigEntry : config.fileHandlers.entrySet()) {
        final Handler fileHandler = configureFileHandler(fileConfigEntry.getValue(), errorManager, filterElements);
        addToNamedHandlers(namedHandlers, fileHandler, fileConfigEntry.getKey());
    }
    for (Entry<String, SyslogConfig> sysLogConfigEntry : config.syslogHandlers.entrySet()) {
        final Handler syslogHandler = configureSyslogHandler(sysLogConfigEntry.getValue(), errorManager, filterElements);
        if (syslogHandler != null) {
            addToNamedHandlers(namedHandlers, syslogHandler, sysLogConfigEntry.getKey());
        }
    }
    return namedHandlers;
}
 
Example #15
Source File: FileHandler.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private void clean() {
    if (maxDays <= 0) {
        return;
    }
    DELETE_FILES_SERVICE.submit(new Runnable() {

        @Override
        public void run() {
            try (DirectoryStream<Path> files = streamFilesForDelete()) {
                for (Path file : files) {
                    Files.delete(file);
                }
            } catch (IOException e) {
                reportError("Unable to delete log files older than [" + maxDays + "] days",
                        null, ErrorManager.GENERIC_FAILURE);
            }
        }
    });
}
 
Example #16
Source File: LocalFileHandler.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void flush() {
    writerLock.readLock().lock();
    try {
        writer.flush();
    } catch (final Exception e) {
        reportError(null, e, ErrorManager.FLUSH_FAILURE);
    } finally {
        writerLock.readLock().unlock();
    }
}
 
Example #17
Source File: WriterHandler.java    From cxf with Apache License 2.0 5 votes vote down vote up
public synchronized void flush() {
    if (writer != null) {
        try {
            writer.flush();
        } 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.FLUSH_FAILURE);
        }
    }
}
 
Example #18
Source File: TNT4JLoggingHandler.java    From TNT4J with Apache License 2.0 5 votes vote down vote up
@Override
public void flush() {
	try {
		logger.getEventSink().flush();
	} catch (IOException e) {
		this.getErrorManager().error("Unable to flush logger=" + logger, e, ErrorManager.FLUSH_FAILURE);
	}
}
 
Example #19
Source File: TNT4JLoggingHandler.java    From TNT4J with Apache License 2.0 5 votes vote down vote up
/**
 * Activate &amp; initialize logging handler
 *
 * @param name
 *            logger/source name
 * @param type
 *            source type
 */
protected void activate(String name, SourceType type) {
	try {
		logger = TrackingLogger.getInstance(name, type);
		logger.open();
	} catch (IOException e) {
		this.getErrorManager().error("Unable to create tracker instance=" + name, e, ErrorManager.OPEN_FAILURE);
	}
}
 
Example #20
Source File: SimpleLogHandler.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void flush() {
  if (output.isOpen()) {
    try {
      output.flush();
    } catch (IOException e) {
      reportError(null, e, ErrorManager.FLUSH_FAILURE);
    }
  }
}
 
Example #21
Source File: FileLogHandler.java    From slf4android with MIT License 5 votes vote down vote up
@Override
public void setErrorManager(ErrorManager newErrorManager) {
    super.setErrorManager(newErrorManager);
    ensureInitialized();
    if (fileHandler != null) {
        fileHandler.setErrorManager(newErrorManager);
    }
}
 
Example #22
Source File: SocketHandler.java    From jboss-logmanager-ext with Apache License 2.0 5 votes vote down vote up
private void safeFlush(Flushable f) {
    try {
        if (f != null) f.flush();
    } catch (Exception e) {
        reportError("Error on flush", e, ErrorManager.FLUSH_FAILURE);
    } catch (Throwable ignored) {
    }
}
 
Example #23
Source File: SocketHandler.java    From jboss-logmanager-ext with Apache License 2.0 5 votes vote down vote up
private void safeClose(Closeable c) {
    try {
        if (c != null) c.close();
    } catch (Exception e) {
        reportError("Error closing resource", e, ErrorManager.CLOSE_FAILURE);
    } catch (Throwable ignored) {
    }
}
 
Example #24
Source File: FileHandler.java    From tomee with Apache License 2.0 5 votes vote down vote up
protected void openWriter() {

        // Create the directory if necessary
        final File dir = new File(directory);
        if (!dir.mkdirs() && !dir.isDirectory()) {
            reportError("Unable to create [" + dir + "]", null,
                ErrorManager.OPEN_FAILURE);
            writer = null;
            return;
        }

        // Open the current log file
        writerLock.writeLock().lock();
        try {
            final File pathname = new File(dir.getAbsoluteFile(), prefix
                + (rotatable ? date : "") + suffix);
            final File parent = pathname.getParentFile();
            if (!parent.mkdirs() && !parent.isDirectory()) {
                reportError("Unable to create [" + parent + "]", null,
                    ErrorManager.OPEN_FAILURE);
                writer = null;
                return;
            }
            final String encoding = getEncoding();
            final FileOutputStream fos = new FileOutputStream(pathname, true);
            final OutputStream os = bufferSize > 0 ? new BufferedOutputStream(fos, bufferSize) : fos;
            writer = new PrintWriter(
                encoding != null ? new OutputStreamWriter(os, encoding)
                    : new OutputStreamWriter(os), false);
            writer.write(getFormatter().getHead(this));
        } catch (final Exception e) {
            reportError(null, e, ErrorManager.OPEN_FAILURE);
            writer = null;
        } finally {
            writerLock.writeLock().unlock();
        }

    }
 
Example #25
Source File: SocketHandler.java    From jboss-logmanager-ext with Apache License 2.0 5 votes vote down vote up
private void writeTail(final Writer writer) {
    try {
        final Formatter formatter = getFormatter();
        if (formatter != null) writer.write(formatter.getTail(this));
    } catch (Exception ex) {
        reportError("Error writing section tail", ex, ErrorManager.WRITE_FAILURE);
    }
}
 
Example #26
Source File: FluentdHandler.java    From thorntail with Apache License 2.0 5 votes vote down vote up
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) {
    }
}
 
Example #27
Source File: LoggingSetupRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private void addNamedHandlersToCategory(CategoryConfig categoryConfig, Map<String, Handler> namedHandlers,
        Logger categoryLogger,
        ErrorManager errorManager) {
    for (String categoryNamedHandler : categoryConfig.handlers.get()) {
        if (namedHandlers.get(categoryNamedHandler) != null) {
            categoryLogger.addHandler(namedHandlers.get(categoryNamedHandler));
        } else {
            errorManager.error(String.format("Handler with name '%s' is linked to a category but not configured.",
                    categoryNamedHandler), null, ErrorManager.GENERIC_FAILURE);
        }
    }
}
 
Example #28
Source File: LoggingSetupRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static Handler configureFileHandler(final FileConfig config, final ErrorManager errorManager,
        final List<LogCleanupFilterElement> filterElements) {
    FileHandler handler = new FileHandler();
    FileConfig.RotationConfig rotationConfig = config.rotation;
    if ((rotationConfig.maxFileSize.isPresent() || rotationConfig.rotateOnBoot)
            && rotationConfig.fileSuffix.isPresent()) {
        PeriodicSizeRotatingFileHandler periodicSizeRotatingFileHandler = new PeriodicSizeRotatingFileHandler();
        periodicSizeRotatingFileHandler.setSuffix(rotationConfig.fileSuffix.get());
        rotationConfig.maxFileSize
                .ifPresent(memorySize -> periodicSizeRotatingFileHandler.setRotateSize(memorySize.asLongValue()));
        periodicSizeRotatingFileHandler.setRotateOnBoot(rotationConfig.rotateOnBoot);
        periodicSizeRotatingFileHandler.setMaxBackupIndex(rotationConfig.maxBackupIndex);
        handler = periodicSizeRotatingFileHandler;
    } else if (rotationConfig.maxFileSize.isPresent()) {
        SizeRotatingFileHandler sizeRotatingFileHandler = new SizeRotatingFileHandler(
                rotationConfig.maxFileSize.get().asLongValue(), rotationConfig.maxBackupIndex);
        sizeRotatingFileHandler.setRotateOnBoot(rotationConfig.rotateOnBoot);
        handler = sizeRotatingFileHandler;
    } else if (rotationConfig.fileSuffix.isPresent()) {
        PeriodicRotatingFileHandler periodicRotatingFileHandler = new PeriodicRotatingFileHandler();
        periodicRotatingFileHandler.setSuffix(rotationConfig.fileSuffix.get());
        handler = periodicRotatingFileHandler;
    }

    final PatternFormatter formatter = new PatternFormatter(config.format);
    handler.setFormatter(formatter);
    handler.setAppend(true);
    try {
        handler.setFile(config.path);
    } catch (FileNotFoundException e) {
        errorManager.error("Failed to set log file", e, ErrorManager.OPEN_FAILURE);
    }
    handler.setErrorManager(errorManager);
    handler.setLevel(config.level);
    handler.setFilter(new LogCleanupFilter(filterElements));
    if (config.async.enable) {
        return createAsyncHandler(config.async, config.level, handler);
    }
    return handler;
}
 
Example #29
Source File: LoggingSetupRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static Handler configureSyslogHandler(final SyslogConfig config,
        final ErrorManager errorManager,
        final List<LogCleanupFilterElement> filterElements) {
    try {
        final SyslogHandler handler = new SyslogHandler(config.endpoint.getHostString(), config.endpoint.getPort());
        handler.setAppName(config.appName.orElse(getProcessName()));
        handler.setHostname(config.hostname.orElse(getQualifiedHostName()));
        handler.setFacility(config.facility);
        handler.setSyslogType(config.syslogType);
        handler.setProtocol(config.protocol);
        handler.setBlockOnReconnect(config.blockOnReconnect);
        handler.setTruncate(config.truncate);
        handler.setUseCountingFraming(config.useCountingFraming);
        handler.setLevel(config.level);
        final PatternFormatter formatter = new PatternFormatter(config.format);
        handler.setFormatter(formatter);
        handler.setErrorManager(errorManager);
        handler.setFilter(new LogCleanupFilter(filterElements));
        if (config.async.enable) {
            return createAsyncHandler(config.async, config.level, handler);
        }
        return handler;
    } catch (IOException e) {
        errorManager.error("Failed to create syslog handler", e, ErrorManager.OPEN_FAILURE);
        return null;
    }
}
 
Example #30
Source File: ProjectHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
    }
}