Log.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.util.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. public class Log
  29. {
  30. private static final Logger _log = Logger.getLogger(Log.class.getName());
  31. public static final void add(String text, String cat)
  32. {
  33. /*
  34. * Logger _log = logs.get(cat); if(_log == null) { _log =
  35. * Logger.getLogger(cat); logs.put(cat, _log); }
  36. */
  37. String date = (new SimpleDateFormat("yy.MM.dd H:mm:ss")).format(new Date());
  38. String curr = (new SimpleDateFormat("yyyy-MM-dd-")).format(new Date());
  39. new File("log/game").mkdirs();
  40. FileWriter save = null;
  41. try
  42. {
  43. File file = new File("log/game/" + (curr != null ? curr : "" )+(cat != null ? cat : "unk") + ".txt");
  44. save = new FileWriter(file, true);
  45. String out = "[" + date + "] " + text + "\n";
  46. save.write(out);
  47. }
  48. catch (IOException e)
  49. {
  50. _log.warning("Error saving logfile: " + e);
  51. e.printStackTrace();
  52. }
  53. finally
  54. {
  55. try
  56. {
  57. save.close();
  58. }
  59. catch (Exception e)
  60. {
  61. }
  62. }
  63. }
  64. public static final void Assert(boolean exp, String cmt)
  65. {
  66. if (exp)
  67. return;
  68. _log.warning("Assertion error [" + cmt + "]");
  69. Thread.dumpStack();
  70. }
  71. }