Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*-
  * See the file LICENSE for redistribution information.
  *
  * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
  *
  */
 
 package com.sleepycat.je.utilint;
 
Formatter for java.util.logging output.
public class TracerFormatter extends Formatter {
    private final Date date;
    private final DateFormat formatter;
    private String envName;
    public TracerFormatter() {
         = new Date();
         = makeDateFormat();
    }
    public TracerFormatter(String envName) {
        this();
        this. = envName;
    }
    /* The date and formatter are not thread safe. */
    protected synchronized String getDate(long millis) {
        .setTime(millis);
        return .format();
    }

    
Format the log record in this form: <short date> <short time> <message level> <message>

Parameters:
record the log record to be formatted.
Returns:
a formatted log record
    @Override
    public String format(LogRecord record) {
        StringBuilder sb = new StringBuilder();
        String dateVal = getDate(record.getMillis());
        sb.append(dateVal);
        sb.append(" ");
        sb.append(record.getLevel().getLocalizedName());
        appendEnvironmentName(sb);
        sb.append(" ");
        sb.append(formatMessage(record));
        sb.append("\n");
        getThrown(recordsb);
        return sb.toString();
    }
    protected void appendEnvironmentName(StringBuilder sb) {
        if ( != null) {
            sb.append(" [" +  + "]");
        }
    }
    protected void getThrown(LogRecord recordStringBuilder sb) {
        if (record.getThrown() != null) {
            try {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                record.getThrown().printStackTrace(pw);
                pw.close();
                sb.append(sw.toString());
            } catch (Exception ex) {
                /* Ignored. */
            }
        }
    }
    /* For unit test support */
    public static DateFormat makeDateFormat() {
        return new SimpleDateFormat("yyMMdd HH:mm:ss:SSS");
    }
New to GrepCode? Check out our FAQ X