DamageFormatter.java 2.8 KB

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