2
0

Log.java 3.0 KB

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