Log.java 3.1 KB

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