这是我可以提出的最基本的应用程序,我无法理解为什么应用程序模块功能的start / 2不会记录消息。这是我所做的:
1)应用配置文件(test_app.app):
{application,test_app,
[{description,"Test App"},
{vsn,0.9},
{applications,[kernel,stdlib]},
{modules,[test_app,log_utils]},
{registered,[test_app]}]}.
2)应用模块(test_app.erl):
-module(test_app).
-behaviour(application).
-export([start/2, stop/1]).
-export([test/0]).
start(_Type, _Args) ->
log_utils:info("here at APP START 1"),
master_sup:start_link({10,20,30}).
stop(_State) ->
ok.
test() ->
log_utils:info("here at APP START 2"),
master_sup:start_link({10,20,30}).
然后,我这样进行编译和测试:
1> application:start(test_app).
ok
2> test_app:test().
==INFO REPORT==== 27-Oct-2013::19:53:29 ===
"here at APP START 2"
我期望的是,application:start(test_app)将执行start / 2函数并像test / 0函数一样记录消息。
实际上,我有一个更复杂的示例,其中我启动了主管,但是类似地,我在app模块中创建的API也会导致错误,指示start_link不起作用。如果我调用启动监督程序的测试功能,那么它将起作用。
您需要为该.app
文件提供一个附加选项,以提供应用程序回调模块并启动args。没有隐式的回调模块名称,如果没有给出,则不会启动任何进程。该选项{mod,{CallBackMod,StartArgs}}
使整个.app
文件变为:
{application,test_app,
[{description,"Test App"},
{vsn,0.9},
{applications,[kernel,stdlib]},
{modules,[test_app,log_utils]},
{registered,[test_app]},
{mod,{test_app,[]}}]}.
test_app
在您的情况下,第二个元素是应用程序的名称,而不是回调模块;他们不必相同。如果给出了回调,Mod:start/2
则将在启动应用程序以及Mod:stop/1
停止应用程序时调用。
请注意,应用程序在启动时不必运行任何进程,例如,stdlib
应用程序无需运行。
您可以在“应用程序”中找到更好的描述。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句