Example usage for java.util.logging LogRecord getParameters

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

Introduction

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

Prototype

public Object[] getParameters() 

Source Link

Document

Get the parameters to the log message.

Usage

From source file:Main.java

public static void main(String[] args) {
    sendLogMessages();//from  w  w w.  j av  a2 s  .  co m
    logger.setFilter(new Filter() {
        public boolean isLoggable(LogRecord record) {
            Object[] params = record.getParameters();
            if (params == null)
                return true;
            if (record.getParameters()[0] instanceof A)
                return true;
            return false;
        }
    });
    logger.info("After setting filter..");
    sendLogMessages();
}

From source file:SimpleFilter.java

public static void main(String[] args) {
    sendLogMessages();/*w w  w .  j a v  a 2  s .c o m*/
    logger.setFilter(new Filter() {
        public boolean isLoggable(LogRecord record) {
            Object[] params = record.getParameters();
            if (params == null)
                return true; // No parameters
            if (record.getParameters()[0] instanceof Duck)
                return true; // Only log Ducks
            return false;
        }
    });
    logger.info("After setting filter..");
    sendLogMessages();

}

From source file:Person.java

public boolean isLoggable(LogRecord record) {
    boolean result = false;
    Object[] objs = record.getParameters();
    Person person = (Person) objs[0];/*from   w w  w . j a va 2s . com*/
    if (person != null) {
        int age = person.getAge();
        if (age > 30)
            result = true;
        else
            result = false;
    }
    return result;
}

From source file:at.bitfire.davdroid.log.PlainTextFormatter.java

@Override
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public String format(LogRecord r) {
    StringBuilder builder = new StringBuilder();

    if (!logcat)/*from  w  w  w. j a  va 2 s.  co m*/
        builder.append(DateFormatUtils.format(r.getMillis(), "yyyy-MM-dd HH:mm:ss")).append(" ")
                .append(r.getThreadID()).append(" ");

    builder.append(String.format("[%s] %s", shortClassName(r.getSourceClassName()), r.getMessage()));

    if (r.getThrown() != null)
        builder.append("\nEXCEPTION ").append(ExceptionUtils.getStackTrace(r.getThrown()));

    if (r.getParameters() != null) {
        int idx = 1;
        for (Object param : r.getParameters())
            builder.append("\n\tPARAMETER #").append(idx++).append(" = ").append(param);
    }

    if (!logcat)
        builder.append("\n");

    return builder.toString();
}

From source file:org.fornax.cartridges.sculptor.smartclient.server.util.UnifiedFormatter.java

@Override
public String format(LogRecord record) {
    String username = "ANONYMOUS";
    if (SecurityContextHolder.getContext() != null
            && SecurityContextHolder.getContext().getAuthentication() != null
            && SecurityContextHolder.getContext().getAuthentication().getPrincipal() != null) {
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal instanceof User) {
            username = ((User) principal).getUsername();
        } else {/* w  w w  . j  a  v a 2  s  .c  o  m*/
            username = principal.toString();
        }
    }

    int dotIndex = record.getSourceClassName().lastIndexOf(".");
    String className = record.getSourceClassName().substring(dotIndex != -1 ? dotIndex + 1 : 0);
    String msg = record.getMessage();
    if (record.getParameters() != null && record.getParameters().length > 0) {
        msg = MessageFormat.format(record.getMessage(), record.getParameters());
    }
    if (record.getThrown() != null) {
        Throwable thrown = record.getThrown();
        StringWriter result = new StringWriter();
        thrown.printStackTrace(new PrintWriter(result));
        result.flush();
        msg += "\n" + result.getBuffer();
    }
    return FST + dateFormat.format(record.getMillis()) + FET + FSEP + RST + FST + record.getLevel() + FET + FSEP
            + FST + className + "." + record.getSourceMethodName() + FET + FSEP + FST + username + FET + FSEP
            + FST + record.getThreadID() + FET + FSEP + FST + msg + FET + RET;
}