use of org.apache.log4j.Appender in project incubator-atlas by apache.
the class FailedMessagesLogger method getRootLoggerDirectory.
/**
* Get the root logger file location under which the failed log messages will be written.
*
* Since this class is used in Hooks which run within JVMs of other components like Hive,
* we want to write the failed messages file under the same location as where logs from
* the host component are saved. This method attempts to get such a location from the
* root logger's appenders. It will work only if at least one of the appenders is a {@link FileAppender}
*
* @return directory under which host component's logs are stored.
*/
private String getRootLoggerDirectory() {
String rootLoggerDirectory = null;
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
Enumeration allAppenders = rootLogger.getAllAppenders();
if (allAppenders != null) {
while (allAppenders.hasMoreElements()) {
Appender appender = (Appender) allAppenders.nextElement();
if (appender instanceof FileAppender) {
FileAppender fileAppender = (FileAppender) appender;
String rootLoggerFile = fileAppender.getFile();
rootLoggerDirectory = new File(rootLoggerFile).getParent();
break;
}
}
}
return rootLoggerDirectory;
}
use of org.apache.log4j.Appender in project ignite by apache.
the class GridVmNodesStarter method getConfigurations.
/**
* Initializes configurations.
*
*
* @param springCfgPath Configuration file path.
* @return List of configurations.
* @throws IgniteCheckedException If an error occurs.
*/
@SuppressWarnings("unchecked")
private static Iterable<IgniteConfiguration> getConfigurations(String springCfgPath) throws IgniteCheckedException {
File path = GridTestUtils.resolveIgnitePath(springCfgPath);
if (path == null)
throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + ". Note that this path should be either absolute path or a relative path to IGNITE_HOME.");
if (!path.isFile())
throw new IgniteCheckedException("Provided file path is not a file: " + path);
// Add no-op logger to remove no-appender warning.
Appender app = new NullAppender();
Logger.getRootLogger().addAppender(app);
ApplicationContext springCtx;
try {
springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString());
} catch (BeansException | MalformedURLException e) {
throw new IgniteCheckedException("Failed to instantiate Spring XML application context: " + e.getMessage(), e);
}
Map cfgMap;
try {
// Note: Spring is not generics-friendly.
cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
} catch (BeansException e) {
throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e);
}
if (cfgMap == null)
throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path);
// Remove previously added no-op logger.
Logger.getRootLogger().removeAppender(app);
if (cfgMap.isEmpty())
throw new IgniteCheckedException("Can't find grid factory configuration in: " + path);
Collection<IgniteConfiguration> res = new ArrayList<>();
for (IgniteConfiguration cfg : (Collection<IgniteConfiguration>) cfgMap.values()) {
res.add(cfg);
cfg.setIgniteInstanceName(IGNITE_INSTANCE_NAME_PREF + gridCnt.incrementAndGet());
}
return res;
}
use of org.apache.log4j.Appender in project ignite by apache.
the class GridRandomCommandLineLoader method getConfiguration.
/**
* Initializes configurations.
*
* @param springCfgPath Configuration file path.
* @param logCfgPath Log file name.
* @return List of configurations.
* @throws IgniteCheckedException If an error occurs.
*/
@SuppressWarnings("unchecked")
private static IgniteConfiguration getConfiguration(String springCfgPath, @Nullable String logCfgPath) throws IgniteCheckedException {
assert springCfgPath != null;
File path = GridTestUtils.resolveIgnitePath(springCfgPath);
if (path == null)
throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + ". Note that this path should be either absolute path or a relative path to IGNITE_HOME.");
if (!path.isFile())
throw new IgniteCheckedException("Provided file path is not a file: " + path);
// Add no-op logger to remove no-appender warning.
Appender app = new NullAppender();
Logger.getRootLogger().addAppender(app);
ApplicationContext springCtx;
try {
springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString());
} catch (BeansException | MalformedURLException e) {
throw new IgniteCheckedException("Failed to instantiate Spring XML application context: " + e.getMessage(), e);
}
Map cfgMap;
try {
// Note: Spring is not generics-friendly.
cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
} catch (BeansException e) {
throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e);
}
if (cfgMap == null)
throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path);
// Remove previously added no-op logger.
Logger.getRootLogger().removeAppender(app);
if (cfgMap.size() != 1)
throw new IgniteCheckedException("Spring configuration file should contain exactly 1 grid configuration: " + path);
IgniteConfiguration cfg = (IgniteConfiguration) F.first(cfgMap.values());
assert cfg != null;
if (logCfgPath != null)
cfg.setGridLogger(new GridTestLog4jLogger(U.resolveIgniteUrl(logCfgPath)));
return cfg;
}
use of org.apache.log4j.Appender in project ignite by apache.
the class GridSingleExecutionTest method getConfigurations.
/**
* Initializes configurations.
*
* @param springCfgPath Configuration file path.
* @param log Log file name.
* @return List of configurations.
* @throws IgniteCheckedException If failed..
*/
@SuppressWarnings("unchecked")
private static Iterable<IgniteConfiguration> getConfigurations(String springCfgPath, String log) throws IgniteCheckedException {
File path = GridTestUtils.resolveIgnitePath(springCfgPath);
if (path == null) {
throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + ". Note that this path should be either absolute path or a relative path to IGNITE_HOME.");
}
if (!path.isFile())
throw new IgniteCheckedException("Provided file path is not a file: " + path);
// Add no-op logger to remove no-appender warning.
Appender app = new NullAppender();
Logger.getRootLogger().addAppender(app);
ApplicationContext springCtx;
try {
springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString());
} catch (BeansException | MalformedURLException e) {
throw new IgniteCheckedException("Failed to instantiate Spring XML application context: " + e.getMessage(), e);
}
Map cfgMap;
try {
// Note: Spring is not generics-friendly.
cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
} catch (BeansException e) {
throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e);
}
if (cfgMap == null)
throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path);
// Remove previously added no-op logger.
Logger.getRootLogger().removeAppender(app);
if (cfgMap.isEmpty())
throw new IgniteCheckedException("Can't find grid factory configuration in: " + path);
Collection<IgniteConfiguration> res = new ArrayList<>();
for (IgniteConfiguration cfg : (Collection<IgniteConfiguration>) cfgMap.values()) {
UUID nodeId = UUID.randomUUID();
cfg.setNodeId(nodeId);
cfg.setGridLogger(initLogger(log));
res.add(cfg);
}
return res;
}
use of org.apache.log4j.Appender in project ignite by apache.
the class Log4JLogger method createConsoleAppender.
/**
* Creates console appender with some reasonable default logging settings.
*
* @param maxLevel Max logging level.
* @return New console appender.
*/
private Appender createConsoleAppender(Level maxLevel) {
String fmt = "[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n";
// Configure output that should go to System.out
Appender app = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
LevelRangeFilter lvlFilter = new LevelRangeFilter();
lvlFilter.setLevelMin(Level.TRACE);
lvlFilter.setLevelMax(maxLevel);
app.addFilter(lvlFilter);
return app;
}
Aggregations