0

尽管我在网上找到了许多示例(语法不同),但我无法获取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]
4

2 回答 2

4

查看您粘贴的输出,看起来您在吠叫错误的树。您看到的可能是执行记录,而不是记录器输出。可以通过在脚本编辑器中按 Ctrl-Enter 访问 Logger 输出。

于 2013-06-18T03:37:09.447 回答
0

独立脚本的输出,它工作得很好(@Fred 也报告了):

[13-06-17 15:45:24:889 EDT] Will this work?
[13-06-17 15:45:24:889 EDT] Will 'this' work?
[13-06-17 15:45:24:889 EDT] Will [this] work?
[13-06-17 15:45:24:889 EDT] Will "this" work?
[13-06-17 15:45:24:890 EDT] Will this work?
[13-06-17 15:45:24:893 EDT] Will [this] work?
[13-06-17 15:45:24:893 EDT] Will this work?
[13-06-17 15:45:24:894 EDT] Will 'this' work?
[13-06-17 15:45:24:894 EDT] Will [this] work?
[13-06-17 15:45:24:894 EDT] Will "this" work?
[13-06-17 15:45:24:894 EDT] Will this work?
[13-06-17 15:45:24:895 EDT] Will [this] work?
[13-06-17 15:45:24:895 EDT] [Mon Jun 17 2013 15:45:24 GMT-0400 (EDT)]    is today
[13-06-17 15:45:24:901 EDT] [Mon Jun 17 2013 15:45:24 GMT-0400 (EDT)]    is today

也在包含电子表格的脚本中验证。如果您可以重复您的结果,请提供有关脚本性质的更多信息。

与此同时,看起来你已经成为了一个小精灵的受害者。

于 2013-06-17T20:01:38.547 回答