Log.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. package com.l2jserver.util.lib;
  16. import java.io.File;
  17. import java.io.FileWriter;
  18. import java.io.IOException;
  19. import java.text.SimpleDateFormat;
  20. import java.util.Date;
  21. import java.util.logging.Level;
  22. import java.util.logging.Logger;
  23. import com.l2jserver.Config;
  24. /**
  25. * @version 0.1, 2005-06-06
  26. * @author Balancer
  27. */
  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. String date = (new SimpleDateFormat("yy.MM.dd H:mm:ss")).format(new Date());
  34. String curr = (new SimpleDateFormat("yyyy-MM-dd-")).format(new Date());
  35. new File("log/game").mkdirs();
  36. final File file = new File("log/game/" + (curr != null ? curr : "") + (cat != null ? cat : "unk") + ".txt");
  37. try (FileWriter save = new FileWriter(file, true))
  38. {
  39. save.write("[" + date + "] " + text + Config.EOL);
  40. }
  41. catch (IOException e)
  42. {
  43. _log.log(Level.WARNING, "Error saving logfile: ", e);
  44. }
  45. }
  46. }