Search in sources :

Example 1 with FileManager

use of org.apache.logging.log4j.core.appender.FileManager in project cryptomator by cryptomator.

the class ConfigurableFileAppender method createAppender.

@PluginFactory
public static AbstractAppender createAppender(@PluginAttribute("name") final String name, @PluginAttribute("pathPropertyName") final String pathPropertyName, @PluginAttribute("append") final String append, @PluginElement("Layout") Layout<? extends Serializable> layout) {
    if (name == null) {
        LOGGER.error("No name provided for ConfigurableFileAppender");
        return null;
    }
    if (pathPropertyName == null) {
        LOGGER.error("No pathPropertyName provided for ConfigurableFileAppender with name " + name);
        return null;
    }
    final String fileName = System.getProperty(pathPropertyName);
    if (Strings.isEmpty(fileName)) {
        LOGGER.warn("No log file location provided in system property \"" + pathPropertyName + "\"");
        return null;
    }
    final Path filePath = parsePath(fileName);
    if (filePath == null) {
        LOGGER.warn("Invalid path \"" + fileName + "\"");
        return null;
    }
    if (!Files.exists(filePath.getParent())) {
        try {
            Files.createDirectories(filePath.getParent());
        } catch (IOException e) {
            LOGGER.error("Could not create parent directories for log file located at " + filePath.toString(), e);
            return null;
        }
    }
    final boolean shouldAppend = Booleans.parseBoolean(append, true);
    if (layout == null) {
        layout = PatternLayout.createDefaultLayout();
    }
    final FileManager manager = FileManager.getFileManager(filePath.toString(), shouldAppend, false, true, null, layout, DEFAULT_BUFFER_SIZE);
    return new ConfigurableFileAppender(name, layout, null, manager);
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) FileManager(org.apache.logging.log4j.core.appender.FileManager) PluginFactory(org.apache.logging.log4j.core.config.plugins.PluginFactory)

Example 2 with FileManager

use of org.apache.logging.log4j.core.appender.FileManager in project hive by apache.

the class HttpServer method getLogDir.

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;
}
Also used : AbstractOutputStreamAppender(org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender) Appender(org.apache.logging.log4j.core.Appender) OutputStreamManager(org.apache.logging.log4j.core.appender.OutputStreamManager) AbstractOutputStreamAppender(org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender) Logger(org.apache.logging.log4j.core.Logger) LoggerContext(org.apache.logging.log4j.core.LoggerContext) FileManager(org.apache.logging.log4j.core.appender.FileManager)

Aggregations

FileManager (org.apache.logging.log4j.core.appender.FileManager)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Appender (org.apache.logging.log4j.core.Appender)1 Logger (org.apache.logging.log4j.core.Logger)1 LoggerContext (org.apache.logging.log4j.core.LoggerContext)1 AbstractOutputStreamAppender (org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender)1 OutputStreamManager (org.apache.logging.log4j.core.appender.OutputStreamManager)1 PluginFactory (org.apache.logging.log4j.core.config.plugins.PluginFactory)1