简体   繁体   English

如何在 email 的正文中发送日志

[英]How to send the log in the body of an email

I have this code I put together, but I didn't know how to send the log in the body of the email.我把这段代码放在一起,但我不知道如何在 email 的正文中发送日志。 So instead, I just put console.log.所以相反,我只放了console.log。 This is all that I did:这就是我所做的一切:

 function myFunction() {

 console.log('log1')
 console.log('log2')
 console.log('log3')


var recipent = 'ar07832@students.leeschools.net';
var heading = 'Heading';
var body = console.log;
MailApp.sendEmail(recipent, heading, body);
}

Try this:尝试这个:

 function myFunction() {
   Logger.log('log1')
   Logger.log('log2')
   Logger.log('log3')
   var recipent = "your email";
   var heading = 'Heading';
   var body = Logger.getLog();
   MailApp.sendEmail(recipent, heading, body);
}

You can try to bind the console.log function and change its behavior.您可以尝试绑定console.log function 并更改其行为。 Then, you can read your saved logs to send it somewhere else.然后,您可以阅读保存的日志以将其发送到其他地方。

Please note that using an array is just a suggestion, not a rule.请注意,使用数组只是一个建议,而不是规则。

// Bind the original function.
console.normalLog = console.log.bind(console);

// Create an empty array of logs.
console.savedLogs = [];

// Create the new logging function.
console.log = function(){
    // Save each log in the array.
    console.savedLogs.push(Array.from(arguments));

    // Execute the normal logging function.
    console.normalLog.apply(console, arguments);
}

// Logging...
console.log('test 1');
console.log('test 2');

// Checking the saved logs.
console.normalLog(console.savedLogs);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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