MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JDK14LoggerFactoryImpl.java
1 /*
2  Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 package com.mysql.clusterj.core.util;
19 
20 import java.util.HashMap;
21 import java.util.Map;
22 import java.util.logging.LogManager;
23 
24 public class JDK14LoggerFactoryImpl implements LoggerFactory {
25 
27  public static final String CLUSTERJ_LOGGER = "com.mysql.clusterj.core";
28 
30  public static final String CLUSTERJ_METADATA_LOGGER = "com.mysql.clusterj.core.metadata";
31 
33  public static final String CLUSTERJ_UTIL_LOGGER = "com.mysql.clusterj.core.util";
34 
36  public static final String CLUSTERJ_QUERY_LOGGER = "com.mysql.clusterj.core.query";
37 
39  static final LogManager logManager = LogManager.getLogManager();
40 
42  static final Map<String, Logger> loggerMap = new HashMap<String, Logger>();
43 
46  // configureJDK14Logger();
47  // create all the known loggers for the core project
52  }
53 
54  public Logger registerLogger(String loggerName) {
55  java.util.logging.Logger logger = java.util.logging.Logger.getLogger(loggerName);
56  Logger result = new JDK14LoggerImpl(logger);
57  loggerMap.put(loggerName, result);
58  return result;
59  }
60 
61  @SuppressWarnings("unchecked")
62  public Logger getInstance(Class cls) {
63  String loggerName = getPackageName(cls);
64  return getInstance(loggerName);
65  }
66 
67  public synchronized Logger getInstance(String loggerName) {
68  Logger result = loggerMap.get(loggerName);
69  if (result == null) {
70  result = registerLogger(loggerName);
71  }
72  return result;
73  }
74 
81  final private static String getPackageName(Class<?> cls)
82  {
83  String className = cls.getName();
84  int index = className.lastIndexOf('.');
85  return ((index != -1) ? className.substring(0, index) : ""); // NOI18N
86  }
87 
88 }