use of org.apache.log4j.varia.NullAppender in project zaproxy by zaproxy.
the class ZapBootstrap method start.
/**
* Starts the bootstrap process.
*
* @return the return code of the program
*/
public int start() {
// Nasty hack to prevent warning messages when running from the command line
NullAppender na = new NullAppender();
Logger.getRootLogger().addAppender(na);
Logger.getRootLogger().setLevel(Level.OFF);
Logger.getLogger(ConfigurationUtils.class).addAppender(na);
Logger.getLogger(DefaultFileSystem.class).addAppender(na);
try {
Constant.getInstance();
} catch (final Throwable e) {
System.err.println(e.getMessage());
return 1;
}
Constant.setLowMemoryOption(getArgs().isLowMem());
return 0;
}
use of org.apache.log4j.varia.NullAppender 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.varia.NullAppender in project n4js by eclipse.
the class MockTest method beforeClass.
/**
*/
@BeforeClass
public static void beforeClass() {
if (!DEBUG) {
getRootLogger().removeAllAppenders();
getRootLogger().addAppender(new NullAppender());
}
}
use of org.apache.log4j.varia.NullAppender in project n4js by eclipse.
the class N4jscBase method doMain.
/**
* This method can be used when the headless builder (a.k.a. n4jsc.jar) is to be invoked programmatically from
* outside bundle {@code org.eclipse.n4js.hlc}, e.g. in tests or in MWE2 work flows.
* <p>
* Obviously, this method is not intended to be used in the IDE product (this bundle should not be included in the
* IDE product anyway).
*
* @param args
* parameters from command-line
* @throws ExitCodeException
* in case of errors.
*
* @return SuccessExitStatus {@link SuccessExitStatus#INSTANCE success status} when everything went fine
*/
public SuccessExitStatus doMain(String... args) throws ExitCodeException {
try {
CmdLineParser parser = new CmdLineParser(this);
parser.setUsageWidth(130);
try {
parser.parseArgument(args);
} catch (CmdLineException e) {
System.err.println(e.getMessage());
printExtendedUsage(parser, System.err);
// exit with error-code 1
throw new ExitCodeException(EXITCODE_WRONG_CMDLINE_OPTIONS);
}
// debug before help, shortcut for check-settings without running
if (debug) {
printDebugLines();
} else {
// Reconfigure Logging to be quiet:
Logger.getRootLogger().removeAllAppenders();
Logger.getRootLogger().addAppender(new NullAppender());
}
// Check help option:
if (help) {
// print and exit:
printExtendedUsage(parser, System.out);
return SuccessExitStatus.INSTANCE;
}
// Injection should not be called before making sure the argument parsing successfully finished. Such as
// help.
initInjection(refProperties());
// Register extensions manually
headlessExtensionRegistrationHelper.registerExtensions();
if (listRunners) {
printAvailableRunners(System.out);
return SuccessExitStatus.INSTANCE;
}
if (listTesters) {
printAvailableTesters(System.out);
return SuccessExitStatus.INSTANCE;
}
EnumSet<BuildType> noSrcRequired = EnumSet.of(BuildType.allprojects, BuildType.dontcompile);
// missing arguments (only build all doesn't require one OR if nothing will be compiled).
if (srcFiles.isEmpty() && (!noSrcRequired.contains(buildtype))) {
// print and exit:
System.out.println("Missing arguments.");
printExtendedUsage(parser, System.out);
throw new ExitCodeException(EXITCODE_WRONG_CMDLINE_OPTIONS);
}
// check missing runner
if ((runThisFile != null) && isNotGiven(runner)) {
// print and exit:
System.out.println("Missing arguments for running: runner must be named with option -rw");
printExtendedUsage(parser, System.out);
throw new ExitCodeException(EXITCODE_WRONG_CMDLINE_OPTIONS);
}
// check missing tester
if ((testThisLocation != null) && isNotGiven(tester)) {
// print and exit:
System.out.println("Missing arguments for testing: tester must be named with option -tw");
printExtendedUsage(parser, System.out);
throw new ExitCodeException(EXITCODE_WRONG_CMDLINE_OPTIONS);
}
// check runner/tester conflict
if (runThisFile != null && testThisLocation != null) {
// print and exit:
System.out.println("Conflicting arguments: must not provide both -r and -t");
printExtendedUsage(parser, System.out);
throw new ExitCodeException(EXITCODE_WRONG_CMDLINE_OPTIONS);
}
if (null != testCatalogFile) {
if (testCatalogFile.exists()) {
if (testCatalogFile.isDirectory()) {
final String msg = "The location of the test catalog file points to a directory and not to a file. " + testCatalogFile;
System.out.println(msg);
printExtendedUsage(parser, System.out);
throw new ExitCodeException(EXITCODE_TEST_CATALOG_ASSEMBLATION_ERROR, msg);
}
if (!testCatalogFile.delete()) {
final String msg = "Error while deleting existing test catalog file. " + testCatalogFile;
System.out.println(msg);
printExtendedUsage(parser, System.out);
throw new ExitCodeException(EXITCODE_TEST_CATALOG_ASSEMBLATION_ERROR, msg);
}
}
try {
if (!testCatalogFile.createNewFile()) {
final String msg = "Error while creating test catalog file at: " + testCatalogFile;
System.out.println(msg);
printExtendedUsage(parser, System.out);
throw new ExitCodeException(EXITCODE_TEST_CATALOG_ASSEMBLATION_ERROR, msg);
}
} catch (final IOException e) {
System.out.println("Error while creating test catalog file. " + e.getMessage());
printExtendedUsage(parser, System.out);
throw new ExitCodeException(EXITCODE_TEST_CATALOG_ASSEMBLATION_ERROR, e);
}
if (!testCatalogFile.exists() || !testCatalogFile.canWrite()) {
final String msg = "Cannot access test catalog file at: " + testCatalogFile;
System.out.println(msg);
printExtendedUsage(parser, System.out);
throw new ExitCodeException(EXITCODE_TEST_CATALOG_ASSEMBLATION_ERROR, msg);
}
}
if (clean && ((buildtype == BuildType.dontcompile) || (buildtype == BuildType.singlefile))) {
String msg = "";
if (buildtype == BuildType.dontcompile) {
msg = "The flag -bt must be specified when --clean/-c is activated";
} else if (buildtype == BuildType.singlefile) {
msg = "The flag --clean/-c flag can not be used in combination with -bt singlefile";
}
System.out.println(msg);
printExtendedUsage(parser, System.out);
throw new ExitCodeException(EXITCODE_WRONG_CMDLINE_OPTIONS);
}
final SystemLoaderInfo systemLoaderType = SystemLoaderInfo.fromString(systemLoader);
if (null == systemLoaderType) {
systemLoader = SystemLoaderInfo.SYSTEM_JS.getId();
}
checkTargetPlatformConfigurations();
if (null != nodeJsBinaryRoot) {
binariesPreferenceStore.setPath(nodeJsBinaryProvider.get(), nodeJsBinaryRoot.toURI());
binariesPreferenceStore.save();
}
if (npmrcRoot != null) {
binariesPreferenceStore.setPath(npmrcBinaryProvider.get(), npmrcRoot.toURI());
binariesPreferenceStore.save();
}
validateBinaries();
cloneGitRepositoryAndInstallNpmPackages();
if (clean) {
// clean without compiling anything.
clean();
} else {
if (installMissingDependencies) {
Map<String, String> dependencies = dependencyHelper.discoverMissingDependencies(projectLocations, srcFiles);
if (verbose) {
System.out.println("installing missing dependencies:");
dependencies.forEach((name, version) -> {
System.out.println(" # " + name + version);
});
}
IStatus status = npmManager.installDependencies(dependencies, new NullProgressMonitor(), false);
if (!status.isOK())
if (keepCompiling)
warn(status.getMessage());
else
throw new ExitCodeException(EXITCODE_DEPENDENCY_NOT_FOUND, "Cannot install dependencies.");
}
// run and dispatch.
doCompileAndTestAndRun();
}
} catch (ExitCodeException e) {
dumpThrowable(e);
throw e;
} finally {
targetPlatformInstallLocation = null;
}
// did everything there was to be done
return SuccessExitStatus.INSTANCE;
}
use of org.apache.log4j.varia.NullAppender 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..
*/
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;
}
Aggregations