Any way to remove logging statements from release builds?

Monkey C provides (:release) and (:debug) annotations; 

Monkey Jungle provides the `excludeAnnotations` mechanism;

One issue with annotation is that they work only on "higher" level code blocks like classes or functions.

Those do not work on a simple lexical block in the form:

(:debug) {
   log("this will not show in release build");
}

which will generate some error about a missing ";" (*)

Also, even at class or function level those annotations do not stack.

I.e. there is no way to write:

(:debug)
(:background)
function debug(string) {
  System.println(string);
}

which makes annotation not very useful for code that runs in the main app and in the background project.

Any suggestions for a preprocessing / compile time code processing functionality?

(*) en.wikipedia.org/.../Syntactic_sugar

Top Replies

  • One issue with annotation is that they work only on "higher" level code blocks like classes or functions.

    I agree that this is an issue if you want to save as much memory as possible…

All Replies

  • One issue with annotation is that they work only on "higher" level code blocks like classes or functions.

    I agree that this is an issue if you want to save as much memory as possible (which I personally do, especially for data fields constrained to 16 KB or 32 KB of RAM), and/or if you want to have different versions of the same functions which only differ by a few lines, without doing refactoring which wastes memory (among other things).

    Also, even at class or function level those annotations do not stack.

    I.e. there is no way to write:

    (:debug)
    (:background)
    function debug(string) {
      System.println(string);
    }

    Actually you can write that. (I had the same thought as you until  set me straight.

    You write what you want ^ above as:
    (:debug :background)

    If you really want a conditional compilation system for Monkey C, I wrote my own janky system using the C-preprocessor and annotations. (But the difference is this lets you have multiple versions of your code, based on line-by-line #ifdefs.

    forums.garmin.com/.../solution-for-line-by-line-mc-conditional-compilation

  • I do this very old school.  If I add Sys.println() calls for use in the sim, I just comment them out when they are no longer needed (by commenting them out, they are easy to add back if needed)

    When you have Sys.println("variable="+var), by commenting it out, not only don't you log it, but you free up space by removing the text, where if you have myDebug("variable="+var)) and then use annotations for debug/release with myDebug, the string still takes space.  

    Plus, with just commenting stuff out, it's not an all or nothing situation, and you have a control over what you are seeing.