尽管我在网上找到了许多示例(语法不同),但我无法获取Logger.log(String format, Object.... values): Logger to format。 Google 的 Logger 官方文档声明它使用 Java 格式字符串语法进行字符串转换,但我的示例代码不同意。我疯了吗?
环境:
Linux (Fedora 17)
Chrome latest (v27.0.1453.110)
Google Apps Script (I assume this engine is server-side...)
$sudo yum install google-chrome-stable.x86_64
Loaded plugins: langpacks, presto, refresh-packagekit
Repository google-chrome is listed more than once in the configuration
Package google-chrome-stable-27.0.1453.110-202711.x86_64 already installed and latest version
Nothing to do
示例代码:
function testLogger() {
var state = "this";
Logger.log("Will %s work?", state.toString());
Logger.log("Will '%s' work?", state.toString());
Logger.log("Will [%s] work?", state.toString());
Logger.log('Will "%s" work?', state.toString());
Logger.log('Will %s work?', state.toString());
Logger.log('Will [%s] work?', state.toString());
Logger.log("Will %s work?", state);
Logger.log("Will '%s' work?", state);
Logger.log("Will [%s] work?", state);
Logger.log('Will "%s" work?', state);
Logger.log('Will %s work?', state);
Logger.log('Will [%s] work?', state);
Logger.log('[%s]\t is today', Date());
Logger.log('[%s]\t is today', Date().toString());
}
输出:
[13-06-17 11:33:23:660 PDT] Starting execution
[13-06-17 11:33:23:664 PDT] Logger.log([Will %s work?, [this]]) [0.0 seconds]
[13-06-17 11:33:23:664 PDT] Logger.log([Will '%s' work?, [this]]) [0.0 seconds]
[13-06-17 11:33:23:665 PDT] Logger.log([Will [%s] work?, [this]]) [0.0 seconds]
[13-06-17 11:33:23:665 PDT] Logger.log([Will "%s" work?, [this]]) [0.0 seconds]
[13-06-17 11:33:23:665 PDT] Logger.log([Will %s work?, [this]]) [0.0 seconds]
[13-06-17 11:33:23:665 PDT] Logger.log([Will [%s] work?, [this]]) [0.0 seconds]
[13-06-17 11:33:23:665 PDT] Logger.log([Will %s work?, [this]]) [0.0 seconds]
[13-06-17 11:33:23:665 PDT] Logger.log([Will '%s' work?, [this]]) [0.0 seconds]
[13-06-17 11:33:23:665 PDT] Logger.log([Will [%s] work?, [this]]) [0.0 seconds]
[13-06-17 11:33:23:666 PDT] Logger.log([Will "%s" work?, [this]]) [0.0 seconds]
[13-06-17 11:33:23:666 PDT] Logger.log([Will %s work?, [this]]) [0.001 seconds]
[13-06-17 11:33:23:666 PDT] Logger.log([Will [%s] work?, [this]]) [0.001 seconds]
[13-06-17 11:33:23:666 PDT] Logger.log([[%s] is today, [Mon Jun 17 2013 11:33:23 GMT-0700 (PDT)]]) [0.001 seconds]
[13-06-17 11:33:23:666 PDT] Logger.log([[%s] is today, [Mon Jun 17 2013 11:33:23 GMT-0700 (PDT)]]) [0.001 seconds]
[13-06-17 11:33:23:667 PDT] Execution succeeded [0.002 seconds total runtime]