use of org.apache.logging.log4j.core.config.ConfigurationException in project logging-log4j2 by apache.
the class Log4j1ConfigurationConverter method run.
private void run() {
if (cla.getRecurseIntoPath() != null) {
final AtomicInteger countOKs = new AtomicInteger();
final AtomicInteger countFails = new AtomicInteger();
try {
Files.walkFileTree(cla.getRecurseIntoPath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
if (cla.getPathIn() == null || file.getFileName().equals(cla.getPathIn())) {
verbose("Reading %s", file);
String newFile = file.getFileName().toString();
final int lastIndex = newFile.lastIndexOf(".");
newFile = lastIndex < 0 ? newFile + FILE_EXT_XML : newFile.substring(0, lastIndex) + FILE_EXT_XML;
final Path resolved = file.resolveSibling(newFile);
try (final InputStream input = new InputStreamWrapper(Files.newInputStream(file), file.toString());
final OutputStream output = Files.newOutputStream(resolved)) {
try {
convert(input, output);
countOKs.incrementAndGet();
} catch (ConfigurationException | IOException e) {
countFails.incrementAndGet();
if (cla.isFailFast()) {
throw e;
}
e.printStackTrace();
}
verbose("Wrote %s", resolved);
}
}
return FileVisitResult.CONTINUE;
}
});
} catch (final IOException e) {
throw new ConfigurationException(e);
} finally {
verbose("OK = %,d, Failures = %,d, Total = %,d", countOKs.get(), countFails.get(), countOKs.get() + countFails.get());
}
} else {
verbose("Reading %s", cla.getPathIn());
try (final InputStream input = getInputStream();
final OutputStream output = getOutputStream()) {
convert(input, output);
} catch (final IOException e) {
throw new ConfigurationException(e);
}
verbose("Wrote %s", cla.getPathOut());
}
}
use of org.apache.logging.log4j.core.config.ConfigurationException in project logging-log4j2 by apache.
the class Log4j1ConfigurationParser method buildConfigurationBuilder.
/**
* Parses a Log4j 1.2 properties configuration file in ISO 8859-1 encoding into a ConfigurationBuilder.
*
* @param input
* InputStream to read from is assumed to be ISO 8859-1, and will not be closed.
* @return the populated ConfigurationBuilder, never {@literal null}
* @throws IOException
* if unable to read the input
* @throws ConfigurationException
* if the input does not contain a valid configuration
*/
public ConfigurationBuilder<BuiltConfiguration> buildConfigurationBuilder(final InputStream input) throws IOException {
try {
properties.load(input);
strSubstitutorProperties = new StrSubstitutor(properties);
strSubstitutorSystem = new StrSubstitutor(System.getProperties());
final String rootCategoryValue = getLog4jValue(ROOTCATEGORY);
final String rootLoggerValue = getLog4jValue(ROOTLOGGER);
if (rootCategoryValue == null && rootLoggerValue == null) {
// This is not a Log4j 1 properties configuration file.
warn("Missing " + ROOTCATEGORY + " or " + ROOTLOGGER + " in " + input);
// throw new ConfigurationException(
// "Missing " + ROOTCATEGORY + " or " + ROOTLOGGER + " in " + input);
}
builder.setConfigurationName("Log4j1");
// DEBUG
final String debugValue = getLog4jValue("debug");
if (Boolean.valueOf(debugValue)) {
builder.setStatusLevel(Level.DEBUG);
}
// Root
buildRootLogger(getLog4jValue(ROOTCATEGORY));
buildRootLogger(getLog4jValue(ROOTLOGGER));
// Appenders
final Map<String, String> appenderNameToClassName = buildClassToPropertyPrefixMap();
for (final Map.Entry<String, String> entry : appenderNameToClassName.entrySet()) {
final String appenderName = entry.getKey();
final String appenderClass = entry.getValue();
buildAppender(appenderName, appenderClass);
}
// Loggers
buildLoggers("log4j.category.");
buildLoggers("log4j.logger.");
buildProperties();
return builder;
} catch (final IllegalArgumentException e) {
throw new ConfigurationException(e);
}
}
Aggregations