List of usage examples for java.util.logging XMLFormatter XMLFormatter
public XMLFormatter()
From source file:Main.java
public static void main(String args[]) throws Exception { XMLFormatter formatter = new XMLFormatter(); LogRecord record = new LogRecord(Level.INFO, "XML message.."); FileHandler handler = new FileHandler("newxml.xml"); handler.setFormatter(formatter);//from w w w .j a v a2 s. co m handler.publish(record); handler.flush(); }
From source file:Main.java
public static void main(String args[]) throws Exception { LogManager lm = LogManager.getLogManager(); Logger logger;/* w w w. j av a2 s . c o m*/ 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(); }
From source file:LoggingExample1.java
public static void main(String args[]) { try {//from ww w . j ava2 s. 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:MainClass.java
public static void main(String args[]) { Logger logger = Logger.getLogger("my.log"); Handler handler = null;/*from w ww . ja va2s .com*/ 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:HTMLFormatter.java
public static void main(String args[]) throws Exception { LogManager lm = LogManager.getLogManager(); Logger parentLogger, childLogger; FileHandler xml_handler = new FileHandler("log_output.xml"); FileHandler html_handler = new FileHandler("log_output.html"); parentLogger = Logger.getLogger("ParentLogger"); childLogger = Logger.getLogger("ParentLogger.ChildLogger"); lm.addLogger(parentLogger);// ww w . j a v a 2 s.c om lm.addLogger(childLogger); parentLogger.setLevel(Level.WARNING); childLogger.setLevel(Level.ALL); xml_handler.setFormatter(new XMLFormatter()); html_handler.setFormatter(new HTMLFormatter()); parentLogger.addHandler(xml_handler); childLogger.addHandler(html_handler); childLogger.log(Level.FINE, "This is a fine log message"); childLogger.log(Level.SEVERE, "This is a severe log message"); xml_handler.close(); html_handler.close(); }
From source file:MailHandlerDemo.java
/** * Example for body only messages. On close any remaining messages are sent. <code> * ##logging.properties/* w ww . j a v a2 s.c o m*/ * MailHandlerDemo.handlers=com.sun.mail.util.logging.MailHandler * com.sun.mail.util.logging.MailHandler.subject=Body and attachment demo * com.sun.mail.util.logging.MailHandler.attachment.formatters=java.util.logging.XMLFormatter * com.sun.mail.util.logging.MailHandler.attachment.names=data.xml * ## * </code> */ private static void initSimpleAttachment() { MailHandler h = new MailHandler(); h.setSubject("Body and attachment demo"); h.setAttachmentFormatters(new XMLFormatter()); h.setAttachmentNames("data.xml"); LOGGER.addHandler(h); }
From source file:com.ebixio.virtmus.stats.StatsLogger.java
/** Creates a log handler for the stats logging. * @param newLogSet An identifier: "A" or "B". *///from www.j a v a2s. com private Handler makeLogHandler(String newLogSet) { Handler handler = null; try { String pattern = "VirtMus-" + newLogSet + "-%g.log"; File logFile = getLogFile(pattern); handler = new FileHandler(logFile.getAbsolutePath(), 50 * 1000 * 1000, 10, true); handler.setFormatter(new XMLFormatter()); handler.setEncoding("utf-8"); } catch (IOException | SecurityException ex) { Log.log(ex); } return handler; }
From source file:MailHandlerDemo.java
/** * Example for various kinds of custom sorting, formatting, and filtering * for multiple attachment messages. The subject will contain the most * severe record and a count of remaining records. The log records are * ordered from most severe to least severe. The body uses a custom * formatter that includes a summary by date and time. The attachment use * XML and plain text formats. Each attachment has a different set of * filtering. The attachment names are generated from either a fixed name or * are built using the number and type of the records formatted. On close * any remaining messages are sent. Use the LogManager config option or * extend the MemoryHandler to emulate this behavior via the * logging.properties.//from w ww .java 2 s . co m */ private static void initCustomAttachments() { MailHandler h = new MailHandler(); //Sort records by severity keeping the severe messages at the top. h.setComparator(Collections.reverseOrder(new SeverityComparator())); //Use subject to provide a hint as to what is in the email. h.setSubject(new CollectorFormatter()); //Make the body give a simple summary of what happened. h.setFormatter(new SummaryFormatter()); //Create 3 attachments. h.setAttachmentFormatters(new XMLFormatter(), new XMLFormatter(), new SimpleFormatter()); //Filter each attachment differently. h.setAttachmentFilters(null, new DurationFilter(3L, 1000L), new DurationFilter(1L, 15L * 60L * 1000L)); //Creating the attachment name formatters. h.setAttachmentNames(new CollectorFormatter("all.xml"), new CollectorFormatter("{3} records and {5} errors.xml"), new CollectorFormatter("{5,choice,0#no errors|1#1 error|1<" + "{5,number,integer} errors}.txt")); LOGGER.addHandler(h); }