-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewire python<->java logging to be generally friendlier to python
Fixes #2734
- Loading branch information
Showing
15 changed files
with
244 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
Integrations/src/main/java/io/deephaven/integrations/python/PyLogOutputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.deephaven.integrations.python; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jpy.PyObject; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Simple output stream that redirects all writes to a python io.TextIOBase type. | ||
*/ | ||
public class PyLogOutputStream extends OutputStream { | ||
private final Supplier<PyObject> rawIoBaseSupplier; | ||
|
||
public PyLogOutputStream(Supplier<PyObject> rawIoBaseSupplier) { | ||
this.rawIoBaseSupplier = rawIoBaseSupplier; | ||
} | ||
|
||
@Override | ||
public void write(int i) throws IOException { | ||
write(new byte[] {(byte) i}); | ||
} | ||
|
||
@Override | ||
public void write(@NotNull byte[] b) throws IOException { | ||
// noinspection PrimitiveArrayArgumentToVarargsMethod | ||
rawIoBaseSupplier.get().callMethod("write", new String(b)); | ||
} | ||
|
||
@Override | ||
public void write(@NotNull byte[] b, int off, int len) throws IOException { | ||
byte[] buffer = new byte[len]; | ||
System.arraycopy(b, off, buffer, 0, len); | ||
write(buffer); | ||
} | ||
|
||
@Override | ||
public void flush() throws IOException { | ||
rawIoBaseSupplier.get().callMethod("flush"); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
rawIoBaseSupplier.get().callMethod("close"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 0 additions & 66 deletions
66
Integrations/src/main/java/io/deephaven/integrations/python/PythonLogAdapter.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...ded-server/java-runtime/src/main/java/io/deephaven/python/server/EmbeddedPyLogModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.deephaven.python.server; | ||
|
||
import dagger.Module; | ||
import dagger.Provides; | ||
import dagger.multibindings.ElementsIntoSet; | ||
import io.deephaven.base.system.StandardStreamState; | ||
import io.deephaven.internal.log.InitSink; | ||
import io.deephaven.internal.log.LoggerFactory; | ||
import io.deephaven.io.log.LogSink; | ||
import io.deephaven.io.logger.LogBuffer; | ||
import io.deephaven.io.logger.LogBufferGlobal; | ||
import io.deephaven.server.log.LogModule; | ||
|
||
import javax.inject.Singleton; | ||
import java.util.Collections; | ||
import java.util.ServiceLoader; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
@Module | ||
public interface EmbeddedPyLogModule { | ||
|
||
@Provides | ||
static LogBuffer providesLogBuffer() { | ||
return LogBufferGlobal.getInstance().orElseThrow(() -> new RuntimeException("No global LogBuffer found")); | ||
} | ||
|
||
@Provides | ||
static LogSink providesLogSink() { | ||
// In contract, this should be a singleton - see LogInit#checkLogSinkIsSingleton() | ||
return LoggerFactory.getLogger(LogModule.class).getSink(); | ||
} | ||
|
||
@Provides | ||
@ElementsIntoSet | ||
static Set<InitSink> providesLoggerSinkSetups() { | ||
return StreamSupport | ||
.stream(ServiceLoader.load(InitSink.class).spliterator(), false) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
static StandardStreamState providesStandardStreamState() { | ||
return new StandardStreamState(Collections.emptySet()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.