Log.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. /**
  16. coded by Balancer
  17. balancer@balancer.ru
  18. http://balancer.ru
  19. version 0.1, 2005-06-06
  20. */
  21. package com.l2jserver.gameserver.lib;
  22. import java.io.File;
  23. import java.io.FileWriter;
  24. import java.io.IOException;
  25. import java.text.SimpleDateFormat;
  26. import java.util.Date;
  27. import java.util.logging.Logger;
  28. import com.l2jserver.Config;
  29. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  30. public class Log
  31. {
  32. private static final Logger _log = Logger.getLogger(Log.class.getName());
  33. public static final void add(String text, String cat)
  34. {
  35. /*
  36. * Logger _log = logs.get(cat); if(_log == null) { _log =
  37. * Logger.getLogger(cat); logs.put(cat, _log); }
  38. */
  39. String date = (new SimpleDateFormat("yy.MM.dd H:mm:ss")).format(new Date());
  40. String curr = (new SimpleDateFormat("yyyy-MM-dd-")).format(new Date());
  41. new File("log/game").mkdirs();
  42. FileWriter save = null;
  43. try
  44. {
  45. File file = new File("log/game/" + (curr != null ? curr : "" )+( cat != null ? cat : "unk" )+ ".txt");
  46. save = new FileWriter(file, true);
  47. String out = "[" + date + "] " + text + "\n";
  48. save.write(out);
  49. }
  50. catch (IOException e)
  51. {
  52. _log.warning("saving chat log failed: " + e);
  53. e.printStackTrace();
  54. }
  55. finally
  56. {
  57. try
  58. {
  59. save.close();
  60. }
  61. catch (Exception e)
  62. {
  63. }
  64. }
  65. if (cat != null)
  66. add(text, null);
  67. }
  68. @Deprecated
  69. public static final void addEvent(L2PcInstance pc, String text)
  70. {
  71. String date = (new SimpleDateFormat("yy.MM.dd H:mm:ss")).format(new Date());
  72. String filedate = (new SimpleDateFormat("yyMMdd_H")).format(new Date());
  73. new File("log/game").mkdirs();
  74. File file = new File("log/game/actions_" + filedate + ".txt");
  75. FileWriter save = null;
  76. try
  77. {
  78. save = new FileWriter(file, true);
  79. String out = "[" + date + "] '<" + pc.getName() + ">': " + text + "\n"; // "+char_name()+"
  80. save.write(out);
  81. }
  82. catch (IOException e)
  83. {
  84. _log.warning("saving actions log failed: " + e);
  85. e.printStackTrace();
  86. }
  87. finally
  88. {
  89. try
  90. {
  91. save.close();
  92. }
  93. catch (Exception e1)
  94. {
  95. }
  96. }
  97. }
  98. @Deprecated
  99. public static final void Assert(boolean exp)
  100. {
  101. Assert(exp, "");
  102. }
  103. public static final void Assert(boolean exp, String cmt)
  104. {
  105. if (exp || !Config.ASSERT)
  106. return;
  107. _log.warning("Assertion error [" + cmt + "]");
  108. Thread.dumpStack();
  109. }
  110. }