List of usage examples for java.util.logging Formatter Formatter
protected Formatter()
From source file:MainClass.java
public static void main(String[] args) { logger.setUseParentHandlers(false);//from w ww .j a v a 2 s . c om 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:com.johncroth.histo.logging.LogHistogramWriter.java
public static Formatter createJavaLoggingFormatter() { Formatter result = new Formatter() { @Override//w ww . j a v a 2 s . c o m public String format(LogRecord record) { return record.getMessage() + "\n"; } }; return result; }
From source file:com.google.oacurl.util.LoggingConfig.java
public static void enableWireLog() { // For clarity, override the formatter so that it doesn't print the // date and method name for each line, and then munge the output a little // bit to make it nicer and more curl-like. Formatter wireFormatter = new Formatter() { @Override//from ww w.j a v a 2s .c om public String format(LogRecord record) { String message = record.getMessage(); String trimmedMessage = message.substring(">> \"".length(), message.length() - 1); if (trimmedMessage.matches("[0-9a-f]+\\[EOL\\]")) { return ""; } trimmedMessage = trimmedMessage.replace("[EOL]", ""); if (trimmedMessage.isEmpty()) { return ""; } StringBuilder out = new StringBuilder(); out.append(message.charAt(0)); out.append(" "); out.append(trimmedMessage); out.append(System.getProperty("line.separator")); return out.toString(); } }; ConsoleHandler wireHandler = new ConsoleHandler(); wireHandler.setLevel(Level.FINE); wireHandler.setFormatter(wireFormatter); Logger wireLogger = Logger.getLogger("org.apache.http.wire"); wireLogger.setLevel(Level.FINE); wireLogger.setUseParentHandlers(false); wireLogger.addHandler(wireHandler); }
From source file:net.oneandone.sushi.fs.webdav.WebdavFilesystem.java
public static void wireLog(String file) { Handler handler;/*from w ww . ja va 2 s.c o m*/ WIRE.setLevel(Level.FINE); try { handler = new FileHandler(file, false); } catch (IOException e) { throw new IllegalStateException(e); } handler.setFormatter(new Formatter() { @Override public String format(LogRecord record) { String message; Throwable e; StringBuilder result; message = record.getMessage(); result = new StringBuilder(message.length() + 1); result.append(message); result.append('\n'); e = record.getThrown(); if (e != null) { // TODO getStacktrace(e, result); } return result.toString(); } }); WIRE.addHandler(handler); }
From source file:com.p000ison.dev.simpleclans2.dataserver.ServerLoggerHandler.java
@Override public Formatter getFormatter() { return new Formatter() { @Override/*from w ww .j a va 2s. c o m*/ public String format(LogRecord record) { String message = DATE_FORMAT.format(record.getMillis()) + " [" + record.getLevel().toString() + "] " + record.getMessage() + "\n"; if (record.getThrown() != null) { message += ExceptionUtils.getStackTrace(record.getThrown()) + '\n'; } return message; } }; }
From source file:com.skelril.aurora.jail.CSVInmateDatabase.java
public CSVInmateDatabase(File inmateStorageDir) { inmateFile = new File(inmateStorageDir, "inmates.csv"); // Set up an audit trail try {//www.java 2 s . co m FileHandler handler = new FileHandler( (new File(inmateStorageDir, "inmates.%g.%u.log")).getAbsolutePath().replace("\\", "/"), true); handler.setFormatter(new Formatter() { @Override public String format(LogRecord record) { return "[" + dateFormat.format(new Date()) + "] " + record.getMessage() + "\r\n"; } }); auditLogger.addHandler(handler); } catch (SecurityException | IOException e) { log.warning("Failed to setup audit log for the " + "CSV inmate database: " + e.getMessage()); } }
From source file:net.poemerchant.ui.ScraperSwingWorker.java
@Override public Void doInBackground() throws Exception { // all logger message will also go to our printStream logger.addHandler(new StreamHandler(printStream, new Formatter() { @Override/* w ww. j a va2 s. co m*/ public String format(LogRecord record) { // System.out.println("intercept: " + record.getMessage()); return record.getMessage() + System.lineSeparator(); } }) { @Override public synchronized void publish(LogRecord record) { super.publish(record); flush(); } }); ShopIndexScraper scraper = new ShopIndexScraper(shopSubForumUrl); logger.info("Scrapping shops subform index: " + shopSubForumUrl); List<String> shopUrls = null; try { shopUrls = scraper.scrape(); } catch (PoEMerchantException e) { logger.severe("Error: " + e.getMessage() + ". Try again."); return null; } // shopUrls = new ArrayList(); // shopUrls.add(this.getClass().getResource("/1148541.htm").getFile()); logger.info("Sucessfully scraped subform, number of shops: " + shopUrls.size()); for (String url : shopUrls) { logger.info("Scrapping shop: " + url); try { scrapeAndSaveShop(configuration.getIndex(), configuration.getType(), url); } catch (Exception e) { logger.severe("error caught for " + url + ". err msg: " + e.getMessage()); } } logger.info(String.format("Sucessfully scraped %d shops.", shopUrls.size())); return null; }
From source file:prm4j.indexing.monitor.ParametricMonitorLogger.java
/** * A simple file logger which outputs only the message. * /* ww w .ja va 2 s. com*/ * @param fileName * path to the output file * @return the logger */ private static Logger getFileLogger(String fileName) { // make sure parent directories exist new File(fileName).getParentFile().mkdirs(); final Logger logger = Logger.getLogger(fileName); try { logger.setUseParentHandlers(false); Handler handler = new FileHandler(fileName, true); handler.setFormatter(new Formatter() { @Override public String format(LogRecord record) { return record.getMessage() + "\n"; } }); logger.addHandler(handler); } catch (Exception e) { throw new RuntimeException(e); } return logger; }
From source file:mop.MemoryLogger.java
/** * A simple file logger which outputs only the message. * * @param fileName// w ww . j a va 2 s . c om * path to the output file * @return the logger */ private static Logger getFileLogger(String fileName) { final Logger logger = Logger.getLogger(fileName); try { logger.setUseParentHandlers(false); Handler handler = new FileHandler(fileName, true); handler.setFormatter(new Formatter() { @Override public String format(LogRecord record) { return record.getMessage() + "\n"; } }); logger.addHandler(handler); } catch (Exception e) { throw new RuntimeException(e); } return logger; }
From source file:org.ensembl.healthcheck.testcase.AbstractPerlModuleBasedTestCase.java
/** * @return formatter for log messages originating in a perl based healthcheck. */// w w w .jav a2 s . com protected Formatter createPerlLogMessageFormatter() { return new Formatter() { @Override public String formatMessage(LogRecord logRecord) { return logRecord.getMessage(); } @Override public String format(LogRecord logRecord) { return formatMessage(logRecord) + "\n"; } }; }