package net.minecraft.src;

import java.util.logging.Formatter;
import java.util.logging.LogRecord;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.DateFormat;
import java.util.Date;

public class PC_LogFormatter
   extends Formatter
 {
   /**
    * Constructs a SimpleFormatter.
    */
   public PC_LogFormatter()
   {
   }
 
 
   /**
    * An instance of a DateFormatter that is used for formatting
    * the time of a log record into a human-readable string,
    * according to the rules of the current locale.  The value
    * is set after the first invocation of format, since it is
    * common that a JVM will instantiate a SimpleFormatter without
    * ever using it.
    */
   private DateFormat dateFormat;
 
   /**
    * The character sequence that is used to separate lines in the
    * generated stream. Somewhat surprisingly, the Sun J2SE 1.4
    * reference implementation always uses UNIX line endings, even on
    * platforms that have different line ending conventions (i.e.,
    * DOS). The GNU implementation does not replicate this bug.
    *
    * @see Sun bug parade, bug #4462871,
    * "java.util.logging.SimpleFormatter uses hard-coded line separator".
    */
   static final String lineSep = System.getProperty("line.separator");
 
 
   /**
    * Formats a log record into a String.
    *
    * @param record the log record to be formatted.
    *
    * @return a short human-readable message, typically one or two
    *   lines.  Lines are separated using the default platform line
    *   separator.
    *
    * @throws NullPointerException if <code>record</code>
    *         is <code>null</code>.
    */
   public String format(LogRecord record)
   {
     StringBuffer buf = new StringBuffer(180);
 
     if (dateFormat == null)
       dateFormat = DateFormat.getDateTimeInstance();
 
     buf.append(dateFormat.format(new Date(record.getMillis())));
     buf.append(' ');
     buf.append(record.getSourceClassName());
     buf.append(' ');
     buf.append(record.getSourceMethodName());
     buf.append(lineSep);
 
     buf.append(record.getLevel());
     buf.append(": ");
     buf.append(formatMessage(record));
 
     buf.append(lineSep);
 
     Throwable throwable = record.getThrown();
     if (throwable != null)
       {
         StringWriter sink = new StringWriter();
         throwable.printStackTrace(new PrintWriter(sink, true));
         buf.append(sink.toString());
       }
 
     return buf.toString();
   }
 }

