From 2504b264bab2020115f7d14d6b93cb9997989c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Walter?= <juergen.walter@uni-wuerzburg.de> Date: Wed, 15 Mar 2017 16:47:25 +0100 Subject: [PATCH] standard log level to INFO (no debug logs) --- .../descartes/pmx/console/PMXCommandLine.java | 104 +++++++++--------- 1 file changed, 53 insertions(+), 51 deletions(-) diff --git a/tools.descartes.pmx.console/src/tools/descartes/pmx/console/PMXCommandLine.java b/tools.descartes.pmx.console/src/tools/descartes/pmx/console/PMXCommandLine.java index 519bf202..d09f2678 100644 --- a/tools.descartes.pmx.console/src/tools/descartes/pmx/console/PMXCommandLine.java +++ b/tools.descartes.pmx.console/src/tools/descartes/pmx/console/PMXCommandLine.java @@ -43,6 +43,8 @@ import org.apache.log4j.ConsoleAppender; import org.apache.log4j.FileAppender; import org.apache.log4j.HTMLLayout; import org.apache.log4j.Layout; +import org.apache.log4j.Level; +import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.apache.log4j.PatternLayout; import org.apache.log4j.SimpleLayout; @@ -131,20 +133,19 @@ public class PMXCommandLine { Option numCoresOption = OptionBuilder.create("n"); options.addOption(numCoresOption); } - + public static void main(String[] args) { run(args); } - public static boolean run(String[] args) { initConsoleLogging(); PMXCommandLine cmd = PMXCommandLine.parse(args); PMXController pmx = cmd.createPMX(); - try{ + try { pmx.run(); return true; - }catch(AnalysisConfigurationException e){ + } catch (AnalysisConfigurationException e) { log.info("AnalysisConfigurationException" + e); return false; } catch (NullPointerException e) { @@ -159,13 +160,13 @@ public class PMXCommandLine { cmd.commandLine = commmandLineParser.parse(options, args); } catch (final ParseException e) { String s = ""; - for(String sub: args){ - s+= " "+sub; + for (String sub : args) { + s += " " + sub; } - if(s.contains("-h") || s.contains("--help")){ - //--help is no error even if the required file path is missing - }else{ - log.info("Error parsing arguments:"+s); + if (s.contains("-h") || s.contains("--help")) { + // --help is no error even if the required file path is missing + } else { + log.info("Error parsing arguments:" + s); // log.info(e.getMessage()); } PMXCommandLine.printUsage(); @@ -181,15 +182,17 @@ public class PMXCommandLine { registerFSReader(analysisController, inputDirs); String outputDir = commandLine.getOptionValue(CMD_LONG_OPT_OUTPUT_DIR); - if(outputDir == null){ + if (outputDir == null) { outputDir = inputDirs[0]; log.info("No output directory specified. Logging to input directory."); } - + HashMap<String, Integer> numCores = getNumberOfCores(); initFileLogging(outputDir, "extraction.log", new SimpleLayout()); initFileLogging(outputDir, "extraction.log.html", new HTMLLayout()); + LogManager.getRootLogger().setLevel(Level.INFO); // log all except + // // for debug PMXController controller = new PMXController(analysisController, outputDir, commandLine.getOptionValue(TimestampFilter.CONFIG_PROPERTY_NAME_IGNORE_BEFORE_TIMESTAMP), @@ -197,11 +200,9 @@ public class PMXCommandLine { commandLine.hasOption("reduced"), numCores); return controller; } catch (NullPointerException e) { - //PMXCommandLine.printUsage(); + // PMXCommandLine.printUsage(); log.info("Nullpointer in class " + e.getStackTrace()[0].getClass() + ", method " - + e.getStackTrace()[0].getMethodName() - + ", Line " - + e.getStackTrace()[0].getLineNumber()); + + e.getStackTrace()[0].getMethodName() + ", Line " + e.getStackTrace()[0].getLineNumber()); } catch (IllegalArgumentException e) { log.info("IllegalArgumentException in class " + e.getStackTrace()[0].getClass() + ", method " + e.getStackTrace()[0].getMethodName() + ", Line " + e.getStackTrace()[0].getLineNumber()); @@ -220,15 +221,15 @@ public class PMXCommandLine { } log.info(coresCmd + " < parsed number of cores specification"); String[] numCoresDescriptions; - if(coresCmd.contains(",")){ + if (coresCmd.contains(",")) { numCoresDescriptions = coresCmd.split(","); - }else if (coresCmd.contains("=")){ - numCoresDescriptions = new String[]{coresCmd}; - }else{ + } else if (coresCmd.contains("=")) { + numCoresDescriptions = new String[] { coresCmd }; + } else { numCoresDescriptions = new String[0]; } HashMap<String, Integer> numberOfCores = new HashMap<String, Integer>(); - for(String ab: numCoresDescriptions){ + for (String ab : numCoresDescriptions) { numberOfCores.put(ab.split("=")[0], Integer.parseInt(ab.split("=")[1])); log.info(ab.split("=")[0] + " = " + Integer.parseInt(ab.split("=")[1])); } @@ -256,20 +257,21 @@ public class PMXCommandLine { private static FSReader registerFSReader(IAnalysisController analysisInstance, final String[] kiekerTraceFile) { final String[] inputDirs = kiekerTraceFile; -// if (new File(kiekerTraceFile).getName().startsWith("kieker-")) { -// inputDirs = new String[1]; -// inputDirs[0] = kiekerTraceFile; -// } else { -// // search subdirectories for folders "kieker- ..." -// File[] fileArray = new File(kiekerTraceFile).listFiles(); -// ArrayList<String> inputDirList = new ArrayList<String>(); -// for (int i = 0; i < fileArray.length; i++) { -// if (fileArray[i].toString().contains("kieker-")) { -// inputDirList.add(fileArray[i].getAbsolutePath()); -// } -// } -// inputDirs = (String[]) inputDirList.toArray(new String[inputDirList.size()]); -// } + // if (new File(kiekerTraceFile).getName().startsWith("kieker-")) { + // inputDirs = new String[1]; + // inputDirs[0] = kiekerTraceFile; + // } else { + // // search subdirectories for folders "kieker- ..." + // File[] fileArray = new File(kiekerTraceFile).listFiles(); + // ArrayList<String> inputDirList = new ArrayList<String>(); + // for (int i = 0; i < fileArray.length; i++) { + // if (fileArray[i].toString().contains("kieker-")) { + // inputDirList.add(fileArray[i].getAbsolutePath()); + // } + // } + // inputDirs = (String[]) inputDirList.toArray(new + // String[inputDirList.size()]); + // } final Configuration readerConfiguration = new Configuration(); readerConfiguration.setProperty(FSReader.CONFIG_PROPERTY_NAME_INPUTDIRS, Configuration.toProperty(inputDirs)); @@ -280,11 +282,11 @@ public class PMXCommandLine { private static void printUsage() { commandLineFormatter.printHelp(toolName, options); } - + private static void initConsoleLogging() { try { SimpleLayout simpleLayout = new SimpleLayout(); - //PatternLayout layout = new PatternLayout("%-5p [%t]: %m%n"); + // PatternLayout layout = new PatternLayout("%-5p [%t]: %m%n"); PatternLayout layout = new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN); ConsoleAppender consoleAppender = new ConsoleAppender(simpleLayout); BasicConfigurator.configure(consoleAppender); @@ -296,7 +298,8 @@ public class PMXCommandLine { private static void initFileLogging(String directory, String logFileName, Layout layout) { try { // add logging to file - //new File(outputDir).isDirectory()?(outputDir):(outputDir+ File.separator) + // new File(outputDir).isDirectory()?(outputDir):(outputDir+ + // File.separator) String path = directory + File.separator + logFileName; log.info("logging to file " + path); FileAppender fileAppender = new FileAppender(layout, path, false); @@ -305,16 +308,14 @@ public class PMXCommandLine { log.error("Error during inialization of logging"); } } - - + /** - * Returns if the specified input directories {@link #inputDirs} exist and that - * each one is a monitoring log. If this is not the case for one of the directories, - * an error message is printed to stderr. + * Returns if the specified input directories {@link #inputDirs} exist and + * that each one is a monitoring log. If this is not the case for one of the + * directories, an error message is printed to stderr. * * @return true if {@link #outputDir} is exists and is a directory; false - * otherwise - * TODO Integrate check in comand line and gui + * otherwise TODO Integrate check in comand line and gui */ private boolean assertInputDirsExistsAndAreMonitoringLogs(String[] inputDirs) { if (inputDirs == null) { @@ -330,13 +331,15 @@ public class PMXCommandLine { return false; } if (!inputDirFile.isDirectory() && !inputDir.endsWith(FSUtil.ZIP_FILE_EXTENSION)) { - log.error("The specified input directory '" + inputDirFile.getCanonicalPath() + "' is neither a directory nor a zip file"); + log.error("The specified input directory '" + inputDirFile.getCanonicalPath() + + "' is neither a directory nor a zip file"); return false; } - // check whether inputDirFile contains a (kieker|tpmon).map file; the latter for legacy reasons + // check whether inputDirFile contains a (kieker|tpmon).map + // file; the latter for legacy reasons if (inputDirFile.isDirectory()) { // only check for dirs final File[] mapFiles = { new File(inputDir + File.separatorChar + FSUtil.MAP_FILENAME), - new File(inputDir + File.separatorChar + FSUtil.LEGACY_MAP_FILENAME), }; + new File(inputDir + File.separatorChar + FSUtil.LEGACY_MAP_FILENAME), }; boolean mapFileExists = false; for (final File potentialMapFile : mapFiles) { if (potentialMapFile.isFile()) { @@ -345,7 +348,8 @@ public class PMXCommandLine { } } if (!mapFileExists) { - log.error("The specified input directory '" + inputDirFile.getCanonicalPath() + "' is not a kieker log directory"); + log.error("The specified input directory '" + inputDirFile.getCanonicalPath() + + "' is not a kieker log directory"); return false; } } @@ -371,12 +375,10 @@ public class PMXCommandLine { return outputDir; } - public static IModelBuilder getModelBuilder() { return modelBuilder; } - public static void setModelBuilder(IModelBuilder modelBuilder) { PMXCommandLine.modelBuilder = modelBuilder; PMXController.setModelBuilder(modelBuilder); -- GitLab