package nxm.sys.lib;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;

import nxm.sys.inc.InternalUseOnly;
import nxm.sys.lib.LogUtilities.EnhancedLogRecord;

/**
 * This is a sample formatter and is not to be used for production purposes. This is only for reference.
 * @author Kevin Esterheld
 *
 */
@InternalUseOnly("Not tested")
public class SampleFormatter extends Formatter {

  /** default constructor */
  public SampleFormatter () {}

  @Override
  public String format (LogRecord rec) {
    Date date = new Date(rec.getMillis());
    DateFormat df = new SimpleDateFormat("MMM d, y hh:mm:ss z");
    String lineNum = "";
    String methodName = rec.getSourceMethodName()==null ? "" : rec.getSourceMethodName();
    if(rec instanceof EnhancedLogRecord) lineNum = "["+((EnhancedLogRecord)rec).getSourceLineNumber()+"]";
    return df.format(date) + " "+
        rec.getSourceClassName() + "." +
        methodName +
        lineNum + " "+
        rec.getLevel() +": "+
        rec.getMessage() +"\n";
  }
}
