erlangchicagoboss

Tools for reading Erlang console or error logs


I am new to erlang and Chicago Boss have been using them for only been a couple of weeks, So I have been making my fare share of mistakes in that time. which does not bother me that much as it all part of learning.

But the thing that does frustrate me is the console and error logs, I find them almost impossible to read as every thing comes out in a single line and I can't tell one level of a stack message from another. even more annoying is that that string has structure in it but all of that is just wiped away.

Is there anyway of seeing these logs in a more understandable form, something like how php prints the error to the webpage, or the print_r function for an array, maybe there is something in Chicago boss.

Example :

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}]}]

Any help would be appropriated


Solution

  • It would be good if they pretty-printed the error messages, but you can do it yourself with a bit of trouble. The meat of the message is an erlang term, in this case a list. Just copy and past the erlang term into your shell, add a period to make it a legal statement:

    > [{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}]}].
    

    ...and hit return:

    * 1: syntax error before: '\\'
    

    Oops, apparently there isn't a literal representation of a port in erlang so they print a brief description of one: #Port<0.41310>. In erlang you can wrap illegal characters in single quote marks I think to create an atom, which is a legal term, so then the shell will allow it: '#Port<0.41310>'. So then:

    > [{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}]}].
    

    ...and hit return:

    [{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}]}]
    

    I've never used Chicago Boss so I can't help with that. The message said undef so that makes me think perhaps erlang couldn't find that first function. Maybe you don't have simple_bridge_request_wrapper installed or compiled yet or something?

    Obviously, this will be pretty annoying to do all the time. Maybe there's a way to get the previous shell command's output. Then you could write a personal shell fun and put it in your user_default.erl to automate this process. Or do it in elisp if you use emacs. Or patch CB to pretty print its error messages.