AuditFormatter.java 1.7 KB

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