DamageFormatter.java 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. if (params != null)
  40. {
  41. for (Object p : params)
  42. {
  43. if (p == null)
  44. continue;
  45. if (p instanceof L2Character)
  46. {
  47. if (p instanceof L2Attackable && ((L2Attackable)p).isRaid())
  48. StringUtil.append(output, "RaidBoss ");
  49. StringUtil.append(output, ((L2Character)p).getName(),
  50. "(", String.valueOf(((L2Character)p).getObjectId()), ") ");
  51. StringUtil.append(output, String.valueOf(((L2Character)p).getLevel()),
  52. " lvl");
  53. if (p instanceof L2Summon)
  54. {
  55. L2PcInstance owner = ((L2Summon)p).getOwner();
  56. if (owner != null)
  57. StringUtil.append(output, " Owner:", owner.getName(),
  58. "(", String.valueOf(owner.getObjectId()), ")");
  59. }
  60. }
  61. else if (p instanceof L2Skill)
  62. {
  63. StringUtil.append(output, " with skill ",((L2Skill)p).getName(),
  64. "(", String.valueOf(((L2Skill)p).getId()), ")");
  65. }
  66. else
  67. StringUtil.append(output, p.toString());
  68. }
  69. }
  70. output.append(CRLF);
  71. return output.toString();
  72. }
  73. }