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);
}
}
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations