View Javadoc
1   /*
2    * This file is part of dependency-check-ant.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   * Copyright (c) 2015 The OWASP Foundation. All Rights Reserved.
17   */
18  package org.owasp.dependencycheck.ant.logging;
19  
20  import org.slf4j.ILoggerFactory;
21  import org.slf4j.IMarkerFactory;
22  import org.slf4j.helpers.BasicMarkerFactory;
23  import org.slf4j.helpers.NOPMDCAdapter;
24  import org.slf4j.spi.MDCAdapter;
25  import org.slf4j.spi.SLF4JServiceProvider;
26  
27  /**
28   * SLF4J 2.0 service provider for the dependency-check Ant integration.
29   * Replaces the old StaticLoggerBinder mechanism used in SLF4J 1.x.
30   */
31  public class AntSlf4jServiceProvider implements SLF4JServiceProvider {
32  
33      /**
34       * Declare the version of the SLF4J API this implementation is compiled
35       * against.
36       */
37      private static final String REQUESTED_API_VERSION = "2.0";
38  
39      private ILoggerFactory loggerFactory;
40      private IMarkerFactory markerFactory;
41      private MDCAdapter mdcAdapter;
42  
43      @Override
44      public ILoggerFactory getLoggerFactory() {
45          return loggerFactory;
46      }
47  
48      @Override
49      public IMarkerFactory getMarkerFactory() {
50          return markerFactory;
51      }
52  
53      @Override
54      public MDCAdapter getMDCAdapter() {
55          return mdcAdapter;
56      }
57  
58      @Override
59      public String getRequestedApiVersion() {
60          return REQUESTED_API_VERSION;
61      }
62  
63      @Override
64      public void initialize() {
65          loggerFactory = new AntLoggerFactory();
66          markerFactory = new BasicMarkerFactory();
67          mdcAdapter = new NOPMDCAdapter();
68      }
69  }