summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandru Scvortov <alexandru@rabbitmq.com>2011-08-03 13:39:31 +0100
committerAlexandru Scvortov <alexandru@rabbitmq.com>2011-08-03 13:39:31 +0100
commita92021dd7c1d79f6b273c3704b47e7c8e6b84358 (patch)
tree3cb135819c98ced33b4a9dc9da36bbb67d2f9e00
parent6ea01578cabe462c32dda4479b40785e1a593230 (diff)
downloadrabbitmq-server-a92021dd7c1d79f6b273c3704b47e7c8e6b84358.tar.gz
abstract out with_local_io/1
Because it will be needed whenever a rabbitmqctl command causes the logger to print anything.
-rw-r--r--src/rabbit_control.erl27
-rw-r--r--src/rabbit_misc.erl11
2 files changed, 22 insertions, 16 deletions
diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl
index bb42efb6..4bc25998 100644
--- a/src/rabbit_control.erl
+++ b/src/rabbit_control.erl
@@ -17,7 +17,7 @@
-module(rabbit_control).
-include("rabbit.hrl").
--export([start/0, stop/0, action/5, diagnostics/1, log_anytime/2]).
+-export([start/0, stop/0, action/5, diagnostics/1, log_action/3]).
-define(RPC_TIMEOUT, infinity).
-define(WAIT_FOR_VM_ATTEMPTS, 5).
@@ -51,7 +51,7 @@
-> 'ok').
-spec(diagnostics/1 :: (node()) -> [{string(), [any()]}]).
-spec(usage/0 :: () -> no_return()).
--spec(log_anytime/2 :: (string(), [term()]) -> ok).
+-spec(log_action/3 :: (node(), string(), [term()]) -> ok).
-endif.
@@ -74,9 +74,7 @@ start() ->
Command = list_to_atom(Command0),
Quiet = proplists:get_bool(?QUIET_OPT, Opts1),
Node = proplists:get_value(?NODE_OPT, Opts1),
- rpc_call(Node, rabbit_control, log_anytime,
- ["~p executing~nrabbitmqctl ~p ~p~n",
- [node(), Command0, mask_args(Command0, Args)]]),
+ rpc_call(Node, rabbit_control, log_action, [node(), Command0, Args]),
Inform = case Quiet of
true -> fun (_Format, _Args1) -> ok end;
false -> fun (Format, Args1) ->
@@ -113,14 +111,6 @@ start() ->
fmt_stderr(Format, Args) -> rabbit_misc:format_stderr(Format ++ "~n", Args).
-%% Log an info item on a remote node regardless of whether rabbit is
-%% running there or not: first change the group leader to that of the
-%% remote node, then use the standard error logger, because rabbit's
-%% might not be running.
-log_anytime(Format, Args) ->
- group_leader(whereis(user), self()),
- error_logger:info_msg(Format, Args).
-
print_report(Node, {Descr, Module, InfoFun, KeysFun}) ->
io:format("~s:~n", [Descr]),
print_report0(Node, {Module, InfoFun, KeysFun}, []).
@@ -487,10 +477,17 @@ quit(Status) ->
{win32, _} -> init:stop(Status)
end.
+log_action(Node, Command, Args) ->
+ rabbit_misc:with_local_io(
+ fun () ->
+ error_logger:info_msg("~p executing~nrabbitmqctl ~p ~p~n",
+ [Node, Command, mask_args(Command, Args)])
+ end).
+
%% Mask passwords and other sensitive info before logging.
-mask_args("add_user", [Name, Password | Args]) ->
+mask_args("add_user", [Name, _Password | Args]) ->
[Name, "****" | Args];
-mask_args("change_password", [Name, Password | Args]) ->
+mask_args("change_password", [Name, _Password | Args]) ->
[Name, "****" | Args];
mask_args(_, Args) ->
Args.
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl
index 3bbfb1d7..0d77ffea 100644
--- a/src/rabbit_misc.erl
+++ b/src/rabbit_misc.erl
@@ -42,7 +42,7 @@
-export([dirty_read_all/1, dirty_foreach_key/2, dirty_dump_log/1]).
-export([read_term_file/1, write_term_file/2, write_file/2, write_file/3]).
-export([append_file/2, ensure_parent_dirs_exist/1]).
--export([format_stderr/2]).
+-export([format_stderr/2, with_local_io/1]).
-export([start_applications/1, stop_applications/1]).
-export([unfold/2, ceil/1, queue_fold/3]).
-export([sort_field_table/1]).
@@ -165,6 +165,7 @@
-spec(append_file/2 :: (file:filename(), string()) -> ok_or_error()).
-spec(ensure_parent_dirs_exist/1 :: (string()) -> 'ok').
-spec(format_stderr/2 :: (string(), [any()]) -> 'ok').
+-spec(with_local_io/1 :: (fun (() -> 'ok')) -> 'ok').
-spec(start_applications/1 :: ([atom()]) -> 'ok').
-spec(stop_applications/1 :: ([atom()]) -> 'ok').
-spec(unfold/2 :: (fun ((A) -> ({'true', B, A} | 'false')), A) -> {[B], A}).
@@ -605,6 +606,14 @@ format_stderr(Fmt, Args) ->
end,
ok.
+%% Execute Fun using the IO system of the local node (i.e. the node on
+%% which the code is executing).
+with_local_io(Fun) ->
+ GL = group_leader(),
+ group_leader(whereis(user), self()),
+ Fun(),
+ group_leader(GL, self()).
+
manage_applications(Iterate, Do, Undo, SkipError, ErrorTag, Apps) ->
Iterate(fun (App, Acc) ->
case Do(App) of