Home > Java > Java custom logger

Java custom logger

JAVA:
  1. import java.util.logging.*;
  2.  
  3. public class MyLogger {
  4.  
  5. //1. CREATE logger
  6. //private static final Logger dnevnik = Logger.getLogger("bla");
  7.  
  8. //2. Init MyLogger
  9. //MyLogger.init();
  10.  
  11. //3. [Switch Off]
  12. //dnevnik.setLevel(Level.OFF);
  13.  
  14. //4. Usage
  15. //dnevnik.info("Vstop v metodo bla bla čšž fasf\n");
  16.  
  17. public static void init()
  18. {
  19. if(System.getProperty("java.util.logging.config.class") == null &&
  20. System.getProperty("java.util.logging.config.class") == null){
  21.  
  22. try {
  23. String currentDir = System.getProperty("user.dir");
  24. System.out.println("Logger Working Directory: " + currentDir);
  25.  
  26. Logger lg = Logger.getLogger("");
  27.  
  28. lg.setLevel(Level.ALL);
  29. FileHandler fh = new FileHandler(currentDir+"\\program%g.log", 0, 10);
  30. fh.setEncoding("UTF-8");
  31.  
  32. lg.addHandler(fh);
  33. } catch (Exception e) {
  34. System.out.printf("Nisem uspel vspostaviti dnevnika!\ne = %s",e);
  35. }
  36. }
  37. }
  38.  
  39. public static void main(String[] args) {
  40. init();
  41. }
  42. }

Categories: Java Tags: ,
  1. April 22nd, 2009 at 14:59 | #1

    You write very well.

  1. No trackbacks yet.

0 pages viewed, 0 today
0 visits, 0 today
FireStats icon Powered by FireStats