Example usage for java.util.logging LogRecord getSourceClassName

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

Introduction

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

Prototype

public String getSourceClassName() 

Source Link

Document

Get the name of the class that (allegedly) issued the logging request.

Usage

From source file:com.acuityph.commons.logging.SimpleFormatter.java

/**
 * {@inheritDoc}/*from   w ww . ja v  a2  s .  c  o  m*/
 *
 * @see java.util.logging.Formatter#format(java.util.logging.LogRecord)
 */
@Override
public final String format(final LogRecord logRecord) {
    final StringBuilder sb = new StringBuilder();
    sb.append(LEVELS_MAP.get(logRecord.getLevel()));
    final DateFormat sdf = DateFormat.getDateTimeInstance();
    sb.append(sdf.format(new Date(logRecord.getMillis()))).append(' ');
    sb.append(getShortName(logRecord.getSourceClassName()));
    sb.append('.').append(logRecord.getSourceMethodName()).append(": ");
    sb.append(logRecord.getMessage()).append("\n");
    return sb.toString();
}

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

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

    if (!logcat)/*w  ww  .jav  a 2  s  .  com*/
        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:com.cloudbees.jenkins.support.SupportLogFormatter.java

@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = {
        "DE_MIGHT_IGNORE" }, justification = "The exception wasn't thrown on our stack frame")
public String format(LogRecord record) {
    StringBuilder builder = new StringBuilder();
    builder.append(fdf.format(new Date(record.getMillis())));
    builder.append(" [id=").append(record.getThreadID()).append("]");

    builder.append("\t").append(record.getLevel().getName()).append("\t");

    if (record.getSourceMethodName() != null) {
        String sourceClass;/*from   w w  w . j a  v a2 s  .  c om*/
        if (record.getSourceClassName() == null) {
            sourceClass = record.getLoggerName();
        } else {
            sourceClass = record.getSourceClassName();
        }

        builder.append(abbreviateClassName(sourceClass, 32)).append("#").append(record.getSourceMethodName());
    } else {
        String sourceClass;
        if (record.getSourceClassName() == null) {
            sourceClass = record.getLoggerName();
        } else {
            sourceClass = record.getSourceClassName();
        }
        builder.append(abbreviateClassName(sourceClass, 40));
    }

    builder.append(": ").append(formatMessage(record));

    if (record.getThrown() != null) {
        try {
            StringWriter writer = new StringWriter();
            PrintWriter out = new PrintWriter(writer);
            record.getThrown().printStackTrace(out);
            out.close();
            builder.append(writer.toString());
        } catch (Exception e) {
            // ignore
        }
    }

    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 {/*from   w w  w .  ja v a 2s. c om*/
            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;
}

From source file:org.dstadler.commons.logging.jdk.PatternFormatter.java

@Override
public String format(LogRecord record) {
    Date time = new Date(record.getMillis());
    String formattedTime = dateFormat.format(time);

    final String logMessage;

    if (record.getThrown() == null) {
        Object[] log = { record.getLoggerName(), record.getLevel(), formattedTime, record.getMessage(),
                record.getSourceClassName(), record.getSourceMethodName() };

        logMessage = logMessageFormat.format(log);
    } else {/*from w  w w .j a v a  2s  .  co m*/
        String stack = getStackLayout(record.getThrown(), "");

        Object[] log = { record.getLoggerName(), record.getLevel(), formattedTime, record.getMessage(),
                record.getSourceClassName(), record.getSourceMethodName(), record.getThrown().getMessage(),
                stack };

        logMessage = exceptionMessageFormat.format(log);
    }
    return logMessage;
}

From source file:org.energy_home.jemma.javagal.launcher.main.java

@Override
public String format(LogRecord record) {
    className = record.getSourceClassName();
    lastDotInClassName = className.lastIndexOf('.');
    className = className.substring(lastDotInClassName + 1, className.length());
    return "\n" + className + " " + record.getSourceMethodName() + ": " + record.getMessage();
}

From source file:org.ensembl.healthcheck.StandaloneTestRunner.java

public Logger getLogger() {
    if (logger == null) {
        logger = Logger.getLogger(StandaloneTestRunner.class.getCanonicalName());
        ConsoleHandler localConsoleHandler = new ConsoleHandler();
        localConsoleHandler.setFormatter(new Formatter() {
            DateFormat format = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");

            @Override//from   w  w  w  . j a v a  2 s  . com
            public String format(LogRecord record) {
                return String.format("%s %s %s : %s%n", format.format(new Date(record.getMillis())),
                        record.getSourceClassName(), record.getLevel().toString(), record.getMessage());
            }
        });
        if (options.isVerbose()) {
            localConsoleHandler.setLevel(Level.ALL);
            logger.setLevel(Level.ALL);
        } else {
            localConsoleHandler.setLevel(Level.INFO);
            logger.setLevel(Level.INFO);
        }
        logger.setUseParentHandlers(false);
        logger.addHandler(localConsoleHandler);
    }
    return logger;
}

From source file:org.syphr.mythtv.test.ConsoleFormatter.java

@Override
public String format(LogRecord record) {
    StringBuilder formattedRecord = new StringBuilder(
            StringUtils.rightPad(record.getSourceClassName(), 65, '.'));
    formattedRecord.append(" | ");

    String message = record.getMessage();
    formattedRecord.append(message != null ? message : " no message provided");
    formattedRecord.append(NEWLINE);//  w w w  .  j av  a2s  .  c o m

    Throwable thrown = record.getThrown();
    if (thrown != null) {
        StringWriter sw = new StringWriter();
        thrown.printStackTrace(new PrintWriter(sw));
        formattedRecord.append(sw);
    }

    return formattedRecord.toString();
}

From source file:pl.otros.logview.logging.GuiJulHandler.java

protected boolean isIgnoringLogRecord(LogRecord record) {
    if (record.getLevel().intValue() < Level.INFO.intValue()) {
        for (String ignoreClass : ignoreClassesList) {
            if (StringUtils.equals(ignoreClass, record.getSourceClassName())) {
                return true;
            }/*from  ww w . j  av a 2  s .  c om*/
        }
    }

    return false;
}

From source file:pl.otros.logview.logging.GuiJulHandler.java

@Override
public void publish(LogRecord lr) {
    if (isIgnoringLogRecord(lr)) {
        return;//from  w w w.  j  a v  a 2 s.  com
    }

    LogData ld = new LogData();
    ld.setMessage(lr.getMessage());
    ld.setDate(new Date(lr.getMillis()));
    ld.setFile("Olv-internal");
    ld.setClazz(lr.getSourceClassName());
    ld.setMethod(lr.getSourceMethodName());
    ld.setThread(Integer.toString(lr.getThreadID()));
    ld.setLevel(lr.getLevel());
    if (bufferingLogDataCollectorProxy != null) {
        bufferingLogDataCollectorProxy.add(ld);
    }
}