【发布时间】:2013-04-12 13:24:21
【问题描述】:
Logger.log() 和 Utility.formatString() 等一些 Google Apps 脚本函数接受无限参数。
我想包装对 Logger.log() 或 Utility.formatString() 的调用,以便在最里面的函数调用中,我可以在结果字符串前面加上时间戳和我自己的文本。通常你只需 .apply 当前模块的 ags 到函数,但在我的测试中,这不能按预期工作。它会导致错误 TypeError: Cannot find default value for object. (line 14, file "Code") 其中 looks 来自 java/server 端。
这是我用于测试的代码。问题:
- 这是这些 Apps 脚本方法中的错误吗?
- 是否有解决方法或替代方法来实现我的目标?
如果是错误,我也会将其提交到问题跟踪器跟踪器中
function testMyLogger() {
myLogger('Testing %s %s %s', 'one', 2, 'three');
}
function myLogger() {
// do common things like prefix a timestamp to the first arg
var logdate = Utilities.formatDate(new Date(), Session.getTimeZone(), "yyyy-MM-dd HH:mm:ss");
arguments[0]= logdate + " " + arguments[0];
Logger.log.apply(this, arguments);
// At the above line I get error "TypeError: Cannot find default value for object. (line 14, file "Code")"
// but I expected '<timestamp> Testing one 2.0 three' to the log (View > Logs...)
}
【问题讨论】:
标签: javascript google-apps-script rhino