List of usage examples for java.util.logging ConsoleHandler ConsoleHandler
public ConsoleHandler()
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);/*from ww w . j a v a 2 s . co m*/ logger.setUseParentHandlers(false); 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:MainClass.java
public static void main(String[] args) throws Exception { FileHandler logFile = new FileHandler("MultipleHandlers.xml"); logger.addHandler(logFile);// ww w . ja va 2s .c o m logger.addHandler(new ConsoleHandler()); logger.warning("Output to multiple handlers"); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { FileHandler logFile = new FileHandler("MultipleHandlers2.xml"); logger.addHandler(logFile);/*from ww w. ja v a2s . c om*/ logger.addHandler(new ConsoleHandler()); logger.setUseParentHandlers(false); logger.warning("Output to multiple handlers"); }
From source file:MainClass.java
public static void main(String[] args) { logger.setUseParentHandlers(false);/* w w w. j a v a2 s .c o m*/ Handler conHdlr = new ConsoleHandler(); conHdlr.setFormatter(new Formatter() { public String format(LogRecord record) { return record.getLevel() + " : " + record.getSourceClassName() + " -:- " + record.getSourceMethodName() + " -:- " + record.getMessage() + "\n"; } }); logger.addHandler(conHdlr); logMessages(); }
From source file:MainClass.java
public static void main(String args[]) { Logger logger = Logger.getLogger("my.log"); Handler handler = null;/*from w ww. j a va 2 s . c om*/ 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:ar.com.ergio.uncoma.cei.MiniPas.java
/** * @param args/* w w w .j a v a 2s. c o m*/ * @throws IOException */ @SuppressWarnings("static-access") public static void main(String[] args) throws IOException { // Config logging system -- TODO improve this Handler console = new ConsoleHandler(); ROOT_LOG.addHandler(console); // Create cmdline options - TODO - I18N final Options options = new Options(); options.addOption(new Option("help", "Muestra este mensaje")); options.addOption(new Option("version", "Muestra la informaci\u00f3 de versi\u00f3n y termina")); options.addOption(new Option("debug", "Muestra informaci\u00f3n para depuraci\u00f3n")); options.addOption( OptionBuilder.withArgName("file").hasArg().withDescription("Archivo de log").create("logFile")); final CommandLineParser cmdlineParser = new GnuParser(); final HelpFormatter formatter = new HelpFormatter(); try { final CommandLine cmdline = cmdlineParser.parse(options, args); // Process command line args -- TODO Improve this if (args.length == 0 || cmdline.hasOption("help")) { formatter.printHelp("minipas", options, true); } else if (cmdline.hasOption("version")) { System.out.println("MiniPas versi\u00f3n: 0.0.1"); } else if (cmdline.hasOption("debug")) { ROOT_LOG.setLevel(Level.FINE); } else { ROOT_LOG.fine("Arguments: " + Arrays.toString(args)); final Scanner scanner = new Scanner(args[0]); while (scanner.hasTokens()) { System.out.println(scanner.nextToken()); } } } catch (ParseException e) { formatter.printHelp("minipas", options, true); } }
From source file:de.burlov.amazon.s3.dirsync.CLI.java
/** * @param args//from w w w.j av a2s . c o m */ @SuppressWarnings("static-access") public static void main(String[] args) { Logger.getLogger("").setLevel(Level.OFF); Logger deLogger = Logger.getLogger("de"); deLogger.setLevel(Level.INFO); Handler handler = new ConsoleHandler(); handler.setFormatter(new VerySimpleFormatter()); deLogger.addHandler(handler); deLogger.setUseParentHandlers(false); // if (true) // { // LogFactory.getLog(CLI.class).error("test msg", new Exception("test extception")); // return; // } Options opts = new Options(); OptionGroup gr = new OptionGroup(); /* * Befehlsgruppe initialisieren */ gr = new OptionGroup(); gr.setRequired(true); gr.addOption(OptionBuilder.withArgName("up|down").hasArg() .withDescription("Upload/Download changed or new files").create(CMD_UPDATE)); gr.addOption(OptionBuilder.withArgName("up|down").hasArg() .withDescription("Upload/Download directory snapshot").create(CMD_SNAPSHOT)); gr.addOption(OptionBuilder.withDescription("Delete remote folder").create(CMD_DELETE_DIR)); gr.addOption(OptionBuilder.withDescription("Delete a bucket").create(CMD_DELETE_BUCKET)); gr.addOption(OptionBuilder.create(CMD_HELP)); gr.addOption(OptionBuilder.create(CMD_VERSION)); gr.addOption(OptionBuilder.withDescription("Prints summary for stored data").create(CMD_SUMMARY)); gr.addOption(OptionBuilder.withDescription("Clean up orphaned objekts").create(CMD_CLEANUP)); gr.addOption(OptionBuilder.withDescription("Changes encryption password").withArgName("new password") .hasArg().create(CMD_CHANGE_PASSWORD)); gr.addOption(OptionBuilder.withDescription("Lists all buckets").create(CMD_LIST_BUCKETS)); gr.addOption(OptionBuilder.withDescription("Lists raw objects in a bucket").create(CMD_LIST_BUCKET)); gr.addOption(OptionBuilder.withDescription("Lists files in remote folder").create(CMD_LIST_DIR)); opts.addOptionGroup(gr); /* * Parametergruppe initialisieren */ opts.addOption(OptionBuilder.withArgName("key").isRequired(false).hasArg().withDescription("S3 access key") .create(OPT_S3S_KEY)); opts.addOption(OptionBuilder.withArgName("secret").isRequired(false).hasArg() .withDescription("Secret key for S3 account").create(OPT_S3S_SECRET)); opts.addOption(OptionBuilder.withArgName("bucket").isRequired(false).hasArg().withDescription( "Optional bucket name for storage. If not specified then an unique bucket name will be generated") .create(OPT_BUCKET)); // opts.addOption(OptionBuilder.withArgName("US|EU").hasArg(). // withDescription( // "Where the new bucket should be created. Default US").create( // OPT_LOCATION)); opts.addOption(OptionBuilder.withArgName("path").isRequired(false).hasArg() .withDescription("Local directory path").create(OPT_LOCAL_DIR)); opts.addOption(OptionBuilder.withArgName("name").isRequired(false).hasArg() .withDescription("Remote directory name").create(OPT_REMOTE_DIR)); opts.addOption(OptionBuilder.withArgName("password").isRequired(false).hasArg() .withDescription("Encryption password").create(OPT_ENC_PASSWORD)); opts.addOption(OptionBuilder.withArgName("patterns").hasArgs() .withDescription("Comma separated exclude file patterns like '*.tmp,*/dir/*.tmp'") .create(OPT_EXCLUDE_PATTERNS)); opts.addOption(OptionBuilder.withArgName("patterns").hasArgs().withDescription( "Comma separated include patterns like '*.java'. If not specified, then all files in specified local directory will be included") .create(OPT_INCLUDE_PATTERNS)); if (args.length == 0) { printUsage(opts); return; } CommandLine cmd = null; try { cmd = new GnuParser().parse(opts, args); if (cmd.hasOption(CMD_HELP)) { printUsage(opts); return; } if (cmd.hasOption(CMD_VERSION)) { System.out.println("s3dirsync version " + Version.CURRENT_VERSION); return; } String awsKey = cmd.getOptionValue(OPT_S3S_KEY); String awsSecret = cmd.getOptionValue(OPT_S3S_SECRET); String bucket = cmd.getOptionValue(OPT_BUCKET); String bucketLocation = cmd.getOptionValue(OPT_LOCATION); String localDir = cmd.getOptionValue(OPT_LOCAL_DIR); String remoteDir = cmd.getOptionValue(OPT_REMOTE_DIR); String password = cmd.getOptionValue(OPT_ENC_PASSWORD); String exclude = cmd.getOptionValue(OPT_EXCLUDE_PATTERNS); String include = cmd.getOptionValue(OPT_INCLUDE_PATTERNS); if (StringUtils.isBlank(awsKey) || StringUtils.isBlank(awsSecret)) { System.out.println("S3 account data required"); return; } if (StringUtils.isBlank(bucket)) { bucket = awsKey + ".dirsync"; } if (cmd.hasOption(CMD_DELETE_BUCKET)) { if (StringUtils.isBlank(bucket)) { System.out.println("Bucket name required"); return; } int deleted = S3Utils.deleteBucket(awsKey, awsSecret, bucket); System.out.println("Deleted objects: " + deleted); return; } if (cmd.hasOption(CMD_LIST_BUCKETS)) { for (String str : S3Utils.listBuckets(awsKey, awsSecret)) { System.out.println(str); } return; } if (cmd.hasOption(CMD_LIST_BUCKET)) { if (StringUtils.isBlank(bucket)) { System.out.println("Bucket name required"); return; } for (String str : S3Utils.listObjects(awsKey, awsSecret, bucket)) { System.out.println(str); } return; } if (StringUtils.isBlank(password)) { System.out.println("Encryption password required"); return; } char[] psw = password.toCharArray(); DirSync ds = new DirSync(awsKey, awsSecret, bucket, bucketLocation, psw); ds.setExcludePatterns(parseSubargumenths(exclude)); ds.setIncludePatterns(parseSubargumenths(include)); if (cmd.hasOption(CMD_SUMMARY)) { ds.printStorageSummary(); return; } if (StringUtils.isBlank(remoteDir)) { System.out.println("Remote directory name required"); return; } if (cmd.hasOption(CMD_DELETE_DIR)) { ds.deleteFolder(remoteDir); return; } if (cmd.hasOption(CMD_LIST_DIR)) { Folder folder = ds.getFolder(remoteDir); if (folder == null) { System.out.println("No such folder found: " + remoteDir); return; } for (Map.Entry<String, FileInfo> entry : folder.getIndexData().entrySet()) { System.out.println(entry.getKey() + " (" + FileUtils.byteCountToDisplaySize(entry.getValue().getLength()) + ")"); } return; } if (cmd.hasOption(CMD_CLEANUP)) { ds.cleanUp(); return; } if (cmd.hasOption(CMD_CHANGE_PASSWORD)) { String newPassword = cmd.getOptionValue(CMD_CHANGE_PASSWORD); if (StringUtils.isBlank(newPassword)) { System.out.println("new password required"); return; } char[] chars = newPassword.toCharArray(); ds.changePassword(chars); newPassword = null; Arrays.fill(chars, ' '); return; } if (StringUtils.isBlank(localDir)) { System.out.println(OPT_LOCAL_DIR + " argument required"); return; } String direction = ""; boolean up = false; boolean snapshot = false; if (StringUtils.isNotBlank(cmd.getOptionValue(CMD_UPDATE))) { direction = cmd.getOptionValue(CMD_UPDATE); } else if (StringUtils.isNotBlank(cmd.getOptionValue(CMD_SNAPSHOT))) { direction = cmd.getOptionValue(CMD_SNAPSHOT); snapshot = true; } if (StringUtils.isBlank(direction)) { System.out.println("Operation direction required"); return; } up = StringUtils.equalsIgnoreCase(OPT_UP, direction); File baseDir = new File(localDir); if (!baseDir.exists() && !baseDir.mkdirs()) { System.out.println("Invalid local directory: " + baseDir.getAbsolutePath()); return; } ds.syncFolder(baseDir, remoteDir, up, snapshot); } catch (DirSyncException e) { System.out.println(e.getMessage()); e.printStackTrace(); } catch (ParseException e) { System.out.println(e.getMessage()); printUsage(opts); } catch (Exception e) { e.printStackTrace(System.err); } }
From source file:core.PlanC.java
/** * inicio de aplicacion/*from w w w. j a v a 2 s. c o m*/ * * @param arg - argumentos de entrada */ public static void main(String[] args) { // user.name /* * Properties prp = System.getProperties(); System.out.println(getWmicValue("bios", "SerialNumber")); * System.out.println(getWmicValue("cpu", "SystemName")); */ try { // log // -Djava.util.logging.SimpleFormatter.format='%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n' // System.setProperty("java.util.logging.SimpleFormatter.format", // "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n"); System.setProperty("java.util.logging.SimpleFormatter.format", "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %5$s%6$s%n"); FileHandler fh = new FileHandler(LOG_FILE); fh.setFormatter(new SimpleFormatter()); fh.setLevel(Level.INFO); ConsoleHandler ch = new ConsoleHandler(); ch.setFormatter(new SimpleFormatter()); ch.setLevel(Level.INFO); logger = Logger.getLogger(""); Handler[] hs = logger.getHandlers(); for (int x = 0; x < hs.length; x++) { logger.removeHandler(hs[x]); } logger.addHandler(fh); logger.addHandler(ch); // point apache log to this log System.setProperty("org.apache.commons.logging.Log", Jdk14Logger.class.getName()); TPreferences.init(); TStringUtils.init(); Font fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("Dosis-Light.ttf")); GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo); fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("Dosis-Medium.ttf")); GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo); fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("AERO_ITALIC.ttf")); GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo); SwingTimerTimingSource ts = new SwingTimerTimingSource(); AnimatorBuilder.setDefaultTimingSource(ts); ts.init(); // parse app argument parameters and append to tpreferences to futher uses for (String arg : args) { String[] kv = arg.split("="); TPreferences.setProperty(kv[0], kv[1]); } RUNNING_MODE = TPreferences.getProperty("runningMode", RM_NORMAL); newMsg = Applet.newAudioClip(TResourceUtils.getURL("newMsg.wav")); } catch (Exception e) { SystemLog.logException1(e, true); } // pass icon from metal to web look and feel Icon i1 = UIManager.getIcon("OptionPane.errorIcon"); Icon i2 = UIManager.getIcon("OptionPane.informationIcon"); Icon i3 = UIManager.getIcon("OptionPane.questionIcon"); Icon i4 = UIManager.getIcon("OptionPane.warningIcon"); // Object fcui = UIManager.get("FileChooserUI"); // JFileChooser fc = new JFileChooser(); WebLookAndFeel.install(); // WebLookAndFeel.setDecorateFrames(true); // WebLookAndFeel.setDecorateDialogs(true); UIManager.put("OptionPane.errorIcon", i1); UIManager.put("OptionPane.informationIcon", i2); UIManager.put("OptionPane.questionIcon", i3); UIManager.put("OptionPane.warningIcon", i4); // UIManager.put("TFileChooserUI", fcui); // warm up the IDW. // in my computer, some weird error ocurr if i don't execute this preload. new RootWindow(null); frame = new TWebFrame(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { Exit.shutdown(); } }); if (RUNNING_MODE.equals(RM_NORMAL)) { initEnviorement(); } if (RUNNING_MODE.equals(RM_CONSOLE)) { initConsoleEnviorement(); } if (RUNNING_MODE.equals(ONE_TASK)) { String cln = TPreferences.getProperty("taskName", "*TaskNotFound"); PlanC.logger.log(Level.INFO, "OneTask parameter found in .properties. file Task name = " + cln); try { Class cls = Class.forName(cln); Object dobj = cls.newInstance(); // new class must be extends form AbstractExternalTask TTaskManager.executeTask((Runnable) dobj); return; } catch (Exception e) { PlanC.logger.log(Level.SEVERE, e.getMessage(), e); Exit.shutdown(); } } }
From source file:org.wor.drawca.DrawCAMain.java
/** * Main function which start drawing the cellular automata. * * @param args Command line arguments./*from ww w . j ava 2 s. c o m*/ */ public static void main(final String[] args) { final Logger log = Logger.getGlobal(); LogManager.getLogManager().reset(); Options options = new Options(); boolean hasArgs = true; // TODO: show defaults in option description options.addOption("h", "help", !hasArgs, "Show this help message"); options.addOption("pci", "perclickiteration", !hasArgs, "Generate one line per mouse click"); options.addOption("v", "verbose", hasArgs, "Verbosity level [-1,7]"); options.addOption("r", "rule", hasArgs, "Rule number to use 0-255"); options.addOption("wh", "windowheigth", hasArgs, "Draw window height"); options.addOption("ww", "windowwidth", hasArgs, "Draw window width"); options.addOption("x", "xscalefactor", hasArgs, "X Scale factor"); options.addOption("y", "yscalefactor", hasArgs, "Y scale factor"); options.addOption("f", "initline", hasArgs, "File name with Initial line."); CommandLineParser parser = new PosixParser(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { e.printStackTrace(); showHelp(options); return; } // Options without an argument if (cmd.hasOption("h")) { showHelp(options); return; } final boolean perClickIteration = cmd.hasOption("pci"); // Options with an argument final int verbosityLevel = Integer.parseInt(cmd.getOptionValue('v', "0")); final int rule = Integer.parseInt(cmd.getOptionValue('r', "110")); final int windowHeigth = Integer.parseInt(cmd.getOptionValue("wh", "300")); final int windowWidth = Integer.parseInt(cmd.getOptionValue("ww", "400")); final float xScaleFactor = Float.parseFloat(cmd.getOptionValue('x', "2.0")); final float yScaleFactor = Float.parseFloat(cmd.getOptionValue('y', "2.0")); final String initLineFile = cmd.getOptionValue('f', ""); final Level logLevel = VERBOSITY_MAP.get(verbosityLevel); log.setLevel(logLevel); // Set log handler Handler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(logLevel); log.addHandler(consoleHandler); log.info("Log level set to: " + log.getLevel()); // Read initial line from a file String initLine = ""; if (initLineFile.length() > 0) { Path initLineFilePath = FileSystems.getDefault().getPath(initLineFile); try { // Should be string of ones and zeros only initLine = new String(Files.readAllBytes(initLineFilePath), "UTF-8"); } catch (IOException e) { System.err.format("IOException: %s\n", e); return; } } SwingUtilities.invokeLater(new RunGUI(windowWidth, windowHeigth, xScaleFactor, yScaleFactor, rule, initLine, perClickIteration)); }
From source file:com.flagleader.builder.FlagLeader.java
public static void main(String[] paramArrayOfString) { Shell localShell = new Shell(16777216); localShell.setLocation(new Point(300, 200)); localShell.setLayout(new FillLayout()); Composite localComposite = new Composite(localShell, 0); localComposite.setLayout(new FillLayout()); Label localLabel = new Label(localComposite, 0); Image localImage = ImageDescriptor .createFromURL(localShell.getClass().getClassLoader().getResource("icons/start.jpg")).createImage(); localLabel.setImage(localImage);// ww w . j av a 2s. co m localShell.setSize(400, 300); localShell.setText("Visual Rules Solution"); localShell.open(); Init.a(); String str = null; if (BuilderConfig.getInstance().isLoadDefault()) str = RuleRepository.DEFAULTEXT; if (paramArrayOfString.length > 0) str = ""; for (int i = 0; i < paramArrayOfString.length; i++) str = str + paramArrayOfString[i] + " "; Logger localLogger = Logger.getLogger("ruleengine"); Object localObject; try { new File(SystemUtils.USER_HOME + File.separator + ".visualrules" + File.separator + "logs").mkdirs(); FileHandler localFileHandler = new FileHandler(SystemUtils.USER_HOME + File.separator + ".visualrules" + File.separator + "logs" + File.separator + "logfile%u.%g.txt", 0, 10); localFileHandler.setFormatter(new com.flagleader.server.c()); localFileHandler.setLevel(Level.ALL); Logger.getLogger("flagleader").addHandler(localFileHandler); localLogger.addHandler(localFileHandler); } catch (Exception localException1) { if (!b) { localObject = new ConsoleHandler(); ((ConsoleHandler) localObject).setFormatter(new com.flagleader.server.c()); ((ConsoleHandler) localObject).setLevel(Level.ALL); Logger.getLogger("flagleader").addHandler((Handler) localObject); localLogger.addHandler((Handler) localObject); } } if (!BuilderManager.checkLicense()) { localImage.dispose(); localShell.dispose(); return; } Property.getInstance().setEngineImplement("com.flagleader.engine.impl.SingleRuleEngineFactory"); FlagLeader localFlagLeader = new FlagLeader(); Property.getInstance().setUpdateInternateTime(0L); localFlagLeader.setBlockOnOpen(true); localFlagLeader.builderManager = new BuilderManager(localFlagLeader); if ((com.flagleader.manager.d.c.a("needLogin", false)) || (BuilderConfig.getInstance().isFirstLogin())) try { localObject = localFlagLeader.builderManager.getUserServer(); if ((localObject == null) || (((String) localObject).length() == 0) || (localFlagLeader.builderManager.getUserType() == 0) || (localFlagLeader.builderManager.getUserid() == 0)) { localImage.dispose(); localShell.dispose(); return; } } catch (Exception localException2) { MessageDialog.openError(null, "", ResourceTools.getMessage("loginserver.error") + localException2.getLocalizedMessage()); localImage.dispose(); localShell.dispose(); return; } if ((str != null) && (new File(str).exists())) localFlagLeader.builderManager.getRulesManager().a(new File(str)); localFlagLeader.initWindow(); if (new File(SystemUtils.JAVA_IO_TMPDIR, "engine.jar").exists()) new File(SystemUtils.JAVA_IO_TMPDIR, "engine.jar").delete(); if (new File(SystemUtils.JAVA_IO_TMPDIR, "export.jar").exists()) new File(SystemUtils.JAVA_IO_TMPDIR, "export.jar").delete(); if (BuilderConfig.getInstance().isAutosave()) new com.flagleader.builder.d.c(localFlagLeader.builderManager).b(); if (BuilderConfig.getInstance().isAutoCheckVersion()) new a(localFlagLeader.builderManager).b(); new e().b(); localImage.dispose(); localShell.dispose(); localFlagLeader.open(); BuilderManager localBuilderManager = localFlagLeader.builderManager; localFlagLeader.getShell().addShellListener(new d(localBuilderManager)); }