1 /**
2 * Copyright (c) 2004-2021 QOS.ch
3 * All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 */
25 package org.slf4j.jdk.platform.logging;
26
27 /**
28 * Uses {@link SLF4JPlarformLoggerFactory#getLogger(String)} to get a logger
29 * that is adapted for {@link System.Logger}.
30 *
31 * @since 2.0.0
32 */
33 public class SLF4JSystemLoggerFinder extends System.LoggerFinder {
34
35 final SLF4JPlarformLoggerFactory platformLoggerFactory = new SLF4JPlarformLoggerFactory();
36
37 @Override
38 public System.Logger getLogger(String name, Module module) {
39 // JEP 264[1], which introduced the Platform Logging API,
40 // contains the following note:
41 //
42 // > An implementation of the LoggerFinder service should make it
43 // > possible to distinguish system loggers (used by system classes
44 // > from the Bootstrap Class Loader (BCL)) and application loggers
45 // > (created by an application for its own usage). This distinction
46 // > is important for platform security. The creator of a logger can
47 // > pass the class or module for which the logger is created to the
48 // > LoggerFinder so that the LoggerFinder can figure out which kind
49 // > of logger to return.
50 //
51 // If backends support this distinction and once `LoggerFactory`'s API
52 // is updated to forward a module, we should do that here.
53 //
54 // [1] https://openjdk.java.net/jeps/264
55 SLF4JPlatformLogger adapter = platformLoggerFactory.getLogger(name);
56 return adapter;
57 }
58
59 }