Console.log VS Logger.log
To display information in the console of Google Sheets, you have 2 options, console.log and Logger.log.
These 2 possibilities may seem similar at first glance, however, that's not the case...
On this page, you'll discover why console.log is a much better choice.
Text
A first test with text:
function test() {
console.log('Sheets-Pratique');
Logger.log('Sheets-Pratique');
}
In this case, the result is identical:
Multiple values
A test with multiple values:
function test() {
console.log('console', 1, 2, 3, 4, 5);
Logger.log('Logger', 1, 2, 3, 4, 5);
}
You can see that console.log displays all values while Logger.log only displays the first one:
Numbers
A test with numbers:
function test() {
console.log(12);
console.log(12.34);
Logger.log(12);
Logger.log(12.34);
}
You can see that console.log displays the values correctly while Logger.log displays an unnecessary decimal for 12:
Objects
A test with objects:
function test() {
console.log([1, 2, 3, [4], {5: 6}]);
Logger.log([1, 2, 3, [4], {5: 6}]);
}
You can see that the display of data is not identical (not to mention the annoying unnecessary decimal in Logger.log):
JavaScript
A test with a custom dialog box:
function test() {
SpreadsheetApp.getUi().showModalDialog(HtmlService.createHtmlOutput(`<script>console.log(123);Logger.log(123);</script></body></html>`), 'Test ...');
}
Unsurprisingly, you can see in the browser console that console.log displays the value while Logger.log returns an error:
Whether it's a custom dialog box or a custom sidebar, the script contained in these elements is JavaScript, and only console.log can work in this case.
Console.warn and console.error
In addition, a test with different methods:
function test() {
console.log('Sheets-Pratique');
console.info('Sheets-Pratique');
console.warn('Sheets-Pratique');
console.error('Sheets-Pratique');
Logger.log('Sheets-Pratique');
}
You can see that console.warn and console.error display a message with a more critical color: