Google Apps脚本:记录器不格式化

时间:2013-06-17 18:46:22

标签: google-apps-script

尽管我在网上找到了许多例子(各种语法),但我无法获得 Logger.log(String format,Object .... values):Logger 格式化。 Google's official doc for 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]

2 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分: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

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

与此同时,看起来你一直是gremlin的牺牲品。