62 lines
2.0 KiB
Erlang
62 lines
2.0 KiB
Erlang
%%%-------------------------------------------------------------------
|
|
%%% @author Fabio Salvini <fs@fabiosalvini.com>
|
|
%%% @copyright (C) 2017, Fabio Salvini
|
|
%% @doc log_monitor public API
|
|
%% @end
|
|
%%% Created : 2 Jul 2017 by Fabio Salvini <fs@fabiosalvini.com>
|
|
%%%-------------------------------------------------------------------
|
|
-module(log_monitor_app).
|
|
|
|
-behaviour(application).
|
|
|
|
-include_lib("mnesia_tables.hrl").
|
|
|
|
%% Application callbacks
|
|
-export([start/2, stop/1]).
|
|
|
|
%%====================================================================
|
|
%% API
|
|
%%====================================================================
|
|
start(_StartType, _StartArgs) ->
|
|
start_mnesia(),
|
|
log_monitor_sup:start_link().
|
|
|
|
%%--------------------------------------------------------------------
|
|
stop(_State) ->
|
|
mnesia:stop(),
|
|
ok.
|
|
|
|
%%====================================================================
|
|
%% Internal functions
|
|
%%====================================================================
|
|
start_mnesia() ->
|
|
Nodes = [node()],
|
|
%% Stop Mnesia if it is running, cannot create schema otherwise.
|
|
mnesia:stop(),
|
|
mnesia:create_schema(Nodes),
|
|
mnesia:start(),
|
|
mnesia:create_table(log_monitor_group,
|
|
[
|
|
{attributes, record_info(fields, log_monitor_group)},
|
|
{disc_copies, Nodes}
|
|
]),
|
|
mnesia:create_table(log_monitor_file,
|
|
[
|
|
{attributes, record_info(fields, log_monitor_file)},
|
|
{index, [#log_monitor_file.group]},
|
|
{disc_copies, Nodes}
|
|
]),
|
|
mnesia:create_table(log_monitor_error,
|
|
[
|
|
{attributes, record_info(fields, log_monitor_error)},
|
|
{disc_copies, Nodes}
|
|
]),
|
|
ok = mnesia:wait_for_tables(
|
|
[
|
|
log_monitor_group,
|
|
log_monitor_file,
|
|
log_monitor_error
|
|
],
|
|
30000
|
|
).
|