RxJava v1 and v2 hooks which enable SLF4J's MDC
propagation.
A fork of bmcstdio/rxjava-slf4j-mdc-hook.
If you're using RxJava 2:
RxJavaPlugins.setScheduleHandler(new MdcPropagatingOnScheduleFunction());
If you're using RxJava ≥ 1.1.7:
RxJavaHooks.setOnScheduleAction(new MdcPropagatingOnScheduleAction());
If you're using RxJava ≤ 1.1.6:
RxJavaPlugins.getInstance().registerSchedulersHook(new RxJavaSchedulersHook() {
@Override
public Action0 onSchedule(final Action0 action) {
return new MdcPropagatingAction(action);
}
});
Note:
Both RxJavaPlugins#getInstance()
and RxJavaSchedulersHook#onSchedule(Action0)
are deprecated since 1.1.7.
rxjava-slf4j-mdc-hook
is available from JCenter:
Gradle:
compile 'io.github.puzpuzpuz:rxjava-slf4j-mdc-hook:1.0.0'
Maven:
<dependency>
<groupId>io.github.puzpuzpuz</groupId>
<artifactId>rxjava-slf4j-mdc-hook</artifactId>
<version>1.0.0</version>
</dependency>
$ git clone https://github.com/puzpuzpuz/rxjava-slf4j-mdc-hook.git
$ cd rxjava-slf4j-mdc-hook
$ ./gradlew build
Copyright 2016-2018 brunomcustodio, puzpuzpuz
Licensed under the Apache License, Version 2.0 (the "License").