Skip to content

Allow JansiLoader to print issues to java Logger instead of System.err #307

@blaghed

Description

@blaghed

In the JansiLoader.java class, exceptions are pushed directly to System.err.
E.g.:

System.err.printf(
        "Failed to load native library:%s. osinfo: %s%n",
        libPath.getName(), OSInfo.getNativeLibFolderPathForCurrentOS());

My original issue is the same as reported on #297 -- file access is fine, this library just doesn't work well with static native images using musl.
At the very least, I would like to redirect the error to an appropriate log file instead of just having it blasted out on the console like this:

Failed to load native library:jansi-2.4.1-ce6b715db40c9640-libjansi.so. osinfo: Linux/x86_64
java.lang.UnsatisfiedLinkError: Can't load library: /tmp/jansi-2.4.1-ce6b715db40c9640-libjansi.so

For reference, the exact same thing happens with JLine, but at least there they output to Logger already, so I would like to ask that this class does the same, please:
https://github.com/jline/jline3/blob/jline-3.30.4/native/src/main/java/org/jline/nativ/JLineNativeLoader.java#L411-L415

log(
        Level.WARNING,
        "Failed to load native library:" + libPath.getName() + ". osinfo: "
                + OSInfo.getNativeLibFolderPathForCurrentOS(),
        e);

(...)
    private static void log(Level level, String message, Throwable t) {
        if (logger.isLoggable(level)) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(level, message, t);
            } else {
                logger.log(level, message + " (caused by: " + t + ", enable debug logging for stacktrace)");
            }
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions