truffleruby icon indicating copy to clipboard operation
truffleruby copied to clipboard

Support less verbosity via the default output

Open rubyFeedback opened this issue 3 years ago • 1 comments

Hey there eregon and others.

A new GraalVM release is out and I wanted to test it.

This is the copy/paste example I used:

import org.graalvm.polyglot.*;

class Embedding {
    public static void main(String[] args) {
        Context polyglot = Context.newBuilder().allowAllAccess(true).build();
        Value array = polyglot.eval("ruby", "[1,2,42,4]");
        int result = array.getArrayElement(2).asInt();
        System.out.println(result);
    }
}

I compiled it e. g. via:

native-image --language:ruby Embedding

When I then run it via ./embedding, I get this result:

[To redirect Truffle log output to a file use one of the following options:

* '--log.file=<path>' if the option is passed using a guest language launcher.

* '-Dpolyglot.log.file=<path>' if the option is passed using the host Java launcher.

* Configure logging using the polyglot embedding API.]

[ruby] WARNING: could not determine TruffleRuby's home - the standard library will not be available - use --log.level=CONFIG to see details

[ruby] WARNING: could not determine TruffleRuby's home - the standard library will not be available - use --log.level=CONFIG to see details

[ruby] WARNING: could not determine TruffleRuby's home - the standard library will not be available - use --log.level=CONFIG to see details

42

I added extra newlines to make it easier to see.

It prints 42, which is correct - no problem here.

But the rest is a bit noisy.

I'd like to be able to suppress ALL the output, e. g. ONLY get back what ruby would tell me.

The warnings above can be useful, no doubt, but I'd like something like --silent or if it is another flag, use that. So my proposal here is to either be less verbose (but this may not be wanted, I get it), or perhaps even better, IF the above is shown, to also tell the user or dev at hand how to change it. That is how to silence the above output and suppress it, all except for the "42" or whatever else is output from the ruby side here.

I'd love to be told right on the commandline how I can silence all the output, e. g. from

* Configure logging using the polyglot embedding API.

to

* Configure logging using the polyglot embedding API. Use --quiet to suppress this output.

Or wherever it makes sense. That's just a suggestion, can be worded differently of course..

^^^^ or something like that, if you get what I mean

I'd like to test some of my larger ruby scripts soon, to see how well polyglot works, and perhaps even use graalvm-truffleruby to replace my jruby use cases (though I may have to find some way to work via a GUI too, in particular on windows; on linux things all work so much better...)

rubyFeedback avatar Apr 27 '22 13:04 rubyFeedback

You can use --log.level=OFF, that will effectively suppress the output.

The warning is there for a reason, it means none of the standard library is available, no RubyGems, nothing. So that probably cannot run anything except trivial examples. What you need in practice for embedding in a native image is to tell it where is the truffleruby home, using --vm.Dorg.graalvm.language.ruby.home=... or --vm.Dorg.graalvm.home=..., or using System.setProperty() before using the Context API. You can also set the path at image build time via -Dorg.graalvm.launcher.home=... or -Dorg.graalvm.launcher.relative.home (relative path from the produced native image to the GraalVM home).

If you run the example on GraalVM JVM then you don't need this because, it already knows where the GraalVM is.

eregon avatar Apr 27 '22 13:04 eregon