Erlang Learning record: app Demo

Source: Internet
Author: User

Directory structure
│  Emakefile│  make.bat│  start.bat├─config│      config.config│      server.app├─ebin│      wulin_app.beam│      wulin_sup.beam│      util.beam│      demo.beam├─logs│      debug.log└─src       wulin_app.erl       wulin_sup.erl       util.erl       demo.erl

Config configuration directory

Ebin Compiling output Directory

Logs log output Directory

SRC Source code Directory

Emakefile (Compile configuration)
{["src/*"],[{outdir,"ebin"}]}.

src/* to compile all source code files in src directory

OutDir specifying the compiled beam file output directory

Make.bat (Compile command)
erl -make all
Start.bat (Launch app)
cd configerl -name [email protected] -setcookie mywulin -boot start_sasl -noshell -config config -pa ../ebin/ -s wulin_app start

-noshell prohibit input

-config XXX Loading the configuration named Xxx.config

-PA the specified directory

-S XXX yyy start the yyy function of the XXX module

Config.config (env variable)
[    {        SASL,        [            {Sasl_error_logger, false},            {Errlog_type, Error},            {Error_logger_mf_dir, ".. /logs "},            {error_logger_mf_maxbytes, 1048760},            {Error_logger_mf_maxfiles, Ten}        ]    },{       AB,       []      }].

You can use APPLICATION:GET_ENV/2 within your program to get the variables defined here

Example: application:get_env(sasl, error_logger_mf_dir). return{ok,"../logs"}

Server.app
{   Application, Server % corresponding file name   , [{Description,  "Server"}      , {VSN, ' 1.0a '}      , {Modules, []}      , {registered, []}      , {Applications, [Kernel, Stdlib, SASL]} % Dependent Libraries      , {Env, [{author, "Demo"}]}      , {MoD, {Wulin_app, [12321]}} % dependent module, main module      , {start_phases, []}]}.

Server (app name) must match Server.app (file name)

Wulin_app.erl
-module(Wulin_app).-behaviour (Application). -export([Start/2,Start/0, Stop/1]). Start ()  - Application:start (Server).Start (_type, [A])  -      Util:debug ("Server starting .... ~p ~n", [A]),      Util:debug ("Server starting .... ~n", []),      {OK, Pid} = Wulin_sup:start_link (),      Util:debug ("Server Started in ~p ~n", [Pid]),          {OK, Pid}.      Stop (_state)  -      Io:format ("Server stoped ... ~n"). 

Server in Application:start (server) corresponds to server in Server.app

Wulin_sup.erl
-module(Wulin_sup).-behaviour (Supervisor).-export([Start_link/0,Init/1]).Start_link ()  -      Supervisor:start_link ({Local,?MODULE}, ?MODULE, []).init ([])  -       {OK, {{One_for_one, 3, Ten},[        {Demo, {Demo, Start, []}, Permanent, 10000, worker, []}    ]}}.  
Demo.erl
-module(demo).-export([start/0]).start()->      util:debug("xxxxx ~n",[]),    {‘ok‘,self()}.
Util.erl
-module(util).-export([Debug/2]). Debug (F, Args)  -    {OK, LogPath} = application:get_env (SASL, Error_logger_mf_dir),    File = LogPath ++ "/debug.txt",    {OK, Steam} = File:open (File, [Write, Append]),    Io:format (Steam, F, Args),    File:close (Steam).
Debug.log
Process

Start.bat, wulin_app:start/0, Server.app,

WULIN_APP:START/2, wulin_sup:start_link/0, demo:start/0

Erlang Learning record: app Demo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.