List of usage examples for java.util.logging LogManager getLogManager
public static LogManager getLogManager()
From source file:eu.tango.energymodeller.EnergyModeller.java
/** * This runs the energy modeller in standalone mode. * * @param args no args are expected./*from w w w. j a v a 2s.c om*/ */ public static void main(String[] args) { boolean running = true; try { if (new File("energy-modeller-logging.properties").exists()) { LogManager.getLogManager() .readConfiguration(new FileInputStream(new File("energy-modeller-logging.properties"))); } } catch (FileNotFoundException ex) { Logger.getLogger(EnergyModeller.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException | SecurityException ex) { Logger.getLogger(EnergyModeller.class.getName()).log(Level.SEVERE, "Could not read the energy modeller's log settings file", ex); } /** * Only the instance that is stated in standalone mode should write to * the background database and log VM data out to disk. All other * instances should read from the database only. */ EnergyModeller modeller = new EnergyModeller(true); Logger.getLogger(EnergyModeller.class.getName()).log(Level.SEVERE, "The logger for the energy modeller has now started"); while (running) { try { Thread.sleep(1000); } catch (InterruptedException ex) { Logger.getLogger(EnergyModeller.class.getName()).log(Level.SEVERE, "The energy modeller was interupted.", ex); } catch (Exception ex) { Logger.getLogger(EnergyModeller.class.getName()).log(Level.SEVERE, "An unhandled exception occured", ex); running = false; } } }
From source file:MailHandlerDemo.java
/** * Runs the demo./* www. j a v a 2s.co m*/ * * @param args the command line arguments * @throws IOException if there is a problem. */ public static void main(String[] args) throws IOException { List<String> l = Arrays.asList(args); if (l.contains("/?") || l.contains("-?") || l.contains("-help")) { LOGGER.info("Usage: java MailHandlerDemo " + "[[-all] | [-body] | [-custom] | [-debug] | [-low] " + "| [-simple] | [-pushlevel] | [-pushfilter] " + "| [-pushnormal] | [-pushonly]] " + "\n\n" + "-all\t\t: Execute all demos.\n" + "-body\t\t: An email with all records and only a body.\n" + "-custom\t\t: An email with attachments and dynamic names.\n" + "-debug\t\t: Output basic debug information about the JVM " + "and log configuration.\n" + "-low\t\t: Generates multiple emails due to low capacity." + "\n" + "-simple\t\t: An email with all records with body and " + "an attachment.\n" + "-pushlevel\t: Generates high priority emails when the" + " push level is triggered and normal priority when " + "flushed.\n" + "-pushFilter\t: Generates high priority emails when the " + "push level and the push filter is triggered and normal " + "priority emails when flushed.\n" + "-pushnormal\t: Generates multiple emails when the " + "MemoryHandler push level is triggered. All generated " + "email are sent as normal priority.\n" + "-pushonly\t: Generates multiple emails when the " + "MemoryHandler push level is triggered. Generates high " + "priority emails when the push level is triggered and " + "normal priority when flushed.\n"); } else { final boolean debug = init(l); //may create log messages. try { LOGGER.log(Level.FINEST, "This is the finest part of the demo.", new MessagingException("Fake JavaMail issue.")); LOGGER.log(Level.FINER, "This is the finer part of the demo.", new NullPointerException("Fake bug.")); LOGGER.log(Level.FINE, "This is the fine part of the demo."); LOGGER.log(Level.CONFIG, "Logging config file is {0}.", getConfigLocation()); LOGGER.log(Level.INFO, "Your temp directory is {0}, " + "please wait...", getTempDir()); try { //Waste some time for the custom formatter. Thread.sleep(3L * 1000L); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } LOGGER.log(Level.WARNING, "This is a warning.", new FileNotFoundException("Fake file chooser issue.")); LOGGER.log(Level.SEVERE, "The end of the demo.", new IOException("Fake access denied issue.")); } finally { closeHandlers(); } //Force parse errors. This does have side effects. if (debug && getConfigLocation() != null) { LogManager.getLogManager().readConfiguration(); } } }
From source file:POP3Mail.java
public static void main(String[] args) { try {/*from w w w.j a v a2 s . co m*/ LogManager.getLogManager().readConfiguration(new FileInputStream("logging.properties")); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String server = null; String username = null; String password = null; if (new File("mail.properties").exists()) { Properties properties = new Properties(); try { properties.load(new FileInputStream(new File("mail.properties"))); server = properties.getProperty("server"); username = properties.getProperty("username"); password = properties.getProperty("password"); ArrayList<String> list = new ArrayList<String>( Arrays.asList(new String[] { server, username, password })); list.addAll(Arrays.asList(args)); args = list.toArray(new String[list.size()]); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (args.length < 3) { System.err .println("Usage: POP3Mail <pop3 server hostname> <username> <password> [TLS [true=implicit]]"); System.exit(1); } server = args[0]; username = args[1]; password = args[2]; String proto = null; int messageid = -1; boolean implicit = false; for (int i = 3; i < args.length; ++i) { if (args[i].equals("-m")) { i += 1; messageid = Integer.parseInt(args[i]); } } // String proto = args.length > 3 ? args[3] : null; // boolean implicit = args.length > 4 ? Boolean.parseBoolean(args[4]) // : false; POP3Client pop3; if (proto != null) { System.out.println("Using secure protocol: " + proto); pop3 = new POP3SClient(proto, implicit); } else { pop3 = new POP3Client(); } pop3.setDefaultPort(110); System.out.println("Connecting to server " + server + " on " + pop3.getDefaultPort()); // We want to timeout if a response takes longer than 60 seconds pop3.setDefaultTimeout(60000); // suppress login details pop3.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true)); try { pop3.connect(server); } catch (IOException e) { System.err.println("Could not connect to server."); e.printStackTrace(); System.exit(1); } try { if (!pop3.login(username, password)) { System.err.println("Could not login to server. Check password."); pop3.disconnect(); System.exit(1); } PrintWriter printWriter = new PrintWriter(new FileWriter("messages.csv"), true); POP3MessageInfo[] messages = null; POP3MessageInfo[] identifiers = null; if (messageid == -1) { messages = pop3.listMessages(); identifiers = pop3.listUniqueIdentifiers(); } else { messages = new POP3MessageInfo[] { pop3.listMessage(messageid) }; } if (messages == null) { System.err.println("Could not retrieve message list."); pop3.disconnect(); return; } else if (messages.length == 0) { System.out.println("No messages"); pop3.logout(); pop3.disconnect(); return; } new File("../json").mkdirs(); int count = 0; for (POP3MessageInfo msginfo : messages) { if (msginfo.number != identifiers[count].number) { throw new RuntimeException(); } msginfo.identifier = identifiers[count].identifier; BufferedReader reader = (BufferedReader) pop3.retrieveMessageTop(msginfo.number, 0); ++count; if (count % 100 == 0) { logger.finest(String.format("%d %s", msginfo.number, msginfo.identifier)); } System.out.println(String.format("%d %s", msginfo.number, msginfo.identifier)); if (reader == null) { System.err.println("Could not retrieve message header."); pop3.disconnect(); System.exit(1); } if (printMessageInfo(reader, msginfo.number, printWriter)) { } } printWriter.close(); pop3.logout(); pop3.disconnect(); } catch (IOException e) { e.printStackTrace(); return; } }
From source file:puma.central.pdp.CentralPUMAPDP.java
public static void main(String[] args) { // initialize log4j BasicConfigurator.configure();//from w w w .ja va2 s.c om CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("ph", "policy-home", true, "The folder where to find the policy file given with the given policy id. " + "For default operation, this folder should contain the central PUMA policy (called " + CENTRAL_PUMA_POLICY_FILENAME + ")"); options.addOption("pid", "policy-id", true, "The id of the policy to be evaluated on decision requests. Default value: " + GLOBAL_PUMA_POLICY_ID + ")"); options.addOption("s", "log-disabled", true, "Verbose mode (true/false)"); String policyHome = ""; String policyId = ""; // read command line try { CommandLine line = parser.parse(options, args); if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Simple PDP Test", options); return; } if (line.hasOption("policy-home")) { policyHome = line.getOptionValue("policy-home"); } else { logger.log(Level.WARNING, "Incorrect arguments given."); return; } if (line.hasOption("log-disabled") && Boolean.parseBoolean(line.getOptionValue("log-disabled"))) { logger.log(Level.INFO, "Now switching to silent mode"); LogManager.getLogManager().getLogger("").setLevel(Level.WARNING); //LogManager.getLogManager().reset(); } if (line.hasOption("policy-id")) { policyId = line.getOptionValue("policy-id"); } else { logger.log(Level.INFO, "Using default policy id: " + GLOBAL_PUMA_POLICY_ID); policyId = GLOBAL_PUMA_POLICY_ID; } } catch (ParseException e) { logger.log(Level.WARNING, "Incorrect arguments given.", e); return; } // // STARTUP THE RMI SERVER // // if (System.getSecurityManager() == null) { // System.setSecurityManager(new SecurityManager()); // } final CentralPUMAPDP pdp; try { pdp = new CentralPUMAPDP(policyHome, policyId); } catch (IOException e) { logger.log(Level.SEVERE, "FAILED to set up the CentralPUMAPDP. Quitting.", e); return; } try { Registry registry; try { registry = LocateRegistry.createRegistry(RMI_REGISITRY_PORT); logger.info("Created new RMI registry"); } catch (RemoteException e) { // MDC: I hope this means the registry already existed. registry = LocateRegistry.getRegistry(RMI_REGISITRY_PORT); logger.info("Reusing existing RMI registry"); } CentralPUMAPDPRemote stub = (CentralPUMAPDPRemote) UnicastRemoteObject.exportObject(pdp, 0); registry.bind(CENTRAL_PUMA_PDP_RMI_NAME, stub); logger.info( "Central PUMA PDP up and running (available using RMI with name \"central-puma-pdp\" on RMI registry port " + RMI_REGISITRY_PORT + ")"); Thread.sleep(100); // MDC: vroeger eindigde de Thread om n of andere reden, dit lijkt te werken... } catch (Exception e) { logger.log(Level.SEVERE, "FAILED to set up PDP as RMI server", e); } // // STARTUP THE THRIFT PEP SERVER // //logger.log(Level.INFO, "Not setting up the Thrift server"); // set up server // PEPServer handler = new PEPServer(new CentralPUMAPEP(pdp)); // RemotePEPService.Processor<PEPServer> processor = new RemotePEPService.Processor<PEPServer>(handler); // TServerTransport serverTransport; // try { // serverTransport = new TServerSocket(THRIFT_PEP_PORT); // } catch (TTransportException e) { // e.printStackTrace(); // return; // } // TServer server = new TSimpleServer(new TServer.Args(serverTransport).processor(processor)); // System.out.println("Setting up the Thrift PEP server on port " + THRIFT_PEP_PORT); // server.serve(); // // STARTUP THE THRIFT PEP SERVER // //logger.log(Level.INFO, "Not setting up the Thrift server"); // set up server // do this in another thread not to block the main thread new Thread(new Runnable() { @Override public void run() { RemotePDPService.Processor<CentralPUMAPDP> pdpProcessor = new RemotePDPService.Processor<CentralPUMAPDP>( pdp); TServerTransport pdpServerTransport; try { pdpServerTransport = new TServerSocket(THRIFT_PDP_PORT); } catch (TTransportException e) { e.printStackTrace(); return; } TServer pdpServer = new TThreadPoolServer( new TThreadPoolServer.Args(pdpServerTransport).processor(pdpProcessor)); logger.info("Setting up the Thrift PDP server on port " + THRIFT_PDP_PORT); pdpServer.serve(); } }).start(); }
From source file:com.archivas.logging.FileHandler.java
private static String getPattern() { LogManager manager = LogManager.getLogManager(); String cname = FileHandler.class.getName(); String pattern = manager.getProperty(cname + ".pattern"); if (pattern == null) { pattern = "%h/java%u.log"; }/* w w w .j av a 2s . co m*/ return pattern; }
From source file:net.erdfelt.android.sdkfido.logging.Logging.java
public static void config() { ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL url = cl.getResource("logging.properties"); if (url != null) { InputStream in = null;/*from w w w . j av a 2 s . co m*/ try { in = url.openStream(); LogManager.getLogManager().readConfiguration(in); } catch (IOException e) { e.printStackTrace(System.err); } finally { IOUtils.closeQuietly(in); } } System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger"); }
From source file:org.stanwood.nwn2.gui.logging.JavaLoggingToCommonLoggingRedirector.java
/** * Activates this feature.//from w ww . java2s . c o m */ public static void activate() { try { Logger rootLogger = LogManager.getLogManager().getLogger(""); // remove old handlers for (Handler handler : rootLogger.getHandlers()) { rootLogger.removeHandler(handler); } // add our own activeHandler = new JDKLogHandler(); activeHandler.setLevel(Level.ALL); rootLogger.addHandler(activeHandler); rootLogger.setLevel(Level.ALL); } catch (Exception exc) { LogFactory.getLog(JavaLoggingToCommonLoggingRedirector.class).error("activation failed", exc); } }
From source file:com.sap.prd.mobile.ios.mios.UpdateVersionInPListTaskTest.java
@BeforeClass public static void setupStatic() { LogManager.getLogManager().addLogger(new XCodePluginLogger()); }
From source file:name.livitski.tools.springlet.Logging.java
/** * Reads the JDK logging configuration from an input stream. * @param configDocumentStream the stream containing logging * configuration properties//w w w .j a v a2s . c o m * @throws IOException */ public static void configureJDKLogs(InputStream configDocumentStream) throws IOException { LogManager.getLogManager().readConfiguration(configDocumentStream); }
From source file:com.archivas.logging.FileHandler.java
private static int getLimit() { LogManager manager = LogManager.getLogManager(); String cname = FileHandler.class.getName(); String limitStr = manager.getProperty(cname + ".limit"); int limit = 10000000; if (limitStr != null) { limit = Integer.valueOf(limitStr); }//from www . ja v a 2s . c o m return limit; }