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.1KB

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