Skip to content

Commit

Permalink
Add Slf4j2 Module
Browse files Browse the repository at this point in the history
This implements the new SLF4JServiceProvider interface, and registers it with a ServiceLoader, as explained here: https://www.slf4j.org/faq.html#changesInVersion200

It depends on the old module and exposes the new interface, and will be picked up first when running on SLF4J versions 2 and above.
  • Loading branch information
andimiller committed Jul 5, 2024
1 parent 5076f09 commit ae2cbbb
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ In benchmarks, the bridge performs as well as [Log4Cats] with a [Logback] backen
"com.permutive" %% "odin-slf4j-bridge" "<VERSION>"
```

## [`odin-slf4j2-bridge`]

A bridge between [Odin] and [Slf4j] versions 2 and above, allowing the dynamic [Odin] logger to be used by default for [Slf4j] log messages.

[`odin-testing`]: odin-testing
[`log4cats-odin`]: log4cats-odin
[`odin-dynamic`]: odin-dynamic
Expand Down
4 changes: 4 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ lazy val `odin-slf4j-bridge` = module
.settings(libraryDependencies += "com.github.valskalla" %% "odin-core" % "0.13.0")
.settings(libraryDependencies += "org.slf4j" % "slf4j-api" % "1.7.36")

lazy val `odin-slf4j2-bridge` = module
.dependsOn(`odin-slf4j-bridge`)
.settings(libraryDependencies += "org.slf4j" % "slf4j-api" % "2.0.13")

lazy val `odin-slf4j-bridge-benchmarks` = module
.enablePlugins(JmhPlugin)
.dependsOn(`odin-slf4j-bridge`)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2022-2024 Permutive Ltd. <https://permutive.com>
*
* 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.slf4j.impl;

import com.permutive.logging.slf4j.odin.LoggerFactory;
import org.slf4j.ILoggerFactory;
import org.slf4j.IMarkerFactory;
import org.slf4j.helpers.BasicMDCAdapter;
import org.slf4j.spi.MDCAdapter;
import org.slf4j.spi.SLF4JServiceProvider;


public class OdinBridge implements SLF4JServiceProvider {

@Override
public ILoggerFactory getLoggerFactory() {
return new LoggerFactory();
}

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

@Override
public MDCAdapter getMDCAdapter() {
return new BasicMDCAdapter();
}

@Override
public String getRequestedApiVersion() {
return "2.0";
}

@Override
public void initialize() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.slf4j.impl.OdinBridge

0 comments on commit ae2cbbb

Please sign in to comment.