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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 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. import logger.MyFormatter.MyFormatter;
  14. /**
  15. *
  16. * @author nobody
  17. */
  18. public class OhmLogger
  19. {
  20. private static Logger lg = null;
  21. public static Logger getLogger()
  22. {
  23. if (lg == null)
  24. {
  25. lg = Logger.getLogger("OhmLogger");
  26. initLogger();
  27. }
  28. return lg;
  29. }
  30. private static void initLogger()
  31. {
  32. try
  33. {
  34. String datei = System.getProperty("java.io.tmpdir") + File.separator + "log.txt";
  35. FileHandler fh = new FileHandler(datei);
  36. ConsoleHandler ch = new ConsoleHandler();
  37. lg.setUseParentHandlers(false);
  38. lg.addHandler(fh);
  39. ch.setFormatter(new MyFormatter());
  40. lg.addHandler(ch);
  41. lg.setLevel(Level.ALL);
  42. }
  43. catch (IOException ioex)
  44. {
  45. System.err.println(ioex);
  46. }
  47. }
  48. public OhmLogger()
  49. {
  50. }
  51. }