[Plugin] Trace Ruby messages
-
I have created a ruby script which overrides the Ruby Console, and writes its messages to a file, and flushes each message as itr is written.
If you ever have a problem where ruby files are not loading properly when you start SketchUp, this may help you debug them.
Place this ruby script in the plugins folder, and it should create a file called c:\tmp\ruby_trace.txt which contains all of the messages which are sent to the Ruby Console (whether the Ruby Console is open or not).
Sample Output
C:\tmp>type ruby_trace.txt
Fri Sep 24 00:51:28 -0600 2010
SketchUp Version: 8.0.3117Console messages are going to c:\tmp\ruby_trace.txt
If you want to trace ruby files as they are loaded, you could place this line at the top of each .rb file, which does not already print its file name.
printf("***** Loading; %s\n",__FILE__)
[EDIT: Revised script for mkdir error]
[EDIT: 5/1/2011 - added timestamp for messages]
[Edit: 5/4/2001 - added machine independent code for file location]Latest Version 5/4/2011: !trace_console.rb
(I want to apologize in advance for posting the same script to two SCF forums )
-
Thanks
PS: Error a line 25 Dir.mkdirsdir >>> Dir.mkdir sdir
-
@sahi said:
:thumb: Thanks
PS: Error a line 25 Dir.mkdirsdir >>> Dir.mkdir sdirIt's even better as
Dir.mkdir(sdir)
- then you don't those kind of typo make mistakes...
It's also the future-proof coding method - the 'without-parenthesis' method might be deprecated soon... -
@sahi said:
:thumb: Thanks
PS: Error a line 25 Dir.mkdirsdir >>> Dir.mkdir sdir
AArrggh:
Thanks sahi and thanks TIG
-
@tig said:
()
It's also the future-proof coding method - the 'without-parenthesis' method might be deprecated soon...Thanks TIG.
-
Sometimes it is necessary to compare as was and as became
It is possible to add here such codeffile1 = "c;\\tmp\\1_ruby_trace.txt" if(File;;exists?(@sfile)) if (File;;exists?(ffile1)) File.delete(ffile1) end File.rename(@sfile, ffile1) end #if ffile
-
Al,
You should make your code portable on Windows and Mac
tmpdir = (RUBY_PLATFORM =~ /darwin/i) ? "/tmp" ; ENV["TEMP"] @sfile = File.join tmpdir, "Trace_Ruby.tmp"
This also avoids calling
mkdir
(since the tmp directories always exists)Fredo
-
I'll make the change.
The only thing I hate is that it is often difficult to find the real temp folder on Windows,
Typing in %TEMP% in Windows Explorer will find it, but I don't know if everyone knows that.
@unknownuser said:
Al,
You should make your code portable on Windows and Mac
> tmpdir = (RUBY_PLATFORM =~ /darwin/i) ? "/tmp" ; ENV["TEMP"] > @sfile = File.join tmpdir, "Trace_Ruby.tmp" >
This also avoids calling
mkdir
(since the tmp directories always exists)Fredo
-
@unknownuser said:
Your script is working great for me! Just that timestamp needs to be logged with each console message.
I made a version with an optional parameter which will show the date and time for each message.
The new version is in the initial post for this thread.
# comment one of these out to add time to traces @show_time = true #@show_time = false
Here is output with timestamp:
Console messages from: !trace_console.rb
Sun May 01 23:14:29 2011
SketchUp Version: 8.0.4811
Sun May 01 23:14:29 2011: -----
Sun May 01 23:14:29 2011:
Sun May 01 23:14:29 2011: Console messages are going to c:\tmp\ruby_trace.txt
Sun May 01 23:14:29 2011:
Sun May 01 23:14:29 2011: ----- -
Hi Al,
I've been using this on a mac since you first posted it.
It took a day to find the .tmp file even though I always have hidden 'off' by default.
so I named your script auditMac.rb, made a plugins/folder put an empty text file in it like so.
@sfile = "/Library/Application\ Support/Google\ SketchUp\ 8/SketchUp/plugins/audit_mac_ruby/audit.txt "
it works great I drop auditMac.rb in the folder when I'm not having problems and put it out when needed.
your script just updates from the previous, so I just pull of copies if I need a log. I also park suspect rubies in the folder if I'm trouble shooting...
easy to find and use
john
-
Finding a suitable 'temp' folder location is easy...
tdir=ENV["TEMP"] tdir=ENV["TMPDIR"]if not tdir ### it's a Mac ?
So 'tdir' is the path to the 'temp; directory for that user...To make the full path to a temporary file use...
tfile=File.join(tdir, tfilename)
-
Very nice workin indeed Al. I'm still having issues re-directing error output to the log file. It seems as though Sketchup does not use stderr for error output. I've had some success just trapping messages in the Excpetion class StandardError but this is clumsy.
-
Hi,
I'm using latest version (from may 2011) and noticed strange problem.
When I have plugin wxSU installed and !trace_console.rb, while Sketchup is running - no problems, and CPU usage is as expected.
When I try to exit Sketchup,SU window is closed but Sketchup.exe process is not finished, and it uses maximal CPU load (when checked in TaskManager).
##########If only one of these 2 plugins wxSU and !trace_console.rb is installed Sketchup process is ended without problems.
It seems that writing to text file is blocked for some reason, and trace file can't be closed.
I'm using SU 7.1 and 8, on Windows 7.
Marija
Advertisement