Log.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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("Error saving logfile: " + e);
  53. e.printStackTrace();
  54. }
  55. finally
  56. {
  57. try
  58. {
  59. save.close();
  60. }
  61. catch (Exception e)
  62. {
  63. }
  64. }
  65. }
  66. @Deprecated
  67. public static final void addEvent(L2PcInstance pc, String text)
  68. {
  69. String date = (new SimpleDateFormat("yy.MM.dd H:mm:ss")).format(new Date());
  70. String filedate = (new SimpleDateFormat("yyMMdd_H")).format(new Date());
  71. new File("log/game").mkdirs();
  72. File file = new File("log/game/actions_" + filedate + ".txt");
  73. FileWriter save = null;
  74. try
  75. {
  76. save = new FileWriter(file, true);
  77. String out = "[" + date + "] '<" + pc.getName() + ">': " + text + "\n"; // "+char_name()+"
  78. save.write(out);
  79. }
  80. catch (IOException e)
  81. {
  82. _log.warning("saving actions log failed: " + e);
  83. e.printStackTrace();
  84. }
  85. finally
  86. {
  87. try
  88. {
  89. save.close();
  90. }
  91. catch (Exception e1)
  92. {
  93. }
  94. }
  95. }
  96. @Deprecated
  97. public static final void Assert(boolean exp)
  98. {
  99. Assert(exp, "");
  100. }
  101. public static final void Assert(boolean exp, String cmt)
  102. {
  103. if (exp || !Config.ASSERT)
  104. return;
  105. _log.warning("Assertion error [" + cmt + "]");
  106. Thread.dumpStack();
  107. }
  108. }