[thrift] revert 61883

Summary: i suck at git/svn ... commited not enough and with no commitlog

Notes: YOU'RE DOING IT WRONG


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665283 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/erl/src/thrift_logger.erl b/lib/erl/src/thrift_logger.erl
index 6deb222..12aa059 100644
--- a/lib/erl/src/thrift_logger.erl
+++ b/lib/erl/src/thrift_logger.erl
@@ -8,9 +8,7 @@
 
 -behaviour(gen_event).
 
--record(state, {config}).
-
--define(CONFIG(Item), config(Item, State)).
+-include("thrift_logger.hrl").
 
 %% TODO(cpiro): either
 %% make exceptions know whether they need to be displayed
@@ -25,14 +23,13 @@
 -export([init/1, handle_event/2, handle_call/2, 
          handle_info/2, terminate/2, code_change/3]).
 
--export([install/0, install/1, reconfig/0, reconfig/1]).
+-export([install/0, install/1]).
 
 %% ensure the regular logger is out and ours is in
 install() ->
     install([]).
-install(Config) ->
+install(Args) ->
     %% remove loggers
-    io:format("starting logger~n"),
     lists:foreach(fun(Logger) ->
       case Logger of
         _ -> gen_event:delete_handler(error_logger, Logger, normal)
@@ -41,19 +38,15 @@
 
     %% TODO(cpiro): sasl someday?
     %% gen_event:add_handler(error_logger, sasl_report_file_h, {LogFile, all}),
+    gen_event:add_handler(error_logger, ?MODULE, Args).
 
-    gen_event:add_handler(error_logger, ?MODULE, []),
+%% how to output
+format(Format, Data) ->
+    io:format(Format, Data).
 
-    reconfig(Config),
-
-    ok.
-
-%% load our config file and amend the given stuff
-reconfig() ->
-    reconfig([]).
-
-reconfig(Config) ->
-    gen_event:call(error_logger, ?MODULE, {reconfig, Config}).
+%% convenience
+sformat(Format, Data) ->
+    thrift_utils:sformat(Format, Data).
 
 %%====================================================================
 %% gen_event callbacks
@@ -67,15 +60,15 @@
 %% @end 
 %%--------------------------------------------------------------------
 init([]) ->
-    BootConfig = [
-      {term_width, 80},
-      {force_one_line, false},
-      {omit, []},
-      {gen_server_messages, true},
-      {lookup, false}
-    ], %% configuration before we try loading from file
+    {ok, #thrift_logger_state{
+       term_width = 110,
+       force_one_line = true,
+       omit = [oop_new], % req_processed
+       gen_server_messages = false,
+       lookup = true
+      }};
 
-    State = #state{config=BootConfig},
+init([State]) ->
     {ok, State}.
 
 %%--------------------------------------------------------------------
@@ -108,7 +101,7 @@
 	end,
 
     Length =
-	case (length(OutputSafe) + BannerLen) < ?CONFIG(term_width) of
+	case (length(OutputSafe) + BannerLen) < State#thrift_logger_state.term_width of
 	    true  -> short;
 	    false -> long
 	end,
@@ -119,7 +112,7 @@
 	    false -> multiline
 	end,
 
-    case { ?CONFIG(force_one_line), Length, OneLine } of
+    case { State#thrift_logger_state.force_one_line, Length, OneLine } of
 	%% one line and short ... print as is
 	{_, short, oneliner} ->
 	    format("~s~s~n", [Banner, OutputSafe]);
@@ -127,7 +120,7 @@
 	%% too long ... squash to one
 	{true, long, _} ->
 	    O = Banner ++ OutputSafe,
-	    Format = sformat("~~~ps >~n", [?CONFIG(term_width)-2]), % e.g. "~80s >~n"
+	    Format = sformat("~~~ps >~n", [State#thrift_logger_state.term_width-2]), % e.g. "~80s >~n"
 	    format(Format, [O]);
 
 	%% short but multiline... collapse to one
@@ -151,7 +144,7 @@
     case Format of
 	"** Generic server ~p terminating \n** Last message in was ~p~n** When Server state == ~p~n** Reason for termination == ~n** ~p~n" ->
 	    %% v- Pid is a pattern match, not a bind
-	    [Ref, LastMessage, Obj, Reason] = Data,
+	    [Pid, LastMessage, Obj, Reason] = Data,
 
 	    %% TODO: move as much logic as possible out of thrift_logger
 	    Ignore =
@@ -175,11 +168,11 @@
 		false ->
 		    Format1 = "** gen_server terminating in message ~p~n** State  = ~s~n** Reason = ~s~n",
 		    Message = sformat(Format1, [LastMessage, oop:inspect(Obj), oop:inspect(Reason)]), %% TODO(cpiro): hope Reason is an object?
-		    handle_event2(Symbol, Ref, "", Message, State)
+		    handle_event2(Symbol, Pid, "", Message, State)
 	    end;
 	_ ->
 	    Message = sformat(Format, Data),
-	    handle_event2(Symbol, Ref, "", Message, State)
+	    handle_event2(Symbol, Pid, "", Message, State)
     end,
     {ok, State};
 
@@ -194,7 +187,7 @@
     case Type of
 	{thrift_info, TI} ->
 	    %% should we show it?
-	    case not lists:member(TI, ?CONFIG(omit)) of
+	    case not lists:member(TI, State#thrift_logger_state.omit) of
 		true ->
 		    Message = handle_thrift_info(TI, Report, State),
 		    handle_event2(Symbol, Pid, "", Message, State);
@@ -256,7 +249,7 @@
 
 %%--------------------------------------------------------------------
 %% @spec handle_call(Request, State) -> {ok, Reply, State} |
-%%                                {swap_handler, Reply, Args1, State1,
+%%                                {swap_handler, Reply, Args1, State1, 
 %%                                  Mod2, Args2} |
 %%                                {remove_handler, Reply}.
 %% 
@@ -266,11 +259,6 @@
 %% handler to handle the request.
 %% @end 
 %%--------------------------------------------------------------------
-handle_call({reconfig, Amendments}, State) ->
-    {OkOrError, State1} = reconfig1(State, Amendments),
-    format(".. reconfig was ~p~n", [OkOrError]),
-    {ok, OkOrError, State1};
-    
 handle_call(_Request, State) ->
     Reply = ok,
     {ok, Reply, State}.
@@ -317,32 +305,3 @@
 %%====================================================================
 %%% Internal functions
 %%====================================================================
-
-%% how to output
-format(Format, Data) ->
-    io:format(Format, Data).
-
-%% convenience
-sformat(Format, Data) ->
-    thrift_utils:sformat(Format, Data).
-
-reconfig1(State, Amendments) ->
-    case thrift:config(thrift_logger) of
-	{value, Config} ->
-	    Config1     = lists:keysort(1, Config),
-	    Amendments1 = lists:keysort(1, Amendments),
-	    Config2     = lists:keymerge(1, Amendments1, Config1),
-
-	    State1 = State#state{config=Config2},
-	    {ok, State1};
-	_ -> 
-	    {error, State}
-    end.
-
-config(Item, State) ->
-    case thrift:config(Item, State#state.config) of
-	{value, V} ->
-	    V;
-	Else ->
-	    ?ERROR("config for ~p is unavailable: ~p", [Item, Else])
-    end.