Please mute debug info in release mode

Hi,
I received the following message from the extension reviewer.
"Approved, but please mute debug info in release mode. This submission added: p choice Please add debug information behind a switch you can enable for development, or disable it before release. "
Would you please let me know what should I do?
Thank you in advance.

Avoid using p or puts to print anything to the Ruby Console. If you need it for debugging, you can have a variable to control it, but by default the extension shouldn’t output to the console.

1 Like

Thank you so much.

module Majid
  module MyExtension

    extend self

    KEY ||= Module.nesting[0].name.gsub('::','_')

    @debug = Sketchup.read_default(KEY, 'debug', false)

    def debug(val)
      Sketchup.write_default(KEY, 'debug', val) if val != @debug
      @debug = val ? true : false
    end

    def some_method
      puts "In method #{__method__}" if @debug
    end

  end
end

Sometimes I use an “emit” method rather than directly using puts. Ie …

module Majid
  module MyExtension

    extend self

    KEY ||= Module.nesting[0].name.gsub('::','_')

    @debug = Sketchup.read_default(KEY, 'debug', false)

    def debug(val)
      Sketchup.write_default(KEY, 'debug', val) if val != @debug
      @debug = val ? true : false
    end

    def emit(str)
      puts(str) if @debug
    end

    def some_method
      emit "In method #{__method__}"
    end

  end
end

So now you can use your editor’s search and replace feature to change all “puts” to “emit”.

3 Likes

I would not connect extension debugging to SketchUp debugging. Someone may want to see the SketchUp warnings without having an unknown extension print its own noise. A separate value for just that extension is better.

3 Likes

+1 to what Christina said. SU debugging and extension debugging are separate things.

1 Like

The documentation does not really indicate that Sketchup::debug_mode= is “SketchUp debugging”.

It says vaguely “incorrect API usage” but does not explain what this means or how code could use the API incorrectly.

It is only an initial value.

In the examples above, it IS A SEPARATE VALUE and has a separate toggle method.

CLARIFICATION: In the above example, … the Sketchup::debug_mode? flag was only used to set the initial value of the example extension’s internal debug flag at load time.

The idea, (when I posted the example,) was that the Sketchup::debug_mode? flag could perhaps serve as a “master switch” to turn on extension debugging globally.

I did see the benefit in being able to control debugging messages specifically per extension. So this is why I showed the extension submodule with it’s own @debug flag and it’s own setter method to control it individually.

However, I also see that initially setting it to Sketchup::debug_mode? flag at each session start can override what the developer had set previously. This could make testing tedious.

So in the above examples, … I am replacing this statement …

    @debug =( Sketchup.debug_mode? rescue false ) if !defined(@debug)

… with this …

    @debug = Sketchup.read_default(Module.nesting[0].name, 'debug', false)

… which should set the extension submodule’s @debug to false upon first load.

Also inserting this line into the debug() method as the first statment …

Sketchup.write_default(Module.nesting[0].name, 'debug', val) if val != @debug

So then the extension would default to false for 1st load, thereafter use the memory setting.
And as @ene_su suggests, be separate from “API debugging” and all other extension testing.

1 Like