FileLogFormatter.java 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2, or (at your option)
  5. * any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. * 02111-1307, USA.
  16. *
  17. * http://www.gnu.org/copyleft/gpl.html
  18. */
  19. package net.sf.l2j;
  20. import java.text.SimpleDateFormat;
  21. import java.util.Date;
  22. import java.util.logging.Formatter;
  23. import java.util.logging.LogRecord;
  24. import javolution.text.TextBuilder;
  25. /**
  26. * This class ...
  27. *
  28. * @version $Revision: 1.1.4.1 $ $Date: 2005/03/27 15:30:08 $
  29. */
  30. public class FileLogFormatter extends Formatter
  31. {
  32. /* (non-Javadoc)
  33. * @see java.util.logging.Formatter#format(java.util.logging.LogRecord)
  34. */
  35. private static final String CRLF = "\r\n";
  36. private static final String _ = "\t";
  37. private SimpleDateFormat dateFmt = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss,SSS");
  38. @Override
  39. public String format(LogRecord record)
  40. {
  41. TextBuilder output = new TextBuilder();
  42. return output
  43. .append(dateFmt.format(new Date(record.getMillis())))
  44. .append(_)
  45. .append(record.getLevel().getName())
  46. .append(_)
  47. .append(record.getThreadID())
  48. .append(_)
  49. .append(record.getLoggerName())
  50. .append(_)
  51. .append(record.getMessage())
  52. .append(CRLF)
  53. .toString();
  54. }
  55. }