1

我是 erlang 的新手,Chicago Boss 只使用了几个星期,所以在那段时间里我一直在犯错误。这并没有让我感到困扰,因为它是学习的一部分。

但是让我感到沮丧的是控制台和错误日志,我发现它们几乎不可能阅读,因为每件事都在一行中出现,而且我无法区分堆栈消息的一个级别。更令人讨厌的是,该字符串具有结构,但所有这些都被抹去了。

无论如何以更易于理解的形式查看这些日志,例如php如何将错误打印到网页,或者数组的print_r函数,也许芝加哥老板有什么东西。

例子 :

2014-07-22 16:30:54.285 [error] <0.784.0>@boss_web_controller:call_controller_action:366 Error in controller error undef 
[{simple_bridge_request_wrapper,post_param,
     [{simple_bridge_request_wrapper,mochiweb_request_bridge,
          {mochicow_request,#Port<0.41310>,'POST',"/greeting/list",
              'HTTP/1.1',
              {9,
               {"host",
                {"host","jason-virtualbox:8001"},
                {"accept",
                 {"accept",
                  "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"},
                 nil,
                 {"accept-language",
                  {"accept-language","en-US,en;q=0.5"},
                  {"accept-encoding",
                   {"accept-encoding","gzip, deflate"},
                   nil,nil},
                  {"connection",
                   {"connection","keep-alive"},
                   nil,
                   {"content-type",
                    {"content-type","application/x-www-form-urlencoded"},
                    {"content-length",{"content-length","44"},nil,nil},
                    nil}}}},
                {"user-agent",
                 {"user-agent",
                  "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0"},
                 {"referer",
                  {"referer","http://****:8001/greeting/hello"},
                  nil,nil},
                 nil}}},
              <<"SheetName=%7BBook1.2%7D%2C%7B0-Sheet1.csv%7D">>},
          false,[],[],none}],
     []},
 {pigeon_greeting_controller,list,3,
     [{file,
          "/home/jason/pigeon/src/controller/pigeon_greeting_controller.erl"},
      {line,34}]},
 {boss_web_controller,call_controller_action,3,
     [{file,"src/boss/boss_web_controller.erl"},{line,363}]},
 {boss_web_controller,apply_action,4,
     [{file,"src/boss/boss_web_controller.erl"},{line,355}]},
 {boss_web_controller,execute_action_inner,9,
     [{file,"src/boss/boss_web_controller.erl"},{line,334}]},
 {boss_web_controller_handle_request,process_dynamic_request,4,
     [{file,"src/boss/boss_web_controller_handle_request.erl"},{line,242}]},
 {boss_web_controller_handle_request,process_request,4,
     [{file,"src/boss/boss_web_controller_handle_request.erl"},{line,228}]},
 {boss_web_controller_handle_request,set_timer,7,
     [{file,"src/boss/boss_web_controller_handle_request.erl"},{line,148}]}]

任何帮助都会被挪用

4

1 回答 1

2

如果他们漂亮地打印错误消息会很好,但你可以自己做,但有点麻烦。消息的核心是一个 erlang 术语,在本例中是一个列表。只需将 erlang 术语复制并粘贴到您的 shell 中,添加句点以使其成为法律声明:

> [{simple_bridge_request_wrapper,post_param,[{simple_bridge_request_wrapper,mochiweb_request_bridge,{mochicow_request,#Port<0.41310>,'POST',"/greeting/list",'HTTP/1.1',{9,{"host",{"host","jason-virtualbox:8001"},{"accept",{"accept", "text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8"},nil,{"accept-language",{"accept-language","en-US,en;q=0.5"},{"accept-encoding",{"accept-encoding","gzip, deflate"},nil,nil},{"connection",{"connection","keep-alive"},nil,{"content-type",{"content-type","application/x-www-form-urlencoded"},{"content-length",{"content-length","44"},nil,nil},nil}}}},{"user-agent",{"user-agent","Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0"},{"referer",{"referer","http://****:8001/greeting/hello"},nil,nil},nil}}},<<"SheetName=%7BBook1.2%7D%2C%7B0-Sheet1.csv%7D">>},false,[],[],none}],[]},{pigeon_greeting_controller,list,3,[{file,"/home/jason/pigeon/src/controller/pigeon_greeting_controller.erl"},{line,34}]},{boss_web_controller,call_controller_action,3,[{file,"src/boss/boss_web_controller.erl"},{line,363}]},{boss_web_controller,apply_action,4,[{file,"src/boss/boss_web_controller.erl"},{line,355}]},{boss_web_controller,execute_action_inner,9,[{file,"src/boss/boss_web_controller.erl"},{line,334}]},{boss_web_controller_handle_request,process_dynamic_request,4,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,242}]},{boss_web_controller_handle_request,process_request,4,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,228}]},{boss_web_controller_handle_request,set_timer,7,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,148}]}].

...并点击返回:

* 1: syntax error before: '\\'

糟糕,显然 erlang 中没有端口的字面表示,所以他们打印了一个简短的描述:#Port<0.41310>。在erlang中,您可以将非法字符用单引号括起来,我认为创建一个原子,这是一个合法术语,因此shell将允许它:'#Port<0.41310>'. 那么:

> [{simple_bridge_request_wrapper,post_param,[{simple_bridge_request_wrapper,mochiweb_request_bridge,{mochicow_request,'#Port<0.41310>','POST',"/greeting/list",'HTTP/1.1',{9,{"host",{"host","jason-virtualbox:8001"},{"accept",{"accept", "text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8"},nil,{"accept-language",{"accept-language","en-US,en;q=0.5"},{"accept-encoding",{"accept-encoding","gzip, deflate"},nil,nil},{"connection",{"connection","keep-alive"},nil,{"content-type",{"content-type","application/x-www-form-urlencoded"},{"content-length",{"content-length","44"},nil,nil},nil}}}},{"user-agent",{"user-agent","Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0"},{"referer",{"referer","http://****:8001/greeting/hello"},nil,nil},nil}}},<<"SheetName=%7BBook1.2%7D%2C%7B0-Sheet1.csv%7D">>},false,[],[],none}],[]},{pigeon_greeting_controller,list,3,[{file,"/home/jason/pigeon/src/controller/pigeon_greeting_controller.erl"},{line,34}]},{boss_web_controller,call_controller_action,3,[{file,"src/boss/boss_web_controller.erl"},{line,363}]},{boss_web_controller,apply_action,4,[{file,"src/boss/boss_web_controller.erl"},{line,355}]},{boss_web_controller,execute_action_inner,9,[{file,"src/boss/boss_web_controller.erl"},{line,334}]},{boss_web_controller_handle_request,process_dynamic_request,4,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,242}]},{boss_web_controller_handle_request,process_request,4,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,228}]},{boss_web_controller_handle_request,set_timer,7,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,148}]}].

...并点击返回:

[{simple_bridge_request_wrapper,post_param,
     [{simple_bridge_request_wrapper,mochiweb_request_bridge,
          {mochicow_request,'#Port<0.41310>','POST',"/greeting/list",
              'HTTP/1.1',
              {9,
               {"host",
                {"host","jason-virtualbox:8001"},
                {"accept",
                 {"accept",
                  "text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8"},
                 nil,
                 {"accept-language",
                  {"accept-language","en-US,en;q=0.5"},
                  {"accept-encoding",{[...],...},nil,...},
                  {"connection",{...},...}}},
                {"user-agent",
                 {"user-agent",
                  "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0"},
                 {"referer",
                  {"referer","http://****:8001/greeting/hello"},
                  nil,nil},
                 nil}}},
              <<"SheetName=%7BBook1.2%7D%2C%7B0-Sheet1.csv%7D">>},
          false,[],[],none}],
     []},
 {pigeon_greeting_controller,list,3,
     [{file,
          "/home/jason/pigeon/src/controller/pigeon_greeting_controller.erl"},
      {line,34}]},
 {boss_web_controller,call_controller_action,3,
     [{file,"src/boss/boss_web_controller.erl"},{line,363}]},
 {boss_web_controller,apply_action,4,
     [{file,"src/boss/boss_web_controller.erl"},{line,355}]},
 {boss_web_controller,execute_action_inner,9,
     [{file,"src/boss/boss_web_controller.erl"},{line,334}]},
 {boss_web_controller_handle_request,process_dynamic_request,
     4,
     [{file,"src/boss/boss_web_controller_handle_request.erl"},
      {line,242}]},
 {boss_web_controller_handle_request,process_request,4,
     [{file,"src/boss/boss_web_controller_handle_request.erl"},
      {line,228}]},
 {boss_web_controller_handle_request,set_timer,7,
     [{file,"src/boss/boss_web_controller_handle_request.erl"},
      {line,148}]}]

我从来没有用过芝加哥老板,所以我无能为力。消息说undef,这让我觉得也许 erlang 找不到第一个函数。也许您还没有安装或编译 simple_bridge_request_wrapper 或其他什么?

显然,这会一直很烦人。也许有一种方法可以获取上一个 shell 命令的输出。然后,您可以编写一个个人 shell fun 并将其放入您的 user_default.erl 以自动执行此过程。或者如果您使用 emacs,请在 elisp 中执行此操作。或修补 CB 以漂亮地打印其错误消息。

于 2014-07-23T22:20:59.790 回答