@Override public void stop() { super.stop(); if (advertiser != null) { advertiser.unadvertise(advertisement); } }
String getLogDir(Configuration conf) { String logDir = conf.get("hive.log.dir"); if (logDir == null) { logDir = System.getProperty("hive.log.dir"); } if (logDir != null) { return logDir; } LoggerContext context = (LoggerContext)LogManager.getContext(false); for (Logger logger: context.getLoggers()) { for (Appender appender: logger.getAppenders().values()) { if (appender instanceof AbstractOutputStreamAppender) { OutputStreamManager manager = ((AbstractOutputStreamAppender<?>)appender).getManager(); if (manager instanceof FileManager) { String fileName = ((FileManager)manager).getFileName(); if (fileName != null) { return fileName.substring(0, fileName.lastIndexOf('/')); } } } } } return null; }
/** * Write the log entry rolling over the file when required. * * @param event The LogEvent. */ @Override public void append(final LogEvent event) { // Unlike RandomAccessFileAppender, do not append log when stopped. if (isStopped()) { // Don't try to log anything when appender is stopped return; } // Leverage the nice batching behaviour of async Loggers/Appenders: // we can signal the file manager that it needs to flush the buffer // to disk at the end of a batch. // From a user's point of view, this means that all log events are // _always_ available in the log file, without incurring the overhead // of immediateFlush=true. getManager().setEndOfBatch(event.isEndOfBatch()); // FIXME manager's EndOfBatch threadlocal can be deleted // LOG4J2-1292 utilize gc-free Layout.encode() method: taken care of in superclass super.append(event); }
/** * Actual writing occurs here. * <p> * Most subclasses of <code>AbstractOutputStreamAppender</code> will need to override this method. * </p> * * @param event The LogEvent. */ @Override public void append(final LogEvent event) { try { tryAppend(event); } catch (final AppenderLoggingException ex) { error("Unable to write to stream " + manager.getName() + " for appender " + getName() + ": " + ex); throw ex; } }
private void tryAppend(final LogEvent event) { if (Constants.ENABLE_DIRECT_ENCODERS) { directEncodeEvent(event); } else { writeByteArrayToManager(event); } }
@Override protected boolean stop(final long timeout, final TimeUnit timeUnit, final boolean changeLifeCycleState) { boolean stopped = super.stop(timeout, timeUnit, changeLifeCycleState); stopped &= manager.stop(timeout, timeUnit); if (changeLifeCycleState) { setStopped(); } LOGGER.debug("Appender {} stopped with status {}", getName(), stopped); return stopped; }
protected void writeByteArrayToManager(final LogEvent event) { final byte[] bytes = getLayout().toByteArray(event); if (bytes != null && bytes.length > 0) { manager.write(bytes, this.immediateFlush || event.isEndOfBatch()); } } }
protected void directEncodeEvent(final LogEvent event) { getLayout().encode(event, manager); if (this.immediateFlush || event.isEndOfBatch()) { manager.flush(); } }
@Override public void stop() { LOGGER.info("Stopping {}.", this); delegate.stop(); super.stop(); }
String getLogDir(Configuration conf) { String logDir = conf.get("hive.log.dir"); if (logDir == null) { logDir = System.getProperty("hive.log.dir"); } if (logDir != null) { return logDir; } LoggerContext context = (LoggerContext)LogManager.getContext(false); for (Logger logger: context.getLoggers()) { for (Appender appender: logger.getAppenders().values()) { if (appender instanceof AbstractOutputStreamAppender) { OutputStreamManager manager = ((AbstractOutputStreamAppender<?>)appender).getManager(); if (manager instanceof FileManager) { String fileName = ((FileManager)manager).getFileName(); if (fileName != null) { return fileName.substring(0, fileName.lastIndexOf('/')); } } } } } return null; }
/** * Writes the log entry rolling over the file when required. * @param event The LogEvent. */ @Override public void append(final LogEvent event) { getManager().checkRollover(event); super.append(event); }
@Override public boolean stop(final long timeout, final TimeUnit timeUnit) { return stop(timeout, timeUnit, true); }
static void flushAll() { final LoggerContext logCtx = ((LoggerContext) LogManager.getContext()); for (final org.apache.logging.log4j.core.Logger logger : logCtx.getLoggers()) { for (final Appender appender : logger.getAppenders().values()) { if (appender instanceof AbstractOutputStreamAppender) { ((AbstractOutputStreamAppender) appender).getManager().flush(); } } } }
/** * Write the log entry rolling over the file when required. * * @param event The LogEvent. */ @Override public void append(final LogEvent event) { // Leverage the nice batching behaviour of async Loggers/Appenders: // we can signal the file manager that it needs to flush the buffer // to disk at the end of a batch. // From a user's point of view, this means that all log events are // _always_ available in the log file, without incurring the overhead // of immediateFlush=true. getManager().setEndOfBatch(event.isEndOfBatch()); // FIXME manager's EndOfBatch threadlocal can be deleted // LOG4J2-1292 utilize gc-free Layout.encode() method: taken care of in superclass super.append(event); }
@Override public boolean stop(long timeout, TimeUnit timeUnit, boolean changeLifeCycleState) { super.stop(timeout, timeUnit, false); if (advertiser != null) { advertiser.unadvertise(advertisement); } if (changeLifeCycleState) { setStopped(); } return true; }
public static void flushAll() { final LoggerContext logCtx = ((LoggerContext) LogManager.getContext()); for(final org.apache.logging.log4j.core.Logger logger : logCtx.getLoggers()) { for(final Appender appender : logger.getAppenders().values()) { if(appender instanceof AbstractOutputStreamAppender) { ((AbstractOutputStreamAppender) appender).getManager().flush(); } } } } //
/** * Write the log entry rolling over the file when required. * * @param event The LogEvent. */ @Override public void append(final LogEvent event) { // Leverage the nice batching behaviour of async Loggers/Appenders: // we can signal the file manager that it needs to flush the buffer // to disk at the end of a batch. // From a user's point of view, this means that all log events are // _always_ available in the log file, without incurring the overhead // of immediateFlush=true. getManager().setEndOfBatch(event.isEndOfBatch()); // FIXME manager's EndOfBatch threadlocal can be deleted super.append(event); // TODO should only call force() if immediateFlush && endOfBatch? }
@Override public boolean stop(final long timeout, final TimeUnit timeUnit) { setStopping(); super.stop(timeout, timeUnit, false); if (advertiser != null) { advertiser.unadvertise(advertisement); } setStopped(); return true; }
/** * Write the log entry rolling over the file when required. * * @param event The LogEvent. */ @Override public void append(final LogEvent event) { final RollingRandomAccessFileManager manager = getManager(); manager.checkRollover(event); // Leverage the nice batching behaviour of async Loggers/Appenders: // we can signal the file manager that it needs to flush the buffer // to disk at the end of a batch. // From a user's point of view, this means that all log events are // _always_ available in the log file, without incurring the overhead // of immediateFlush=true. manager.setEndOfBatch(event.isEndOfBatch()); // FIXME manager's EndOfBatch threadlocal can be deleted // LOG4J2-1292 utilize gc-free Layout.encode() method: taken care of in superclass super.append(event); }