-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sketchup Ruby Console output to file #296
Comments
Have you tried to also redirect stderr? |
stderr do not get the „ERROR MESSAGE“ |
What error message are you referring to? |
Here is an Example. # ruby test start
testPath = "c:/temp"
outFile = File.new("#{testPath}/stdout.log", "w+")
errFile = File.new("#{testPath}/stderr.log", "w+")
outOrg = $stdout
errOrg = $stderr
$stdout = outFile
$stderr = errFile
begin
puts "Hello"
raise ArgumentError,"Test ERROR"
ensure
$stdout = outOrg
$stderr = errOrg
outFile.close
errFile.close
end
# ruby test end |
I tried this in standalone Ruby and it doesn't work there either. If you want to catch errors form your extension you could try something similar to how I collect errors for mine: https://github.com/thomthom/true-bend/blob/master/src/tt_truebend/command.rb I add an exception handler in a custom |
What IDE are you using? And why do you need to output errors to file when using an ide for debugging? The IDE should be able to let you inspect errors. |
I use Netbeans. To get the Error messages to the file I use TracePoint but it do not get all ERROR yet. Now I get nearly all output to Netbeans. The advantage is: It would we better and faster if I get the Error Message directly. |
orig_out = $stdout.dup
orig_err = $stderr.dup
path = ENV['TMPDIR'] || ENV['TEMPDIR']
File.open("#{path}/stdout.log", mode: 'w+') { |f| $stdout.reopen f }
File.open("#{path}/stderr.log", mode: 'w+') { |f| $stderr.reopen f }
puts 'Hello from puts'
warn 'Hello from warn'
$stdout = orig_out
$stderr = orig_err
puts 'stdout works'
warn 'stderr works'``` |
Hello MSP-Greg |
@SoapSkinBubble My bad. Sorry. I saw the mention of stand-alone Ruby, made a few changes, and kind of forgot that |
Just for reference, I asked how to send STDIO to an IDE in forum post ... ... but most discussion was in a thread of the SU Debugger GitHub project ... |
@SoapSkinBubble Again, sorry for the previous post. Try the following: # frozen_string_literal: true
$orig_out, $stdout = $stdout, STDOUT.dup
$orig_err, $stderr = $stderr, STDERR.dup
path = ENV['TMPDIR'] || ENV['TEMPDIR']
File.open("#{path}/stdout.log", mode: 'w+') { |f| $stdout.reopen f }
File.open("#{path}/stderr.log", mode: 'w+') { |f| $stderr.reopen f }
puts "[#{Time.now}] Hello from puts"
warn "[#{Time.now}] Hello from warn"
$stdout.close
$stderr.close
$stdout = $orig_out
$stderr = $orig_err
puts 'Restore SU Ruby console: stdout works'
warn 'Restore SU Ruby console: stderr works' |
@MSP-Greg |
@SoapSkinBubble I posted something in the forum with an attached file. See: https://forums.sketchup.com/t/redirect-ruby-console-to-file-s-example/99790 I required it in a plugin and set Normally when I load the plugin, a bunch of warnings ('warning: File.exists? is a deprecated name') appear in the console. With the This seems to show that stderr is routed to a file, at least for loaded Ruby code. I did notice that if you use the Ruby console and enter something that generates an error, it appears in the Ruby console... Not sure about that... |
I think some of the API exception code writes to $stdout and not $stderr (if memory serves. It seems this has been a complaint in the past.) |
Since my code never has errors, I just used the warnings that appear in the Ruby console on SU start. Ok, just kidding.
Could be. Kind of odd, because the standard Ruby C calls are build with errors going to stderr. Then again, some of the API c code could be quite old... But, what I meant above is that if one uses the code to route both stdout & stderr to file(s), and then types some nonsense into the console like But, I did that, then triggered something in my plugin UI that writes with |
The SketchUp Ruby Console has always been weird. I've always wanted to replace it with a better one. |
Some output in the Ruby Console might be printed directly instead of via stdout or stderr. |
It would be very good if the entire output goes over stdout and stderr. |
@thomthom Can we get this issue changed to a bug, as ALL output should go through |
Logged as: SU-47093 |
Thank you. |
For connecting an IDE with Sketchup it would be help full
to get all output from the Ruby Console into a file.
If I redirect “stdout” to a File, I do not get the “ERROR MESSAGES”
Example: (missing ERROR MESSAGES)
Example: (new feature)
Switch on
Switch off
The text was updated successfully, but these errors were encountered: