Created
April 8, 2016 08:37
-
-
Save sivsushruth/d6a4a9b2c8dc1c2d1c3c97a97d986943 to your computer and use it in GitHub Desktop.
Barrel Log Event Handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(barrel_log_event). | |
-behaviour(gen_server). | |
% public API | |
-export([start_link/0, stop/0]). | |
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, | |
terminate/2, code_change/3]). | |
start_link() -> | |
gen_server:start_link({local, barrel_log_event}, barrel_log_event, [], []). | |
stop() -> | |
couch_event_sup:stop(barrel_log_event). | |
init(X) -> | |
lager_handler_watcher:start(lager_event, barrel_log_event_handler, []), | |
{ok, X}. | |
handle_call(X, Y, Z) -> | |
{ok, ok, Z}. | |
handle_cast(X, Y) -> | |
{noreply, Y}. | |
handle_info(X, Y) -> | |
{ok, Y}. | |
code_change(X, Y, Z) -> | |
{ok, Y}. | |
terminate(X, Y) -> | |
ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(barrel_log_event_handler). | |
-behaviour(gen_event). | |
-export([init/1, handle_event/2, handle_call/2, handle_info/2, code_change/3, | |
terminate/2]). | |
init([]) -> | |
{ok, []}. | |
handle_event({log, Log}, State) -> | |
io:format("****** LOG -------------- ~p ~n", [Log]), | |
{ok, State}; | |
handle_event(_, State) -> | |
{ok, State}. | |
handle_call(_, State) -> | |
{ok, ok, State}. | |
handle_info(_, State) -> | |
{ok, State}. | |
code_change(_OldVsn, State, _Extra) -> | |
{ok, State}. | |
terminate(_Reason, _State) -> | |
ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%%------------------------------------------------------------------- | |
%% @doc barrel_core top level supervisor. | |
%% @end | |
%%%------------------------------------------------------------------- | |
-module('barrel_sup'). | |
-behaviour(supervisor). | |
%% API | |
-export([start_link/0]). | |
%% Supervisor callbacks | |
-export([init/1]). | |
-define(SERVER, ?MODULE). | |
%%==================================================================== | |
%% API functions | |
%%==================================================================== | |
start_link() -> | |
supervisor:start_link({local, ?SERVER}, ?MODULE, []). | |
%%==================================================================== | |
%% Supervisor callbacks | |
%%==================================================================== | |
%% Child :: {Id,StartFunc,Restart,Shutdown,Type,Modules} | |
init([]) -> | |
UUIDs = {barrel_uuids, | |
{barrel_uuids, start_link, []}, | |
permanent, brutal_kill, worker, [barrel_uuids]}, | |
Log = {barrel_log, | |
{barrel_log, start_link, []}, | |
permanent, brutal_kill, worker, [barrel_log]}, | |
LogEvent = {barrel_log_event, | |
{barrel_log_event, start_link, []}, | |
permanent, brutal_kill, worker, [barrel_log_event]}, | |
{ok, { {one_for_all, 0, 1}, [UUIDs, Log, LogEvent]} }. | |
%%==================================================================== | |
%% Internal functions | |
%%==================================================================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
do you need https://gist.github.com/sivsushruth/d6a4a9b2c8dc1c2d1c3c97a97d986943#file-barrel_sup-erl-L40-L42 ?
Anyway the idea sounds good according the infos you gave on slack. Go ahead, I will review the PR :)