DamageFormatter.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.log;
  16. import java.text.SimpleDateFormat;
  17. import java.util.Date;
  18. import java.util.logging.Formatter;
  19. import java.util.logging.LogRecord;
  20. import com.l2jserver.gameserver.model.L2Skill;
  21. import com.l2jserver.gameserver.model.actor.L2Attackable;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.L2Summon;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.util.StringUtil;
  26. public class DamageFormatter extends Formatter
  27. {
  28. private static final String CRLF = "\r\n";
  29. private SimpleDateFormat dateFmt = new SimpleDateFormat("yy.MM.dd H:mm:ss");
  30. @Override
  31. public String format(LogRecord record)
  32. {
  33. final Object[] params = record.getParameters();
  34. final StringBuilder output = StringUtil.startAppend(30
  35. + record.getMessage().length()
  36. + (params == null ? 0 : params.length * 10), "[",
  37. dateFmt.format(new Date(record.getMillis())), "] '---': ",
  38. record.getMessage());
  39. for (Object p : params)
  40. {
  41. if (p == null)
  42. continue;
  43. if (p instanceof L2Character)
  44. {
  45. if (p instanceof L2Attackable && ((L2Attackable)p).isRaid())
  46. StringUtil.append(output, "RaidBoss ");
  47. StringUtil.append(output, ((L2Character)p).getName(),
  48. "(", String.valueOf(((L2Character)p).getObjectId()), ") ");
  49. StringUtil.append(output, String.valueOf(((L2Character)p).getLevel()),
  50. " lvl");
  51. if (p instanceof L2Summon)
  52. {
  53. L2PcInstance owner = ((L2Summon)p).getOwner();
  54. if (owner != null)
  55. StringUtil.append(output, " Owner:", owner.getName(),
  56. "(", String.valueOf(owner.getObjectId()), ")");
  57. }
  58. }
  59. else if (p instanceof L2Skill)
  60. {
  61. StringUtil.append(output, " with skill ",((L2Skill)p).getName(),
  62. "(", String.valueOf(((L2Skill)p).getId()), ")");
  63. }
  64. else
  65. StringUtil.append(output, p.toString());
  66. }
  67. output.append(CRLF);
  68. return output.toString();
  69. }
  70. }