2 Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
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.
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.
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
18 package com.mysql.clusterj.core.util;
20 import java.util.HashMap;
22 import java.util.logging.LogManager;
24 public class JDK14LoggerFactoryImpl implements LoggerFactory {
26 /** The root logger name */
27 public static final String CLUSTERJ_LOGGER = "com.mysql.clusterj.core";
29 /** The metadata logger name */
30 public static final String CLUSTERJ_METADATA_LOGGER = "com.mysql.clusterj.core.metadata";
32 /** The util logger name */
33 public static final String CLUSTERJ_UTIL_LOGGER = "com.mysql.clusterj.core.util";
35 /** The query logger name */
36 public static final String CLUSTERJ_QUERY_LOGGER = "com.mysql.clusterj.core.query";
38 /** The global JDK14 LogManager */
39 static final LogManager logManager = LogManager.getLogManager();
41 /** The loggers in a map */
42 static final Map<String, Logger> loggerMap = new HashMap<String, Logger>();
44 /** The constructor */
45 public JDK14LoggerFactoryImpl() {
46 // configureJDK14Logger();
47 // create all the known loggers for the core project
48 registerLogger(CLUSTERJ_LOGGER);
49 registerLogger(CLUSTERJ_METADATA_LOGGER);
50 registerLogger(CLUSTERJ_QUERY_LOGGER);
51 registerLogger(CLUSTERJ_UTIL_LOGGER);
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);
61 @SuppressWarnings("unchecked")
62 public Logger getInstance(Class cls) {
63 String loggerName = getPackageName(cls);
64 return getInstance(loggerName);
67 public synchronized Logger getInstance(String loggerName) {
68 Logger result = loggerMap.get(loggerName);
70 result = registerLogger(loggerName);
76 * Returns the package portion of the specified class.
77 * @param cls the class from which to extract the
79 * @return package portion of the specified class
81 final private static String getPackageName(Class<?> cls)
83 String className = cls.getName();
84 int index = className.lastIndexOf('.');
85 return ((index != -1) ? className.substring(0, index) : ""); // NOI18N