ItemLogFormatter.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. import net.sf.l2j.gameserver.model.L2ItemInstance;
  26. /**
  27. * @author Advi
  28. *
  29. */
  30. public class ItemLogFormatter extends Formatter
  31. {
  32. private static final String CRLF = "\r\n";
  33. private SimpleDateFormat dateFmt = new SimpleDateFormat("dd MMM H:mm:ss");
  34. @Override
  35. public String format(LogRecord record)
  36. {
  37. TextBuilder output = new TextBuilder();
  38. output.append('[');
  39. output.append(dateFmt.format(new Date(record.getMillis())));
  40. output.append(']');
  41. output.append(' ');
  42. output.append(record.getMessage());
  43. for (Object p : record.getParameters())
  44. {
  45. if (p == null) continue;
  46. output.append(',');
  47. output.append(' ');
  48. if (p instanceof L2ItemInstance)
  49. {
  50. L2ItemInstance item = (L2ItemInstance)p;
  51. output.append("item " + item.getObjectId() + ":");
  52. if (item.getEnchantLevel() > 0) output.append("+" + item.getEnchantLevel() + " ");
  53. output.append(item.getItem().getName());
  54. output.append("(" + item.getCount() + ")");
  55. }
  56. // else if (p instanceof L2PcInstance)
  57. // output.append(((L2PcInstance)p).getName());
  58. else output.append(p.toString()/* + ":" + ((L2Object)p).getObjectId()*/);
  59. }
  60. output.append(CRLF);
  61. return output.toString();
  62. }
  63. }