简体   繁体   中英

Logger is not defined, Google Apps Script

I'm sure I'm doing something incredibly stupid here, but I have a very simple function which is supposed to be called when button is clicked in my HTML form created through google apps script. Function is just as follows:

$("#click").click(function(){
Logger.log("Clicked");
})

But when I click it, nothing is logged and my console shows the error "userCodeAppPanel:39 Uncaught ReferenceError: Logger is not defined"... can't work out where I'm going wrong!

Logger is available only in google apps script .gs file environment and not in javascript environment.

So if you want to log in javascript then you can use console.log(message)

If you're adamant or want to log into google apps script logs then you can create a function like this and make logs by passing message to that

// In .gs file
function make_log(message) {
    Logger.log(message)
}

// In frontend/html/js code
$("#click").click(function(){
    google.script.run.make_log("Clicked");
});

You should log via Console Object console.log("My log");

$("#click").click(function(){
    console.log("Clicked");
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM