You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OhmLogger.java 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package chatprogramm.logger;
  7. import java.io.File;
  8. import java.io.IOException;
  9. import java.util.logging.ConsoleHandler;
  10. import java.util.logging.FileHandler;
  11. import java.util.logging.Level;
  12. import java.util.logging.Logger;
  13. /**
  14. *
  15. * @author nobody
  16. */
  17. public class OhmLogger
  18. {
  19. private static Logger instance;
  20. private OhmLogger()
  21. {
  22. }
  23. public static Logger getLogger()
  24. {
  25. if (instance == null)
  26. {
  27. instance = Logger.getLogger("OhmLogger");
  28. initLogger();
  29. }
  30. return instance;
  31. }
  32. private static void initLogger()
  33. {
  34. instance.setUseParentHandlers(false);
  35. try
  36. {
  37. String datei = System.getProperty("java.io.tmpdir") + File.separator + "log.csv";
  38. FileHandler fh = new FileHandler(datei);
  39. ConsoleHandler ch = new ConsoleHandler();
  40. instance.addHandler(fh);
  41. ch.setFormatter(new OhmLoggerFormatter());
  42. instance.addHandler(ch);
  43. instance.setLevel(Level.ALL);
  44. }
  45. catch(IOException ioex)
  46. {
  47. System.err.println(ioex);
  48. }
  49. }
  50. }