/** create a gzip file */ @BeforeClass public static void init() { SWTBotUtils.failIfUIThread(); zipTrace(); fLogger.removeAllAppenders(); fLogger.addAppender(new NullAppender()); }
private void crossover(String scenario, String crossoverLogFile) { try { WindScenario ws = new WindScenario("Scenarios/" + scenario + ".xml"); KusiakLayoutEvaluator wfle = new KusiakLayoutEvaluator(); wfle.initialize(ws); // Crossover Operation crossoverLogger.removeAllAppenders(); FileAppender crossoverAppender = new FileAppender(layout, crossoverLogFile, false); crossoverAppender.setImmediateFlush(true); crossoverLogger.addAppender(crossoverAppender); System.out.println(crossoverLogFile); for (int i = 0; i < runs; i++) { MuLambdaES es = new MuLambdaES(wfle); es.setMaxEvaluations(maxEvaluations); es.setNum_Turbines(num_T); es.setMu(mu); es.setLambda(lambda); es.setOperatorFlag("crossover"); String bestResult = String.valueOf(es.run_Dot_ES()); crossoverLogger.info(bestResult); } } catch (Exception e) { e.printStackTrace(); } }
private String logOut(String message, Throwable throwable) { StringWriter writer = new StringWriter(); Logger logger = createLogger(writer); logger.info(message, throwable); // remove and close the appender logger.removeAllAppenders(); return writer.toString(); }
/** * Create an appender that directs all log messages to a file with given name and replace all * current appenders with it. * * @param fileName Name of the log file to use. * @param append Value indicating if messages will be appended to the given file or it will be * truncated. */ public static void logToFile(String fileName, boolean append) throws IOException { final Appender newAppender = new FileAppender(new PatternLayout(), fileName, append); final List<Logger> loggers = Collections.list(LogManager.getCurrentLoggers()); loggers.add(LogManager.getRootLogger()); for (Logger logger : loggers) { logger.removeAllAppenders(); logger.addAppender(newAppender); } }
public static void initTddlLog() { if (initOK) return; Appender dbTabAppender = buildAppender("TDDL_Vtab_Appender", "tddl-db-tab.log", "%m"); Appender vSlotAppender = buildAppender("TDDL_Vtab_Appender", "tddl-vslot.log", "%m"); Appender dynamicRuleAppender = buildAppender("TDDL_DynamicRule_Appender", "tddl-dynamic-rule.log", "%m"); DB_TAB_LOG.setAdditivity(false); DB_TAB_LOG.removeAllAppenders(); DB_TAB_LOG.addAppender(dbTabAppender); DB_TAB_LOG.setLevel(Level.INFO); VSLOT_LOG.setAdditivity(false); VSLOT_LOG.removeAllAppenders(); VSLOT_LOG.addAppender(vSlotAppender); VSLOT_LOG.setLevel(Level.INFO); DYNAMIC_RULE_LOG.setAdditivity(false); DYNAMIC_RULE_LOG.removeAllAppenders(); DYNAMIC_RULE_LOG.addAppender(dynamicRuleAppender); DYNAMIC_RULE_LOG.setLevel(Level.INFO); }
/** This method must work for the root category as well. */ void parseCategory( Properties props, Logger logger, String optionKey, String loggerName, String value) { LogLog.debug("Parsing for [" + loggerName + "] with value=[" + value + "]."); // We must skip over ',' but not white space StringTokenizer st = new StringTokenizer(value, ","); // If value is not in the form ", appender.." or "", then we should set // the level of the loggeregory. if (!(value.startsWith(",") || value.equals(""))) { // just to be on the safe side... if (!st.hasMoreTokens()) return; String levelStr = st.nextToken(); LogLog.debug("Level token is [" + levelStr + "]."); // If the level value is inherited, set category level value to // null. We also check that the user has not specified inherited for the // root category. if (INHERITED.equalsIgnoreCase(levelStr) || NULL.equalsIgnoreCase(levelStr)) { if (loggerName.equals(INTERNAL_ROOT_NAME)) { LogLog.warn("The root logger cannot be set to null."); } else { logger.setLevel(null); } } else { logger.setLevel(OptionConverter.toLevel(levelStr, (Level) Level.DEBUG)); } LogLog.debug("Category " + loggerName + " set to " + logger.getLevel()); } // Begin by removing all existing appenders. logger.removeAllAppenders(); Appender appender; String appenderName; while (st.hasMoreTokens()) { appenderName = st.nextToken().trim(); if (appenderName == null || appenderName.equals(",")) continue; LogLog.debug("Parsing appender named \"" + appenderName + "\"."); appender = parseAppender(props, appenderName); if (appender != null) { logger.addAppender(appender); } } }
private static void configureLogging() { BasicConfigurator.configure(); Logger root = Logger.getRootLogger(); root.removeAllAppenders(); Layout layout = new PatternLayout(LOG_LAYOUT); root.addAppender(new ConsoleAppender(layout)); logger.info("Console logging started"); String logFileName = getLogFileName(); String logFilePath = Paths.LOGS_DIR + "/" + logFileName; try { root.addAppender(new FileAppender(layout, logFilePath)); logger.info("File logging started"); } catch (IOException e) { logger.warn("Failed to create FileAppender: " + e.getMessage()); } }
public static Logger getLogger(String categroy, String name) { Logger logger = Logger.getLogger(name); logger.removeAllAppenders(); logger.setAdditivity(false); FileAppender appender = null; PatternLayout layout = new PatternLayout(); layout.setConversionPattern("[%p][%d{yyyy-MM-dd HH:mm:ss}] %m%n"); try { appender = new DailyRollingFileAppender( layout, String.format("/data/applogs/%s/%s.log", categroy, name), "yyyy-MM-dd"); appender.setEncoding("UTF-8"); appender.activateOptions(); } catch (IOException e) { throw new RuntimeException("LogUtil fail.", e); } logger.addAppender(appender); logger.setLevel(Level.INFO); return logger; }
/** * Initialization, creates a temp trace * * @throws IOException should not happen */ @BeforeClass public static void init() throws IOException { SWTBotUtils.failIfUIThread(); Thread.currentThread().setName("SWTBot Thread"); // for the debugger /* set up for swtbot */ SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ fLogger.removeAllAppenders(); fLogger.addAppender(new ConsoleAppender(new SimpleLayout())); fBot = new SWTWorkbenchBot(); SWTBotUtils.closeView("welcome", fBot); SWTBotUtils.switchToTracingPerspective(); /* finish waiting for eclipse to load */ SWTBotUtils.waitForJobs(); fFileLocation = File.createTempFile("sample", ".xml"); try (BufferedRandomAccessFile braf = new BufferedRandomAccessFile(fFileLocation, "rw")) { braf.writeBytes(TRACE_START); for (int i = 0; i < 100; i++) { braf.writeBytes(makeEvent(i * 100, i % 4)); } braf.writeBytes(TRACE_END); } }
public synchronized void removeAllAppenders() { super.removeAllAppenders(); }
/** Delete the file */ @AfterClass public static void cleanUp() { fLogger.removeAllAppenders(); fFileLocation.delete(); }
@Before public void initialize() { logger = Logger.getLogger("logger"); logger.removeAllAppenders(); Logger.getRootLogger().removeAllAppenders(); }
public void setUp() { root = Logger.getRootLogger(); root.removeAllAppenders(); }
@Before public void clearAppenders() { log4jLogger.removeAllAppenders(); root.removeAllAppenders(); }
/** cleanup */ @AfterClass public static void destroy() { fLogger.removeAllAppenders(); }