Easier Reading of Erlang Console and Error Logs

I’m still new to Erlang and Chicago Boss, using them for just a couple of weeks now. So far, I’ve made plenty of mistakes—no big deal, since it’s all part of the learning process.

But what’s been driving me crazy is how the console and error logs are formatted. Everything comes out as one long string, making it a nightmare to read. I can’t tell where one part of the stack trace ends and the next begins. What’s frustrating is that these logs do have structure, but it gets lost in the mess of text.

I’m wondering— is there any way to make these logs more readable? I’m thinking of something like how PHP prints errors directly on the webpage or the way print_r() outputs arrays. Does Chicago Boss offer anything like that? Or maybe there’s a way to configure the logs to be more readable?

Error Code:

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

Solution to the undef Error:

The error you’re encountering:

code2014-07-22 16:30:54.285 [error] <0.784.0>@boss_web_controller:call_controller_action:366 Error in controller error undef

indicates that the Erlang runtime couldn’t find or execute the function post_param within the simple_bridge_request_wrapper module. Here’s what could be causing the error and potential solutions:

Correct Code:

code2014-07-22 16:30:54.285 [error] <0.784.0>@boss_web_controller:call_controller_action:366 Error in controller: 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}
]
}
].

Explanation:

  1. Error Type:
    The error message shows an undef error, which means the Erlang runtime could not find the function post_param within the module simple_bridge_request_wrapper. This happens when either:
    • The function doesn’t exist.
    • There’s a typo in the function/module name.
    • The module isn’t loaded correctly.
  2. Request Breakdown:
    • Request Method: 'POST'
    • Endpoint: "/greeting/list"
    • HTTP Version: 'HTTP/1.1'
    • Headers: Includes Host, Accept, Accept-Language, Accept-Encoding, Connection, Content-Type, and Content-Length.
    • User-Agent: Browser information indicates the request is coming from Firefox on Linux (Mozilla/5.0).
  3. Controller Error Handling:
    • Controller Action: The error occurred in pigeon_greeting_controller:list/3.
    • Error Location:
      • File: /home/jason/pigeon/src/controller/pigeon_greeting_controller.erl
      • Line: 34
  4. Stack Trace:
    The stack trace shows the series of function calls leading to the error. It starts from call_controller_action in the boss_web_controller module and moves through various functions handling the request. The trace ends with set_timer in the request handling module.
  5. Possible Fixes:
    • Check the Function: Ensure post_param is correctly defined in simple_bridge_request_wrapper.
    • Reload the Module: If the function exists but isn’t recognized, try reloading the module or restarting the server.
    • Log Formatting: If logs are unreadable, consider using io:format/2 or enabling better error formatting tools like Lager to structure logs for readability.

Final Thought

The undef error in the provided log indicates that the function post_param within the simple_bridge_request_wrapper module could not be found or invoked correctly. This can happen due to missing definitions, incorrect module loading, or typos in function calls. To resolve this, double-check the module implementation, ensure all dependencies are correctly loaded, and restart the server if needed.

Additionally, the raw structure of the log output can make it challenging to trace issues effectively. Consider using a structured logging tool like Lager or formatting your error messages with io:format/2 to improve readability. This will help separate stack trace levels and make it easier to understand the root cause of errors, saving you time in debugging.

Related blog posts