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.slf4j.impl;
19
20 import org.apache.maven.plugin.logging.Log;
21 import org.owasp.dependencycheck.maven.slf4j.MavenLoggerFactory;
22 import org.slf4j.ILoggerFactory;
23 import org.slf4j.spi.LoggerFactoryBinder;
24
25 /**
26 * The binding of {@link org.slf4j.LoggerFactory} class with an actual instance of {@link ILoggerFactory} is performed using
27 * information returned by this class.
28 *
29 * @author colezlaw
30 */
31 public class StaticLoggerBinder implements LoggerFactoryBinder {
32
33 /**
34 * The unique instance of this class
35 */
36 private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
37
38 /**
39 * Return the singleton of this class.
40 *
41 * @return the StaticLoggerBinder singleton
42 */
43 public static final StaticLoggerBinder getSingleton() {
44 return SINGLETON;
45 }
46
47 /**
48 * Maven mojos have their own logger, so we'll use one of those
49 */
50 private Log log = null;
51
52 /**
53 * Set the Task which will this is to log through.
54 *
55 * @param log the task through which to log
56 */
57 public void setLog(Log log) {
58 this.log = log;
59 loggerFactory = new MavenLoggerFactory(log);
60 }
61
62 /**
63 * Declare the version of the SLF4J API this implementation is compiled against. The value of this filed is usually modified
64 * with each release.
65 */
66 // to avoid constant folding by the compiler, this field must *not* be final
67 public static String REQUESTED_API_VERSION = "1.7.12"; // final
68
69 /**
70 * The logger factory class string.
71 */
72 private static final String LOGGER_FACTORY_CLASS = MavenLoggerFactory.class.getName();
73
74 /**
75 * The ILoggerFactory instance returned by the {@link #getLoggerFactory} method should always be the same object
76 */
77 private ILoggerFactory loggerFactory;
78
79 /**
80 * Constructs the static logger factory.
81 */
82 private StaticLoggerBinder() {
83 loggerFactory = new MavenLoggerFactory(log);
84 }
85
86 /**
87 * Returns the logger factory.
88 *
89 * @return the logger factory
90 */
91 @Override
92 public ILoggerFactory getLoggerFactory() {
93 return loggerFactory;
94 }
95
96 /**
97 * Returns the logger factory class string.
98 *
99 * @return the logger factory class string
100 */
101 @Override
102 public String getLoggerFactoryClassStr() {
103 return LOGGER_FACTORY_CLASS;
104 }
105 }