Changes to console.log behaviour in SDK 1.14

8

One change in SDK 1.14 that has already surprised some people in the community is a change in the visibility of messages printed from console.log.

In 1.14 we added some additional features to the console API and also set the default log level to “error” instead of “info” for add-ons installed into Firefox via the Add-on Manager and Add-on Builder Helper as well as tools like the Extension Auto-installer.

An unfortunate side-effect is that by default, developers using these tools will no longer see messages from console.log() in the jsconsole window.

We have provided the ability for developers to set preferences to control logging behavior both globally and for a specific add-on, and by setting one of these preferences you can override the default.

Logging levels

The console module now defines a range of logging levels:

  1. all: log calls to any console method
  2. debug: log calls to debug(), log(), info(), warn(), error()
  3. info: log calls to log(), info(), warn(), error()
  4. warn: log calls to warn() and error()
  5. error: log calls to error()
  6. off: log nothing

New Preferences

We have defined two new preferences, which set the logging level either globally for all SDK add-ons, or for a specific SDK add-on:

extensions.sdk.console.logLevel: this preference can be added to about:config to change the logging level of all installed SDK-based add-ons.

extensions.[extension-id].sdk.console.logLevel: this preference can be added to about:config to change the logging level of a specific add-on. This preference overrides the global preference.

The value for each preference is the desired logging level, given as a string. If neither preference is set, the logging level defaults to “error”.

Restoring the old behavior

If you want to restore the previous behavior in which console.log messages are visible in the error log, please do the following:

  1. open about:config
  2. right-click and select New -> String
  3. for the preference name, enter ‘extensions.sdk.console.logLevel’
  4. for the preference value, enter ‘all’
  5. restart Firefox

Here is a screenshot of what the result should look like:

about_config

Categories: builder, developers, general, jetpack, sdk

8 responses

  1. backy0175

    I create a little library to set logging level for a specific SDK add-on.

    logLevel
    https://builder.addons.mozilla.org/package/180387/latest/

  2. Alexufo

    oooww… 3:30 am now i understand why console.log not working… omg.. sleep now..

    1. Jeff Griffiths Author

      Ouch! I’m really sorry you lost sleep over this. :(

  3. Jonas

    Just a heads up so others dont waste time like i did (not much but still)

    Whenever you run ‘cfx run -p <path/to/your/profile/' , extensions.sdk.console.logLevel will be set to info, overwriting any changes you may have made.

  4. Chris

    I’m just wondering, several hours can’t figure out how to enable console.log into an extension content script? Firefox 22; SDK 1.4; extensions.sdk.console.logLevel set to true,
    but nothing happens.

    P.S How developers can develop great extensions (like on Chrome) for Firefox without console support?
    Why they should configure Firefox and about:config several hours to start porting an extension?
    Today’s this is just abnormal situation.

    1. Jeff Griffiths Author

      As discussed in the blog post above, you need to set ‘extensions.sdk.console.logLevel’ to ‘all’ or ‘info’ to see console.log messages.

  5. James Schend

    I added “extensions.sdk.console.logLevel”, and set the value to “all”, but I still can’t see console.log() messages from content scripts in the extension I’m working on. (Strangely, I also can’t see console.error() messages.) I followed your instructions, including restarting Firefox, and it is version 22. I’m stumped.

    Additionally, I’m noticing that inserting “debugger;” calls in the content script doesn’t seem to bring up the debugger– how the heck are you supposed to debug content scripts?

    1. Jugurtha Hadjar

      What is driving me nuts is that it’s not consistent: I wish it didn’t work all the way.

      It didn’t work, then I made it work for few days, and now it doesn’t anymore. I didn’t change the code (I was busy with other stuff). I’m a beginner (writing add-ons and JavaScript) and I’ll have not to rely on this.

      But.. The Add-on Builder is *great* and I’m happy to use it.