Search in sources :

Example 36 with FileAppender

use of org.apache.log4j.FileAppender in project com.revolsys.open by revolsys.

the class ThreadLocalFileAppender method removeLocalFile.

public void removeLocalFile() {
    final String localFileName = this.localFile.get();
    if (localFileName != null) {
        this.localAppender.set(null);
        this.localFile.set(null);
        final FileAppender appender = this.appenders.get(localFileName);
        if (appender != null) {
            appender.close();
            this.appenders.remove(localFileName);
        }
    }
}
Also used : FileAppender(org.apache.log4j.FileAppender)

Example 37 with FileAppender

use of org.apache.log4j.FileAppender in project openmrs-core by openmrs.

the class OpenmrsUtil method setupLogAppenders.

/**
 * Setup root level log appenders.
 *
 * @since 1.9.2
 */
public static void setupLogAppenders() {
    Logger rootLogger = Logger.getRootLogger();
    FileAppender fileAppender = null;
    @SuppressWarnings("rawtypes") Enumeration appenders = rootLogger.getAllAppenders();
    while (appenders.hasMoreElements()) {
        Appender appender = (Appender) appenders.nextElement();
        if (OpenmrsConstants.LOG_OPENMRS_FILE_APPENDER.equals(appender.getName())) {
            // the appender already exists
            fileAppender = (FileAppender) appender;
            break;
        }
    }
    String logLayout = Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GP_LOG_LAYOUT, "%p - %C{1}.%M(%L) |%d{ISO8601}| %m%n");
    PatternLayout patternLayout = new PatternLayout(logLayout);
    String logLocation = null;
    try {
        logLocation = OpenmrsUtil.getOpenmrsLogLocation();
        if (fileAppender == null) {
            fileAppender = new RollingFileAppender(patternLayout, logLocation);
            fileAppender.setName(OpenmrsConstants.LOG_OPENMRS_FILE_APPENDER);
            rootLogger.addAppender(fileAppender);
        } else {
            fileAppender.setFile(logLocation);
            fileAppender.setLayout(patternLayout);
        }
        fileAppender.activateOptions();
    } catch (IOException e) {
        log.error("Error while setting an OpenMRS log file to " + logLocation, e);
    }
}
Also used : RollingFileAppender(org.apache.log4j.RollingFileAppender) FileAppender(org.apache.log4j.FileAppender) RollingFileAppender(org.apache.log4j.RollingFileAppender) Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) Enumeration(java.util.Enumeration) RollingFileAppender(org.apache.log4j.RollingFileAppender) PatternLayout(org.apache.log4j.PatternLayout) IOException(java.io.IOException) Logger(org.apache.log4j.Logger)

Example 38 with FileAppender

use of org.apache.log4j.FileAppender in project devonfw-testing by devonfw.

the class BFLoggerInstance method createFileAppender.

private FileAppender createFileAppender() {
    PatternLayout patternLayout = new PatternLayout(logPattern);
    FileAppender appender;
    try {
        appender = new FileAppender(patternLayout, getLogFile().getPath(), true);
        appender.setName(getAppenderName());
        appender.setThreshold(Level.DEBUG);
        appender.activateOptions();
    } catch (Exception e) {
        System.out.println("Unable to create appender: " + e);
        return null;
    }
    return appender;
}
Also used : FileAppender(org.apache.log4j.FileAppender) PatternLayout(org.apache.log4j.PatternLayout) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 39 with FileAppender

use of org.apache.log4j.FileAppender in project openzaly by akaxincom.

the class LogCreater method createLogger.

/**
 * @param logName
 *            log文件名称
 * @param logPath
 *            log路径
 * @param layout
 *            log布局
 * @param additivity
 *            子类appender是否集成父类appender
 * @param isDailyMode
 *            是否按天来记录
 * @return
 */
public static Logger createLogger(String logName, String logPath, PatternLayout layout, boolean additivity, boolean isDailyMode) {
    Logger createdLogger = Logger.getLogger(logName);
    try {
        String logFileName = null;
        if (StringUtils.isEmpty(logPath)) {
            logFileName = DEFAULT_SITE_PATH + logName + ".log";
        } else if (logPath.endsWith("/")) {
            logFileName = logPath + logName + ".log";
        } else {
            logFileName = logPath + "/" + logName + ".log";
        }
        FileAppender fileAppender = null;
        if (isDailyMode) {
            fileAppender = new DailyRollingFileAppender(layout, logFileName, "'.'yyyy-MM-dd");
        } else {
            fileAppender = new RollingFileAppender(layout, logFileName, true);
            RollingFileAppender rollingAppender = (RollingFileAppender) fileAppender;
            rollingAppender.setMaxFileSize("200MB");
            rollingAppender.setMaxBackupIndex(5);
        }
        // not need bufferedIO
        // fileAppender.setBufferedIO(true);
        // fileAppender.setBufferSize(8192);
        createdLogger = Logger.getLogger(logName);
        createdLogger.removeAllAppenders();
        createdLogger.setAdditivity(additivity);
        createdLogger.addAppender(fileAppender);
    } catch (Exception e) {
        logger.error("create logger error", e);
        throw new RuntimeException();
    }
    return createdLogger;
}
Also used : DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender) FileAppender(org.apache.log4j.FileAppender) RollingFileAppender(org.apache.log4j.RollingFileAppender) DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender) RollingFileAppender(org.apache.log4j.RollingFileAppender) Logger(org.apache.log4j.Logger) DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender)

Example 40 with FileAppender

use of org.apache.log4j.FileAppender in project phpinspectionsea by kalessil.

the class EAApplicationComponent method initComponent.

@Override
public void initComponent() {
    IdeaPluginDescriptor plugin = PluginManager.getPlugin(PluginId.getId("com.kalessil.phpStorm.phpInspectionsEA"));
    if (null == plugin) {
        return;
    }
    final EASettings settings = EASettings.getInstance();
    /* collect installation events (anonymous) */
    this.updated = !plugin.getVersion().equals(settings.getVersion());
    if (this.updated) {
        settings.setVersion(plugin.getVersion());
        AnalyticsUtil.registerPluginEvent(settings, "install", settings.getOldestVersion());
    }
    AnalyticsUtil.registerPluginEvent(settings, "run", settings.getOldestVersion());
    /* collect exceptions */
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
        final FileAppender appender = new FileAppender() {

            @Override
            public void append(@NotNull LoggingEvent event) {
                final ThrowableInformation exceptionDetails = event.getThrowableInformation();
                if (exceptionDetails != null) {
                    AnalyticsUtil.registerLoggedException(settings.getVersion(), settings.getUuid(), exceptionDetails.getThrowable());
                }
            }
        };
        appender.setName("ea-exceptions-tracker");
        Logger.getRootLogger().addAppender(appender);
    }
}
Also used : FileAppender(org.apache.log4j.FileAppender) LoggingEvent(org.apache.log4j.spi.LoggingEvent) ThrowableInformation(org.apache.log4j.spi.ThrowableInformation) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FileAppender (org.apache.log4j.FileAppender)47 Appender (org.apache.log4j.Appender)18 File (java.io.File)15 IOException (java.io.IOException)14 PatternLayout (org.apache.log4j.PatternLayout)14 Logger (org.apache.log4j.Logger)12 ConsoleAppender (org.apache.log4j.ConsoleAppender)8 Layout (org.apache.log4j.Layout)5 Enumeration (java.util.Enumeration)4 Properties (java.util.Properties)4 FileNotFoundException (java.io.FileNotFoundException)3 DailyRollingFileAppender (org.apache.log4j.DailyRollingFileAppender)3 RollingFileAppender (org.apache.log4j.RollingFileAppender)3 SimpleLayout (org.apache.log4j.SimpleLayout)3 InputStream (java.io.InputStream)2 HTMLLayout (org.apache.log4j.HTMLLayout)2 LoggingEvent (org.apache.log4j.spi.LoggingEvent)2 LoggerChannel (com.biglybt.pif.logging.LoggerChannel)1 LoggerChannelListener (com.biglybt.pif.logging.LoggerChannelListener)1 LogProfileInfo (com.creditease.uav.profiling.handlers.log.LogProfileInfo)1