List of usage examples for java.util.logging Logger addHandler
public void addHandler(Handler handler) throws SecurityException
From source file:Main.java
public static void main(String[] argv) throws Exception { Logger logger = Logger.getLogger("com.mycompany"); FileHandler fh = new FileHandler("mylog.txt"); fh.setFormatter(new SimpleFormatter()); logger.addHandler(fh); // fh = new FileHandler("mylog.xml"); // fh.setFormatter(new XMLFormatter()); // logger.addHandler(fh); // Log a few messages logger.severe("my severe message"); logger.warning("my warning message"); logger.info("my info message"); logger.config("my config message"); logger.fine("my fine message"); logger.finer("my finer message"); logger.finest("my finest message"); }
From source file:Main.java
public static void main(String args[]) throws Exception { Logger logger = Logger.getLogger("your.logging"); ConsoleHandler handler = new ConsoleHandler(); MemoryHandler mHandler = new MemoryHandler(handler, 10, Level.ALL); logger.addHandler(mHandler); logger.setUseParentHandlers(false);//from www . j a v a 2s.c om LogRecord record1 = new LogRecord(Level.SEVERE, "This is SEVERE level message"); LogRecord record2 = new LogRecord(Level.WARNING, "This is WARNING level message"); logger.log(record1); logger.log(record2); }
From source file:MyHtmlFormatter.java
public static void main(String[] argv) throws Exception { Logger logger = Logger.getLogger("com.mycompany"); FileHandler fh = new FileHandler("mylog.html"); fh.setFormatter(new MyHtmlFormatter()); logger.addHandler(fh); logger.setLevel(Level.ALL);/*from w w w . j av a 2s .c om*/ logger.severe("my severe message"); logger.info("my info message"); logger.entering("Main class", "myMethod", new Object[] { "para1", "para2" }); }
From source file:net.sf.mpaxs.spi.computeHost.StartUp.java
/** * * @param args// ww w . j a va 2 s .c o m */ public static void main(String args[]) { FileHandler handler; try { handler = new FileHandler("computeHost.log"); Logger logger = Logger.getLogger(StartUp.class.getName()); logger.addHandler(handler); } catch (IOException ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); } catch (SecurityException ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); } Options options = new Options(); Option[] optionArray = new Option[] { OptionBuilder.withArgName("configuration").hasArg().isRequired() .withDescription("URL to configuration file for compute host").create("c") }; for (Option opt : optionArray) { options.addOption(opt); } if (args.length == 0) { HelpFormatter hf = new HelpFormatter(); hf.printHelp(StartUp.class.getCanonicalName(), options, true); System.exit(1); } GnuParser gp = new GnuParser(); try { CommandLine cl = gp.parse(options, args); try { URL configURL = new URL(cl.getOptionValue("c")); PropertiesConfiguration cfg = new PropertiesConfiguration(configURL); StartUp su = new StartUp(cfg); } catch (ConfigurationException ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); } catch (MalformedURLException ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); } } catch (ParseException ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Main.java
public static void main(String args[]) throws Exception { LogManager lm = LogManager.getLogManager(); Logger logger; FileHandler fh = new FileHandler("log_test.txt"); logger = Logger.getLogger("LoggingExample1"); lm.addLogger(logger);/*from ww w. j av a 2 s . c o m*/ logger.setLevel(Level.INFO); fh.setFormatter(new XMLFormatter()); logger.addHandler(fh); //logger.setUseParentHandlers(false); logger.log(Level.INFO, "test 1"); logger.log(Level.INFO, "test 2"); logger.log(Level.INFO, "test 3"); fh.close(); }
From source file:LoggingExample1.java
public static void main(String args[]) { try {//w w w . j a v a 2s . c o m LogManager lm = LogManager.getLogManager(); Logger logger; FileHandler fh = new FileHandler("log_test.txt"); logger = Logger.getLogger("LoggingExample1"); lm.addLogger(logger); logger.setLevel(Level.INFO); fh.setFormatter(new XMLFormatter()); logger.addHandler(fh); //logger.setUseParentHandlers(false); logger.log(Level.INFO, "test 1"); logger.log(Level.INFO, "test 2"); logger.log(Level.INFO, "test 3"); fh.close(); } catch (Exception e) { System.out.println("Exception thrown: " + e); e.printStackTrace(); } }
From source file:com.googlecode.promnetpp.main.Main.java
/** * Main function (entry point for the tool). * * @param args Command-line arguments./* w w w .ja va 2 s. c o m*/ */ public static void main(String[] args) { //Prepare logging try { Handler fileHandler = new FileHandler("promnetpp-log.xml"); Logger logger = Logger.getLogger(""); logger.removeHandler(logger.getHandlers()[0]); logger.addHandler(fileHandler); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } catch (SecurityException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } String PROMNeTppHome = System.getenv("PROMNETPP_HOME"); if (PROMNeTppHome == null) { String userDir = System.getProperty("user.dir"); System.err.println("WARNING: PROMNETPP_HOME environment variable" + " not set."); System.err.println("PROMNeT++ will assume " + userDir + " as" + " home."); PROMNeTppHome = userDir; } System.setProperty("promnetpp.home", PROMNeTppHome); Logger.getLogger(Main.class.getName()).log(Level.INFO, "PROMNeT++ home" + " set to {0}", System.getProperty("promnetpp.home")); if (args.length == 1) { fileNameOrPath = args[0]; configurationFilePath = PROMNeTppHome + "/default-configuration.xml"; } else if (args.length == 2) { fileNameOrPath = args[0]; configurationFilePath = args[1]; } else { System.err.println("Invalid number of command-line arguments."); System.err.println("Usage #1: promnetpp.jar <PROMELA model>.pml"); System.err.println("Usage #2: promnetpp.jar <PROMELA model>.pml" + " <configuration file>.xml"); System.exit(1); } //We must have a file name or path at this point assert fileNameOrPath != null : "Unspecified file name or" + " path to file!"; //Log basic info Logger.getLogger(Main.class.getName()).log(Level.INFO, "Running" + " PROMNeT++ from {0}", System.getProperty("user.dir")); //Final steps loadXMLFile(); Verifier verifier = new StandardVerifier(fileNameOrPath); verifier.doVerification(); assert verifier.isErrorFree() : "Errors reported during model" + " verification!"; verifier.finish(); buildAbstractSyntaxTree(); Translator translator = new StandardTranslator(); translator.init(); translator.translate(abstractSyntaxTree); translator.finish(); }
From source file:MainClass.java
public static void main(String args[]) { Logger logger = Logger.getLogger("my.log"); Handler handler = null;// w ww. j a v a 2 s . c o m try { handler = new FileHandler("messages.log"); } catch (IOException e) { System.out.println("Could not create file. Using the console handler"); handler = new ConsoleHandler(); } logger.addHandler(handler); handler.setFormatter(new XMLFormatter()); logger.info("Our first logging message"); logger.severe("Something terrible happened"); }
From source file:net.zdechov.sharpmz.jmzemu.JMzEmu.java
/** * Main method launching the application. * * @param args arguments// ww w . j av a 2 s . c om */ public static void main(String[] args) { try { preferences = Preferences.userNodeForPackage(JMzEmu.class); } catch (SecurityException ex) { preferences = null; } try { bundle = LanguageUtils.getResourceBundleByClass(JMzEmu.class); // Parameters processing Options opt = new Options(); opt.addOption("h", "help", false, bundle.getString("cl_option_help")); opt.addOption("v", false, bundle.getString("cl_option_verbose")); opt.addOption("dev", false, bundle.getString("cl_option_dev")); BasicParser parser = new BasicParser(); CommandLine cl = parser.parse(opt, args); if (cl.hasOption('h')) { HelpFormatter f = new HelpFormatter(); f.printHelp(bundle.getString("cl_syntax"), opt); } else { verboseMode = cl.hasOption("v"); devMode = cl.hasOption("dev"); Logger logger = Logger.getLogger(""); try { logger.setLevel(Level.ALL); logger.addHandler(new XBHead.XBLogHandler(verboseMode)); } catch (java.security.AccessControlException ex) { // Ignore it in java webstart } XBBaseApplication app = new XBBaseApplication(); app.setAppPreferences(new PreferencesWrapper(preferences)); app.setAppBundle(bundle, LanguageUtils.getResourceBaseNameBundleByClass(JMzEmu.class)); XBApplicationModuleRepository moduleRepository = app.getModuleRepository(); moduleRepository.addClassPathModules(); moduleRepository.addModulesFromManifest(JMzEmu.class); moduleRepository.loadModulesFromPath(new File("plugins").toURI()); moduleRepository.initModules(); app.init(); GuiFrameModuleApi frameModule = moduleRepository.getModuleByInterface(GuiFrameModuleApi.class); GuiEditorModuleApi editorModule = moduleRepository.getModuleByInterface(GuiEditorModuleApi.class); GuiMenuModuleApi menuModule = moduleRepository.getModuleByInterface(GuiMenuModuleApi.class); GuiAboutModuleApi aboutModule = moduleRepository.getModuleByInterface(GuiAboutModuleApi.class); GuiFileModuleApi fileModule = moduleRepository.getModuleByInterface(GuiFileModuleApi.class); GuiOptionsModuleApi optionsModule = moduleRepository .getModuleByInterface(GuiOptionsModuleApi.class); GuiUpdateModuleApi updateModule = moduleRepository.getModuleByInterface(GuiUpdateModuleApi.class); frameModule.createMainMenu(); // try { // updateModule.setUpdateUrl(new URL(bundle.getString("update_url"))); // updateModule.setUpdateDownloadUrl(new URL(bundle.getString("update_download_url"))); // } catch (MalformedURLException ex) { // Logger.getLogger(JMzEmu.class.getName()).log(Level.SEVERE, null, ex); // } updateModule.registerDefaultMenuItem(); aboutModule.registerDefaultMenuItem(); AboutDialogSidePanel sidePanel = new AboutDialogSidePanel(); aboutModule.setAboutDialogSideComponent(sidePanel); frameModule.registerExitAction(); frameModule.registerBarsVisibilityActions(); // Register clipboard editing actions fileModule.registerMenuFileHandlingActions(); fileModule.registerToolBarFileHandlingActions(); fileModule.registerLastOpenedMenuActions(); fileModule.registerCloseListener(); // undoModule.registerMainMenu(); // undoModule.registerMainToolBar(); // undoModule.registerUndoManagerInMainMenu(); // Register clipboard editing actions menuModule.getClipboardActions(); // menuModule.registerMenuClipboardActions(); // menuModule.registerToolBarClipboardActions(); optionsModule.registerMenuAction(); // HexPanel hexPanel = (HexPanel) deltaHexModule.getEditorProvider(); // editorModule.registerEditor("hex", hexPanel); // editorModule.registerUndoHandler(); // undoModule.setUndoHandler(hexPanel.getHexUndoHandler()); // deltaHexModule.registerStatusBar(); // deltaHexModule.registerOptionsPanels(); // deltaHexModule.getTextStatusPanel(); updateModule.registerOptionsPanels(); // deltaHexModule.loadFromPreferences(preferences); ApplicationFrameHandler frameHandler = frameModule.getFrameHandler(); GraphicsModule graphicsModule = new GraphicsModule(); frameHandler.setMainPanel(graphicsModule.getGraphicsComponent()); frameHandler.setDefaultSize(new Dimension(600, 400)); frameHandler.show(); updateModule.checkOnStart(frameHandler.getFrame()); List fileArgs = cl.getArgList(); if (fileArgs.size() > 0) { fileModule.loadFromFile((String) fileArgs.get(0)); } } } catch (ParseException | RuntimeException ex) { Logger.getLogger(JMzEmu.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.exbin.deltahex.editor.DeltaHexEditor.java
/** * Main method launching the application. * * @param args arguments// w w w. j a v a2 s . co m */ public static void main(String[] args) { try { preferences = Preferences.userNodeForPackage(DeltaHexEditor.class); } catch (SecurityException ex) { preferences = null; } try { bundle = LanguageUtils.getResourceBundleByClass(DeltaHexEditor.class); // Parameters processing Options opt = new Options(); opt.addOption("h", "help", false, bundle.getString("cl_option_help")); opt.addOption("v", false, bundle.getString("cl_option_verbose")); opt.addOption("dev", false, bundle.getString("cl_option_dev")); BasicParser parser = new BasicParser(); CommandLine cl = parser.parse(opt, args); if (cl.hasOption('h')) { HelpFormatter f = new HelpFormatter(); f.printHelp(bundle.getString("cl_syntax"), opt); } else { verboseMode = cl.hasOption("v"); devMode = cl.hasOption("dev"); Logger logger = Logger.getLogger(""); try { logger.setLevel(Level.ALL); logger.addHandler(new XBHead.XBLogHandler(verboseMode)); } catch (java.security.AccessControlException ex) { // Ignore it in java webstart } XBBaseApplication app = new XBBaseApplication(); app.setAppPreferences(preferences); app.setAppBundle(bundle, LanguageUtils.getResourceBaseNameBundleByClass(DeltaHexEditor.class)); XBApplicationModuleRepository moduleRepository = app.getModuleRepository(); moduleRepository.addClassPathModules(); moduleRepository.addModulesFromManifest(DeltaHexEditor.class); moduleRepository.loadModulesFromPath(new File("plugins").toURI()); moduleRepository.initModules(); app.init(); GuiFrameModuleApi frameModule = moduleRepository.getModuleByInterface(GuiFrameModuleApi.class); GuiEditorModuleApi editorModule = moduleRepository.getModuleByInterface(GuiEditorModuleApi.class); GuiMenuModuleApi menuModule = moduleRepository.getModuleByInterface(GuiMenuModuleApi.class); GuiAboutModuleApi aboutModule = moduleRepository.getModuleByInterface(GuiAboutModuleApi.class); GuiUndoModuleApi undoModule = moduleRepository.getModuleByInterface(GuiUndoModuleApi.class); GuiFileModuleApi fileModule = moduleRepository.getModuleByInterface(GuiFileModuleApi.class); GuiOptionsModuleApi optionsModule = moduleRepository .getModuleByInterface(GuiOptionsModuleApi.class); GuiDockingModuleApi dockingModule = moduleRepository .getModuleByInterface(GuiDockingModuleApi.class); GuiUpdateModuleApi updateModule = moduleRepository.getModuleByInterface(GuiUpdateModuleApi.class); DeltaHexModule deltaHexModule = moduleRepository.getModuleByInterface(DeltaHexModule.class); frameModule.createMainMenu(); try { updateModule.setUpdateUrl(new URL(bundle.getString("update_url"))); updateModule.setUpdateDownloadUrl(new URL(bundle.getString("update_download_url"))); } catch (MalformedURLException ex) { Logger.getLogger(DeltaHexEditor.class.getName()).log(Level.SEVERE, null, ex); } updateModule.registerDefaultMenuItem(); aboutModule.registerDefaultMenuItem(); frameModule.registerExitAction(); frameModule.registerBarsVisibilityActions(); // Component dockingPanel = dockingModule.getDockingPanel(); // Register clipboard editing actions fileModule.registerMenuFileHandlingActions(); fileModule.registerToolBarFileHandlingActions(); fileModule.registerLastOpenedMenuActions(); fileModule.registerCloseListener(); undoModule.registerMainMenu(); undoModule.registerMainToolBar(); undoModule.registerUndoManagerInMainMenu(); // Register clipboard editing actions menuModule.registerMenuClipboardActions(); menuModule.registerToolBarClipboardActions(); optionsModule.registerMenuAction(); // HexEditorProvider editorProvider = deltaHexModule.getMultiEditorProvider(); HexEditorProvider editorProvider = deltaHexModule.getEditorProvider(); deltaHexModule.registerEditFindMenuActions(); deltaHexModule.registerEditFindToolBarActions(); deltaHexModule.registerViewNonprintablesMenuActions(); deltaHexModule.registerToolsOptionsMenuActions(); deltaHexModule.registerClipboardCodeActions(); deltaHexModule.registerOptionsMenuPanels(); deltaHexModule.registerGoToLine(); deltaHexModule.registerPropertiesMenu(); deltaHexModule.registerPrintMenu(); deltaHexModule.registerViewModeMenu(); deltaHexModule.registerCodeTypeMenu(); deltaHexModule.registerPositionCodeTypeMenu(); deltaHexModule.registerHexCharactersCaseHandlerMenu(); deltaHexModule.registerWordWrapping(); ApplicationFrameHandler frameHandler = frameModule.getFrameHandler(); editorModule.registerEditor("hex", editorProvider); // editorModule.registerMultiEditor("hex", (MultiEditorProvider) editorProvider); editorModule.registerUndoHandler(); undoModule.setUndoHandler(editorProvider.getHexUndoHandler()); deltaHexModule.registerStatusBar(); deltaHexModule.registerOptionsPanels(); deltaHexModule.getTextStatusPanel(); updateModule.registerOptionsPanels(); deltaHexModule.loadFromPreferences(preferences); // frameHandler.setMainPanel(dockingPanel); // Single editor only frameHandler.setMainPanel(editorModule.getEditorPanel()); frameHandler.setDefaultSize(new Dimension(600, 400)); frameHandler.show(); updateModule.checkOnStart(frameHandler.getFrame()); List fileArgs = cl.getArgList(); if (fileArgs.size() > 0) { fileModule.loadFromFile((String) fileArgs.get(0)); } } } catch (ParseException | RuntimeException ex) { Logger.getLogger(DeltaHexEditor.class.getName()).log(Level.SEVERE, null, ex); } }