如何在执行代码时获取system.debug输出?

Par*_*ana 6 salesforce apex-code

我编写了一个简单的程序,希望在运行代码时看到输出.当我使用'Annoymously execute apex code'命令在force.com IDE中运行它时,当我只需要system.debug语句时,我会收到很多不需要的结果.我可以使用记事本或excel,但似乎应该有一个直接的方式(本机或工具).有什么建议?

谢谢,

EL-noobre

public with sharing class Aa_playground {



 public static void listExp(){
    List<Integer> x = new List<Integer>();
    x.add(1212);
    for (Integer i = 0; i < x.size(); i++){
        System.debug(x[i]);
    }

}
} 
Run Code Online (Sandbox Code Playgroud)

产量

Anonymous execution was successful.

24.0     APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;VALIDATION,INFO;WORKFLOW,INFO
Execute Anonymous: Aa_playground.listExp();
13:40:52.037 (37218000)|EXECUTION_STARTED
13:40:52.037 (37228000)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
13:40:52.037 (37634000)|METHOD_ENTRY|[1]|01pQ000000062u5|Aa_playground.Aa_playground()
13:40:52.037 (37726000)|METHOD_EXIT|[1]|Aa_playground
13:40:52.037 (37740000)|METHOD_ENTRY|[1]|01pQ000000062u5|Aa_playground.listExp()
13:40:52.037 (37920000)|USER_DEBUG|[9]|DEBUG|1212
13:40:52.037 (37947000)|METHOD_EXIT|[1]|01pQ000000062u5|Aa_playground.listExp()
13:40:52.594 (37979000)|CUMULATIVE_LIMIT_USAGE
13:40:52.594|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of script statements: 5 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

13:40:52.594|CUMULATIVE_LIMIT_USAGE_END

13:40:52.038 (38005000)|CODE_UNIT_FINISHED|execute_anonymous_apex
13:40:52.038 (38011000)|EXECUTION_FINISHED
Run Code Online (Sandbox Code Playgroud)

Mat*_*t K 7

我想我会在答案中总结一些我发现的信息.

  1. 下载Notepad ++ v6.1 +
  2. 在Notepad ++中,打开(或粘贴)您的调试日志文件.
  3. 从菜单中,选择"宏">"开始录制".
  4. 按CTRL-H(或搜索和替换的快捷方式).
  5. 复制此正则表达式^(?!.+USER_DEBUG.+$).*$并将其粘贴到"查找内容:"文本框中.
  6. 确保搜索模式设置为正则表达式,并且"替换为:"文本框为空.
  7. 当结果对话框显示时,单击"全部替换"和"确定".
  8. 复制此正则表达式(?m)^([ \t\s]*|;.*)(\r?\n|$)并将其粘贴到"查找内容:"文本框中.
  9. 确保搜索模式设置为正则表达式,并且"替换为:"文本框为空.
  10. 单击"全部替换"和"确定".然后,关闭"搜索和替换"对话框.
  11. 从菜单中,选择"宏">"停止录制".然后选择"宏">"保存当前记录的宏".
  12. 输入新宏的名称,并可选择设置快捷键.然后单击"确定".

要执行新宏,请从菜单中选择"宏",然后单击您的宏名称.

正则表达式的信用转到nivyaj(参见问题评论).Daniel Ballinger的博客文章也很有帮助.


Dan*_*all 5

这可能是不好的做法,但我过去所做的是将APEX_CODE的日志级别设置为INFO,并将调试消息的日志级别设置为info

System.debug(Logginglevel.INFO, 'Debug Message with INFO level');
Run Code Online (Sandbox Code Playgroud)