List of usage examples for java.util.logging Logger getHandlers
public Handler[] getHandlers()
From source file:es.upm.dit.gsi.sim.twitter.TwitterSimulation.java
/** * @param seed// w ww . ja v a 2s . c o m * @param network */ public TwitterSimulation(long seed, Network network, List<String> topics) { super(seed); Logger globalLogger = logger.getParent(); globalLogger.setLevel(level); for (Handler handler : globalLogger.getHandlers()) { handler.setLevel(level); } this.topicManager = new TopicManager(); this.topicManager.setTopics(topics); this.initialNetwork = network; this.loadInitialNetwork = true; }
From source file:edu.usu.sdl.openstorefront.web.rest.service.Application.java
@PUT @RequireAdmin//from w w w . j a va 2s . c om @APIDescription("Sets logger level") @Produces({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.WILDCARD }) @DataType(LoggerView.class) @Path("/logger/{loggername}/level") public Response updateApplicationProperty(@PathParam("loggername") @RequiredParam String loggername, String level) { Response response = Response.status(Response.Status.NOT_FOUND).build(); Logger logger = LogManager.getLogManager().getLogger(loggername); if (logger != null) { List<String> levels = loadLevels(); boolean saved = false; if (StringUtils.isBlank(level)) { logger.setLevel(null); saved = true; } else { if (levels.contains(level)) { logger.setLevel(Level.parse(level)); saved = true; } else { RestErrorModel restErrorModel = new RestErrorModel(); restErrorModel.getErrors().put("level", "Log level is not valid. Check level value passed in."); response = Response.ok(restErrorModel).build(); } } if (saved) { LoggerView loggerView = new LoggerView(); loggerView.setName(loggername); loggerView.setLevel(level); for (Handler handlerLocal : logger.getHandlers()) { loggerView.getHandlers() .add(handlerLocal.getClass().getName() + " = " + handlerLocal.getLevel().getName()); } response = Response.ok(loggerView).build(); } } return response; }
From source file:processing.app.Base.java
static public void initLogger() { Handler consoleHandler = new ConsoleLogger(); consoleHandler.setLevel(Level.ALL); consoleHandler.setFormatter(new LogFormatter("%1$tl:%1$tM:%1$tS [%4$7s] %2$s: %5$s%n")); Logger globalLogger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); globalLogger.setLevel(consoleHandler.getLevel()); // Remove default Handler[] handlers = globalLogger.getHandlers(); for (Handler handler : handlers) { globalLogger.removeHandler(handler); }//w w w . j av a 2 s. c om Logger root = Logger.getLogger(""); handlers = root.getHandlers(); for (Handler handler : handlers) { root.removeHandler(handler); } globalLogger.addHandler(consoleHandler); Logger.getLogger("cc.arduino.packages.autocomplete").setParent(globalLogger); Logger.getLogger("br.com.criativasoft.cpluslibparser").setParent(globalLogger); Logger.getLogger(Base.class.getPackage().getName()).setParent(globalLogger); }
From source file:edu.harvard.iq.dvn.core.study.StudyServiceBean.java
public void exportStudyFilesToLegacySystem(String lastUpdateTime, String authority) { // Get list of studies that have been updated yesterday, // and export them to legacy VDC system Logger logger = null; String exportLogDirStr = System.getProperty("vdc.export.log.dir"); if (exportLogDirStr == null) { System.out.println("Missing system property: vdc.export.log.dir. Please add to JVM options"); return;//from w w w . j a v a 2 s . c o m } File exportLogDir = new File(exportLogDirStr); if (!exportLogDir.exists()) { exportLogDir.mkdir(); } logger = Logger.getLogger("edu.harvard.iq.dvn.core.web.servlet.VDCExportServlet"); // Everytime export runs, we want to write to a separate log file (handler). // So if export has run previously, remove the previous handler if (logger.getHandlers() != null && logger.getHandlers().length > 0) { int numHandlers = logger.getHandlers().length; for (int i = 0; i < numHandlers; i++) { logger.removeHandler(logger.getHandlers()[i]); } } SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd"); FileHandler handler = null; try { handler = new FileHandler( exportLogDirStr + File.separator + "export_" + formatter.format(new Date()) + ".log"); } catch (IOException e) { throw new EJBException(e); } // Add handler to the desired logger logger.addHandler(handler); logger.info("Begin Exporting Studies"); int studyCount = 0; int deletedStudyCount = 0; try { /* THIS IS LEGACY CODE AND SHOULD BE DELETED // For all studies that have been deleted in the dataverse since last export, remove study directory in VDC String query = "SELECT s from DeletedStudy s where s.authority = '" + authority + "' "; List deletedStudies = em.createQuery(query).getResultList(); for (Iterator it = deletedStudies.iterator(); it.hasNext();) { DeletedStudy deletedStudy = (DeletedStudy) it.next(); logger.info("Deleting study " + deletedStudy.getGlobalId()); Study study = em.find(Study.class, deletedStudy.getId()); File legacyStudyDir = new File(FileUtil.getLegacyFileDir() + File.separatorChar + study.getAuthority() + File.separatorChar + study.getStudyId()); // Remove files in the directory, then delete the directory. File[] studyFiles = legacyStudyDir.listFiles(); if (studyFiles != null) { for (int i = 0; i < studyFiles.length; i++) { studyFiles[i].delete(); } } legacyStudyDir.delete(); deletedStudyCount++; em.remove(deletedStudy); } */ // Do export of all studies updated at "lastUpdateTime"" if (authority == null) { authority = vdcNetworkService.find().getAuthority(); } String beginTime = null; String endTime = null; if (lastUpdateTime == null) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, -1); beginTime = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); // Use yesterday as default value cal.add(Calendar.DAY_OF_YEAR, 1); endTime = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); } else { beginTime = lastUpdateTime; Date date = new SimpleDateFormat("yyyy-MM-dd").parse(lastUpdateTime); Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.DAY_OF_YEAR, 1); endTime = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); } String query = "SELECT s from Study s where s.authority = '" + authority + "' "; query += " and s.lastUpdateTime >'" + beginTime + "'"; // query+=" and s.lastUpdateTime <'" +endTime+"'"; query += " order by s.studyId"; List updatedStudies = em.createQuery(query).getResultList(); for (Iterator it = updatedStudies.iterator(); it.hasNext();) { Study study = (Study) it.next(); logger.info("Exporting study " + study.getStudyId()); exportStudyToLegacySystem(study, authority); studyCount++; } } catch (Exception e) { logger.severe(e.getMessage()); String stackTrace = "StackTrace: \n"; logger.severe("Exception caused by: " + e + "\n"); StackTraceElement[] ste = e.getStackTrace(); for (int m = 0; m < ste.length; m++) { stackTrace += ste[m].toString() + "\n"; } logger.severe(stackTrace); } logger.info("End export, " + studyCount + " studies successfully exported, " + deletedStudyCount + " studies deleted."); }
From source file:org.quickserver.net.server.QuickServer.java
/** * Sets the console log handler formatter. * @param formatter fully qualified name of the class that implements * {@link java.util.logging.Formatter}/* w w w .j a va 2s . c o m*/ * @since 1.2 */ public void setConsoleLoggingFormatter(String formatter) throws ClassNotFoundException, InstantiationException, IllegalAccessException { if (formatter == null) return; consoleLoggingformatter = formatter; java.util.logging.Formatter conformatter = (java.util.logging.Formatter) getClass(formatter, true) .newInstance(); Logger jdkLogger = Logger.getLogger(""); Handler[] handlers = jdkLogger.getHandlers(); for (int index = 0; index < handlers.length; index++) { if (ConsoleHandler.class.isInstance(handlers[index])) { handlers[index].setFormatter(conformatter); } } logger.log(Level.FINEST, "Set to {0}", formatter); }
From source file:org.quickserver.net.server.QuickServer.java
/** * Sets the level for all log handlers.//w ww.j a v a2 s . co m * @since 1.3.1 */ public void setLoggingLevel(Level level) { Logger rlogger = Logger.getLogger(""); Handler[] handlers = rlogger.getHandlers(); for (int index = 0; index < handlers.length; index++) { handlers[index].setLevel(level); } if (level == Level.SEVERE) loggingLevel = "SEVERE"; else if (level == Level.WARNING) loggingLevel = "WARNING"; else if (level == Level.INFO) loggingLevel = "INFO"; else if (level == Level.CONFIG) loggingLevel = "CONFIG"; else if (level == Level.FINE) loggingLevel = "FINE"; else if (level == Level.FINER) loggingLevel = "FINER"; else if (level == Level.FINEST) loggingLevel = "FINEST"; else if (level == Level.OFF) loggingLevel = "OFF"; else loggingLevel = "UNKNOWN"; consoleLoggingLevel = loggingLevel; logger.log(Level.FINE, "Set to {0}", level); }
From source file:org.quickserver.net.server.QuickServer.java
/** * Sets the console log handler level.//from www .jav a 2s .c om * @since 1.2 */ public void setConsoleLoggingLevel(Level level) { Logger rlogger = Logger.getLogger(""); Handler[] handlers = rlogger.getHandlers(); boolean isConsole = true; try { if (System.console() == null) { isConsole = false; } } catch (Throwable e) { //ignore } for (int index = 0; index < handlers.length; index++) { if (ConsoleHandler.class.isInstance(handlers[index])) { if (isConsole == false && level != Level.OFF) { System.out.println("QuickServer: You do not have a console.. so turning console logger off.."); level = Level.OFF; } if (level == Level.OFF) { logger.info("QuickServer: Removing console handler.. "); rlogger.removeHandler(handlers[index]); handlers[index].setLevel(level); handlers[index].close(); } else { handlers[index].setLevel(level); } } } if (level == Level.SEVERE) consoleLoggingLevel = "SEVERE"; else if (level == Level.WARNING) consoleLoggingLevel = "WARNING"; else if (level == Level.INFO) consoleLoggingLevel = "INFO"; else if (level == Level.CONFIG) consoleLoggingLevel = "CONFIG"; else if (level == Level.FINE) consoleLoggingLevel = "FINE"; else if (level == Level.FINER) consoleLoggingLevel = "FINER"; else if (level == Level.FINEST) consoleLoggingLevel = "FINEST"; else if (level == Level.OFF) consoleLoggingLevel = "OFF"; else consoleLoggingLevel = "UNKNOWN"; logger.log(Level.FINE, "Set to {0}", level); }