View Javadoc
1   package net.sf.mbus4j.log;
2   
3   /*
4    * #%L
5    * mbus4j-core
6    * %%
7    * Copyright (C) 2009 - 2014 MBus4J
8    * %%
9    * mbus4j - Drivers for the M-Bus protocol - http://mbus4j.sourceforge.net/
10   * Copyright (C) 2009-2014, mbus4j.sf.net, and individual contributors as indicated
11   * by the @authors tag. See the copyright.txt in the distribution for a
12   * full listing of individual contributors.
13   * 
14   * This is free software; you can redistribute it and/or modify it
15   * under the terms of the GNU General Public License as
16   * published by the Free Software Foundation; either version 3 of
17   * the License, or (at your option) any later version.
18   * 
19   * This software is distributed in the hope that it will be useful,
20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22   * Lesser General Public License for more details.
23   * 
24   * You should have received a copy of the GNU Lesser General Public
25   * License along with this software; if not, write to the Free
26   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
28   * #L%
29   */
30  import java.io.IOException;
31  import java.util.logging.Level;
32  import java.util.logging.LogManager;
33  import java.util.logging.Logger;
34  
35  /**
36   *
37   * @author aploese
38   */
39  public class LogUtils {
40  
41      final static public String LOG_PREFIX = "net.sf.mbus4j.log";
42  
43      final static public Logger getCoreLogger() {
44          return Logger.getLogger(LOG_PREFIX + ".core.Core");
45      }
46  
47      final static public Logger getEncoderLogger() {
48          return Logger.getLogger(LOG_PREFIX + ".core.Encoder");
49      }
50  
51      final static public Logger getDecoderLogger() {
52          return Logger.getLogger(LOG_PREFIX + ".core.Decoder");
53      }
54  
55      public static Logger getMasterLogger() {
56          return Logger.getLogger(LOG_PREFIX + ".master.Master");
57      }
58  
59      public static Logger getSlaveLogger() {
60          return Logger.getLogger(LOG_PREFIX + ".slave.Slave");
61      }
62  
63      public static void initJulFromResource(String loggingproperties) {
64          try {
65              LogManager.getLogManager().readConfiguration(LogUtils.class.getClassLoader().getResourceAsStream(loggingproperties));
66          } catch (Exception e) {
67              Logger.getGlobal().log(Level.SEVERE, "Can't read new logger configuration", e);
68          }
69      }
70  
71      public static void initJul() {
72          try {
73              LogManager.getLogManager().readConfiguration();
74          } catch (Exception e) {
75              Logger.getGlobal().log(Level.SEVERE, "Can't read default logger configuration", e);
76          }
77      }
78  
79  }