1 /*
2 * This entire file is sublicensed to you under GPLv3 or (at your option) any
3 * later version. The original copyright notice is retained below.
4 */
5 /*
6 * Portions of this file are
7 * Copyright (C) 2016 Ronald Jack Jenkins Jr.
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22 /**
23 * Copyright (c) 2004-2011 QOS.ch
24 * All rights reserved.
25 *
26 * Permission is hereby granted, free of charge, to any person obtaining
27 * a copy of this software and associated documentation files (the
28 * "Software"), to deal in the Software without restriction, including
29 * without limitation the rights to use, copy, modify, merge, publish,
30 * distribute, sublicense, and/or sell copies of the Software, and to
31 * permit persons to whom the Software is furnished to do so, subject to
32 * the following conditions:
33 *
34 * The above copyright notice and this permission notice shall be
35 * included in all copies or substantial portions of the Software.
36 *
37 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
38 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
39 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
40 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
41 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
42 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
43 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44 */
45 package org.slf4j.impl;
46
47 import java.util.concurrent.ConcurrentHashMap;
48 import java.util.concurrent.ConcurrentMap;
49
50 import org.slf4j.ILoggerFactory;
51 import org.slf4j.Logger;
52
53 /**
54 * An implementation of {@link ILoggerFactory} which always returns
55 * {@link BukkitLoggerAdapter} instances.
56 *
57 * @author Ceki Gülcü
58 * @author Ronald Jack Jenkins Jr.
59 */
60 public class BukkitLoggerFactory implements ILoggerFactory {
61
62 ConcurrentMap<String, Logger> loggerMap;
63
64 public BukkitLoggerFactory() {
65 this.loggerMap = new ConcurrentHashMap<String, Logger>();
66 // ensure jul initialization. see also SLF4J-359
67 java.util.logging.LogManager.getLogManager();
68 }
69
70 /**
71 * Return an appropriate {@link BukkitLoggerAdapter} instance by name.
72 */
73 @Override
74 public Logger getLogger(final String name) {
75 final Logger bukkitLogger = this.loggerMap.get(name);
76 if (bukkitLogger != null) {
77 return bukkitLogger;
78 } else {
79 final Logger newInstance = new BukkitLoggerAdapter(name);
80 final Logger oldInstance = this.loggerMap.putIfAbsent(name, newInstance);
81 return oldInstance == null ? newInstance : oldInstance;
82 }
83 }
84
85 }