summaryrefslogtreecommitdiff
path: root/ereproxy_log.erl
blob: fe5c28ba439a80b45be9031813b126a7a1eec936 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
-module(ereproxy_log).
-export([start_link/1, log/1]).

-include("ereproxy_config.hrl").

start_link(CfgMod) ->
    case file:open((CfgMod:config())#cfg.log_file, [append]) of
	{ok, LogFile} ->
	    Pid = spawn_link(?MODULE, log, [LogFile]),
	    true = register(?MODULE, Pid),
	    {ok, Pid};
	Error ->
	    error_logger:error_report(
	      [{?MODULE, ?LINE}, Error]),
	    {error, Error}
	end.

%% log: write all message to logfile (w/ timestamp)
log(FD) ->
    receive
	Msg -> 
	    io:format(FD, "~w~n", [{erlang:localtime(), Msg}]),
	    log(FD)
    end.
contact: Jan Huwald // Impressum