Skip to content

Commit

Permalink
Add support for SLF4J discovery via service loader (fixes tinylog-org…
Browse files Browse the repository at this point in the history
  • Loading branch information
f4lco committed Apr 7, 2021
1 parent 506bf90 commit bfef236
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<mockk.version>1.11.0</mockk.version>
<powermock.version>2.0.9</powermock.version>
<scala.version>2.12.13</scala.version>
<slf4j.version>1.7.30</slf4j.version>
<slf4j.version>1.8.0-beta4</slf4j.version>

</properties>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2018 Martin Winandy
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package org.tinylog.slf4j;

import org.slf4j.ILoggerFactory;
import org.slf4j.IMarkerFactory;
import org.slf4j.helpers.BasicMarkerFactory;
import org.slf4j.spi.MDCAdapter;
import org.slf4j.spi.SLF4JServiceProvider;

/**
* SPI implementation for SLF4j 1.8+. Replacement mechanism for {@link org.slf4j.impl.StaticLoggerBinder}.
*/
public class TinylogSlf4jServiceProvider implements SLF4JServiceProvider {

/**
* SLF4J API 1.8 and newer is supported.
*/
public static final String REQUESTED_API_VERSION = "1.8";

private ILoggerFactory loggerFactory;
private IMarkerFactory markerFactory;
private MDCAdapter mdcAdapter;

/** */
public TinylogSlf4jServiceProvider() {
}

@Override
public ILoggerFactory getLoggerFactory() {
return loggerFactory;
}

@Override
public IMarkerFactory getMarkerFactory() {
return markerFactory;
}

@Override
public MDCAdapter getMDCAdapter() {
return mdcAdapter;
}

@Override
public String getRequesteApiVersion() {
return REQUESTED_API_VERSION;
}

@Override
public void initialize() {
loggerFactory = new TinylogLoggerFactory();
markerFactory = new BasicMarkerFactory();
mdcAdapter = new TinylogMdcAdapter();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.tinylog.slf4j.TinylogSlf4jServiceProvider

0 comments on commit bfef236

Please sign in to comment.