Example usage for java.util.logging LogRecord getMessage

List of usage examples for java.util.logging LogRecord getMessage

Introduction

In this page you can find the example usage for java.util.logging LogRecord getMessage.

Prototype

public String getMessage() 

Source Link

Document

Get the "raw" log message, before localization or formatting.

Usage

From source file:MainClass.java

public static void main(String[] args) {
    logger.setUseParentHandlers(false);/*from  ww  w.  j ava  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:Main.java

public static void main(String[] args) {
    logger.addHandler(new Handler() {
        public void publish(LogRecord logRecord) {
            strHolder.add(logRecord.getLevel() + ":");
            strHolder.add(logRecord.getSourceClassName() + ":");
            strHolder.add(logRecord.getSourceMethodName() + ":");
            strHolder.add("<" + logRecord.getMessage() + ">");
            strHolder.add("\n");
        }//from  w ww .  j a va 2 s  .  co m

        public void flush() {
        }

        public void close() {
        }
    });
    logger.warning("Logging Warning");
    logger.info("Logging Info");
    System.out.print(strHolder);
}

From source file:com.johncroth.histo.logging.LogHistogramWriter.java

public static Formatter createJavaLoggingFormatter() {
    Formatter result = new Formatter() {

        @Override//ww  w. j  av  a2  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// ww  w  .  j a  v a  2 s. c o m
        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:prm4j.indexing.monitor.ParametricMonitorLogger.java

/**
 * A simple file logger which outputs only the message.
 * /*  w w  w .  j a  va 2  s . c om*/
 * @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  w w.  j a va2  s.  c o  m
 *            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:hudson.logging.LogRecorderManager.java

/**
 * Renders the given log recorders as RSS.
 *///from   w  w w .j a va  2  s . co  m
/*package*/ static void doRss(StaplerRequest req, StaplerResponse rsp, List<LogRecord> logs)
        throws IOException, ServletException {
    // filter log records based on the log level
    String level = req.getParameter("level");
    if (level != null) {
        Level threshold = Level.parse(level);
        List<LogRecord> filtered = new ArrayList<LogRecord>();
        for (LogRecord r : logs) {
            if (r.getLevel().intValue() >= threshold.intValue())
                filtered.add(r);
        }
        logs = filtered;
    }

    RSS.forwardToRss("Hudson log", "", logs, new FeedAdapter<LogRecord>() {
        public String getEntryTitle(LogRecord entry) {
            return entry.getMessage();
        }

        public String getEntryUrl(LogRecord entry) {
            return "log"; // TODO: one URL for one log entry?
        }

        public String getEntryID(LogRecord entry) {
            return String.valueOf(entry.getSequenceNumber());
        }

        public String getEntryDescription(LogRecord entry) {
            return Functions.printLogRecord(entry);
        }

        public Calendar getEntryTimestamp(LogRecord entry) {
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTimeInMillis(entry.getMillis());
            return cal;
        }

        public String getEntryAuthor(LogRecord entry) {
            return Mailer.descriptor().getAdminAddress();
        }
    }, req, rsp);
}

From source file:geva.Main.Run.java

protected static void initJavaLogging(java.util.logging.Level level) {
    // All of the library code uses the commons logging library for output.
    // If you want to change the log formats or do anything fancy it's strongly
    // recommended that you switch to the much more capable log4j library as
    // described at http://commons.apache.org/logging/guide.html

    // As a default we'll make the JDK logging behave like System.out.println 
    // so we dont introduce another dependency.

    java.util.logging.SimpleFormatter fmt = new java.util.logging.SimpleFormatter() {
        @Override//from  ww  w .j  a  v a 2s. c o  m
        public synchronized String format(LogRecord record) {
            return record.getMessage() + "\n";
        }
    };
    java.util.logging.Handler handler = new java.util.logging.StreamHandler(System.out, fmt);
    java.util.logging.Logger rootLogger = java.util.logging.Logger.getLogger("");
    for (java.util.logging.Handler h : rootLogger.getHandlers()) {
        rootLogger.removeHandler(h);
    }
    rootLogger.addHandler(handler);
    rootLogger.setLevel(level);

}

From source file:net.oneandone.sushi.fs.webdav.WebdavFilesystem.java

public static void wireLog(String file) {
    Handler handler;/*ww  w.j av a  2  s.  c  om*/

    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:Main.java

public void publish(LogRecord record) {
    String msg = record.getMessage();
    int exceptionIndex = msg.indexOf("Exception");

    if (exceptionIndex > -1) {
        Pattern pattern = Pattern.compile("(.*Exception.*)");

        Matcher matcher = pattern.matcher(msg);

        if (matcher != null && matcher.find()) {
            String err = "EXCEPTION FOUND " + matcher.group(1);
            System.out.println(err);
        }/*from  w  w  w  . j a va2 s  . c  o m*/
    }
}