View Javadoc
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  import com.avaje.ebeaninternal.server.transaction.log.SimpleLogger;
54  
55  /**
56   * An implementation of {@link ILoggerFactory} which always returns
57   * {@link SimpleLogger} instances.
58   *
59   * @author Ceki G&uuml;lc&uuml;
60   * @author Ronald Jack Jenkins Jr.
61   */
62  public class BukkitPluginLoggerFactory implements ILoggerFactory {
63  
64    ConcurrentMap<String, Logger> loggerMap;
65  
66    public BukkitPluginLoggerFactory() {
67      this.loggerMap = new ConcurrentHashMap<String, Logger>();
68      // ensure jul initialization. see also SLF4J-359
69      java.util.logging.LogManager.getLogManager();
70    }
71  
72    /**
73     * Return an appropriate {@link BukkitPluginLoggerAdapter} instance by name.
74     */
75    @Override
76    public Logger getLogger(final String name) {
77      final Logger bukkitLogger = this.loggerMap.get(name);
78      if (bukkitLogger != null) {
79        return bukkitLogger;
80      } else {
81        final Logger newInstance = new BukkitPluginLoggerAdapter(name);
82        final Logger oldInstance = this.loggerMap.putIfAbsent(name, newInstance);
83        return oldInstance == null ? newInstance : oldInstance;
84      }
85    }
86  
87  }