Difference between revisions of "GM log"

From GreaseSpot Wiki
Jump to navigationJump to search
(deprecation warning)
(Update for 4.0)
(One intermediate revision by one other user not shown)
Line 1: Line 1:
As of Greasemonkey 4.0, this method has been removed.  
You should use the [https://developer.mozilla.org/en-US/docs/Web/API/console.log console] instead.
<div style="border: 3px dotted; color: red; font-size: 1.2em; padding: 0.5em; margin: 1em; text-align: center">
'''This feature is deprecated.  Script authors are advised to use [https://developer.mozilla.org/en-US/docs/Web/API/console.log console logging] instead.'''
== Description ==
This method provides a very simple logging facility.
If you aren't seeing your messages, make sure you navigate to [[mozillazine:About:config|about:config]], and change the values of <code>javascript.options.showInConsole</code> and <code>javascript.options.strict</code> to true.
The output is displayed in the [https://developer.mozilla.org/en/Error_Console error console], and includes the namespace and name of the script before and the provided string value.
So, this script:
<pre class='sample'>
// ==UserScript==
// @name          GM_log Example
// @namespace    http://www.example.com/
// ==/UserScript==
GM_log("This is an example of GM_log");
Will produce a line in the error console like:
<nowiki>http://www.example.com/GM_log Example: This is an example of GM_log</nowiki>
Compatibility: [[Version_history#0.3_beta|Greasemonkey 0.3b+]]
== Syntax ==
=== Arguments ===
; <code>message</code>
: <code>String</code> (or any object with a <code>.toString()</code> method) The message to display in the console.
=== Returns ===
== Examples ==
<pre class='sample'>
GM_log("Hello, World!");
<pre class='sample'>
GM_log("Warning, " + someInputField.value + "!");
== GM_log and Firebug ==
Since [https://addons.mozilla.org/firefox/addon/1843 Firebug] 1.0, <code>extensions.firebug.showChromeMessages</code> must be set to <code>true</code> for GM_log messages to show up in the Firebug console.
It is also recommended to enable <code>extensions.firebug.showChromeErrors</code>, as doing so will reveal syntax errors and script breaks.
This can be done from <code>about:config</code>, or from the Firebug GUI. Go to the "Console" tab, then click the arrow next to the tab's name, and ensure that "Show Chrome Errors" and "Show Chrome Messages" are checked.
However, since <code>GM_log</code> will only display a single string at a time, users with Firebug installed may prefer to use <code>console.log</code> instead.

Latest revision as of 10:03, 3 November 2017

As of Greasemonkey 4.0, this method has been removed. You should use the console instead.