diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2014-08-14 12:11:39 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2014-08-14 12:11:39 +0100 |
commit | a97fe35a0b35bf7e39a3803a858ae76cb41896c9 (patch) | |
tree | 4223701ec7d200f71d112ddd35742e5633adb8c4 | |
parent | f8e3cc7d56b34409fd1570a71db45e8cb1a75b82 (diff) | |
parent | 4a3968ead4cf5dcbca4e1a5a8d68b3e0d8ba428a (diff) | |
download | rabbitmq-server-a97fe35a0b35bf7e39a3803a858ae76cb41896c9.tar.gz |
Merge bug26345
-rw-r--r-- | src/rabbit.erl | 10 | ||||
-rw-r--r-- | src/rabbit_log.erl | 30 | ||||
-rw-r--r-- | src/rabbit_misc.erl | 20 | ||||
-rw-r--r-- | src/rabbit_mnesia.erl | 17 |
4 files changed, 38 insertions, 39 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl index 4b8af870..b00a1ad7 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -360,7 +360,7 @@ stop() -> undefined -> ok; _ -> await_startup(true) end, - rabbit_misc:local_info_msg("Stopping RabbitMQ~n", []), + rabbit_log:info("Stopping RabbitMQ~n", []), Apps = ?APPS ++ rabbit_plugins:active(), stop_apps(app_utils:app_dependency_order(Apps, true)). @@ -368,7 +368,7 @@ stop_and_halt() -> try stop() after - rabbit_misc:local_info_msg("Halting Erlang VM~n", []), + rabbit_log:info("Halting Erlang VM~n", []), init:stop() end, ok. @@ -481,7 +481,7 @@ environment() -> rotate_logs(BinarySuffix) -> Suffix = binary_to_list(BinarySuffix), - rabbit_misc:local_info_msg("Rotating logs with suffix '~s'~n", [Suffix]), + rabbit_log:info("Rotating logs with suffix '~s'~n", [Suffix]), log_rotation_result(rotate_logs(log_location(kernel), Suffix, rabbit_error_logger_file_h), @@ -638,7 +638,7 @@ boot_error(Reason, Fmt, Args, Stacktrace) -> basic_boot_error(Reason, Format, Args) -> io:format("~n~nBOOT FAILED~n===========~n~n" ++ Format, Args), - rabbit_misc:local_info_msg(Format, Args), + rabbit_log:info(Format, Args), timer:sleep(1000), exit({?MODULE, failure_during_boot, Reason}). @@ -762,7 +762,7 @@ force_event_refresh(Ref) -> %% misc log_broker_started(Plugins) -> - rabbit_misc:with_local_io( + rabbit_log:with_local_io( fun() -> PluginList = iolist_to_binary([rabbit_misc:format(" * ~s~n", [P]) || P <- Plugins]), diff --git a/src/rabbit_log.erl b/src/rabbit_log.erl index 2ca5260c..e05ef05a 100644 --- a/src/rabbit_log.erl +++ b/src/rabbit_log.erl @@ -17,6 +17,7 @@ -module(rabbit_log). -export([log/3, log/4, info/1, info/2, warning/1, warning/2, error/1, error/2]). +-export([with_local_io/1]). %%---------------------------------------------------------------------------- @@ -37,6 +38,8 @@ -spec(error/1 :: (string()) -> 'ok'). -spec(error/2 :: (string(), [any()]) -> 'ok'). +-spec(with_local_io/1 :: (fun (() -> A)) -> A). + -endif. %%---------------------------------------------------------------------------- @@ -46,11 +49,12 @@ log(Category, Level, Fmt) -> log(Category, Level, Fmt, []). log(Category, Level, Fmt, Args) when is_list(Args) -> case level(Level) =< catlevel(Category) of false -> ok; - true -> (case Level of - info -> fun error_logger:info_msg/2; - warning -> fun error_logger:warning_msg/2; - error -> fun error_logger:error_msg/2 - end)(Fmt, Args) + true -> F = case Level of + info -> fun error_logger:info_msg/2; + warning -> fun error_logger:warning_msg/2; + error -> fun error_logger:error_msg/2 + end, + with_local_io(fun () -> F(Fmt, Args) end) end. info(Fmt) -> log(default, info, Fmt). @@ -75,3 +79,19 @@ level(info) -> 3; level(warning) -> 2; level(error) -> 1; level(none) -> 0. + +%% Execute Fun using the IO system of the local node (i.e. the node on +%% which the code is executing). Since this is invoked for every log +%% message, we try to avoid unnecessarily churning group_leader/1. +with_local_io(Fun) -> + GL = group_leader(), + Node = node(), + case node(GL) of + Node -> Fun(); + _ -> group_leader(whereis(user), self()), + try + Fun() + after + group_leader(GL, self()) + end + end. diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 7ff88f04..d2456918 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -42,7 +42,6 @@ -export([table_filter/3]). -export([dirty_read_all/1, dirty_foreach_key/2, dirty_dump_log/1]). -export([format/2, format_many/1, format_stderr/2]). --export([with_local_io/1, local_info_msg/2]). -export([unfold/2, ceil/1, queue_fold/3]). -export([sort_field_table/1]). -export([pid_to_string/1, string_to_pid/1, node_to_fake_pid/1]). @@ -185,8 +184,6 @@ -spec(format/2 :: (string(), [any()]) -> string()). -spec(format_many/1 :: ([{string(), [any()]}]) -> string()). -spec(format_stderr/2 :: (string(), [any()]) -> 'ok'). --spec(with_local_io/1 :: (fun (() -> A)) -> A). --spec(local_info_msg/2 :: (string(), [any()]) -> 'ok'). -spec(unfold/2 :: (fun ((A) -> ({'true', B, A} | 'false')), A) -> {[B], A}). -spec(ceil/1 :: (number()) -> integer()). -spec(queue_fold/3 :: (fun ((any(), B) -> B), B, queue()) -> B). @@ -644,23 +641,6 @@ 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()), - try - Fun() - after - group_leader(GL, self()) - end. - -%% Log an info message on the local node using the standard logger. -%% Use this if the call didn't originate on the local node (e.g. -%% rabbitmqctl calls). -local_info_msg(Format, Args) -> - with_local_io(fun () -> rabbit_log:info(Format, Args) end). - unfold(Fun, Init) -> unfold(Fun, [], Init). diff --git a/src/rabbit_mnesia.erl b/src/rabbit_mnesia.erl index a499686f..d5dd9712 100644 --- a/src/rabbit_mnesia.erl +++ b/src/rabbit_mnesia.erl @@ -177,14 +177,13 @@ join_cluster(DiscoveryNode, NodeType) -> reset_gracefully(), %% Join the cluster - rabbit_misc:local_info_msg("Clustering with ~p as ~p node~n", - [ClusterNodes, NodeType]), + rabbit_log:info("Clustering with ~p as ~p node~n", + [ClusterNodes, NodeType]), ok = init_db_with_mnesia(ClusterNodes, NodeType, true, true), rabbit_node_monitor:notify_joined_cluster(), ok; true -> - rabbit_misc:local_info_msg("Already member of cluster: ~p~n", - [ClusterNodes]), + rabbit_log:info("Already member of cluster: ~p~n", [ClusterNodes]), {ok, already_member} end. @@ -193,12 +192,12 @@ join_cluster(DiscoveryNode, NodeType) -> %% persisted messages reset() -> ensure_mnesia_not_running(), - rabbit_misc:local_info_msg("Resetting Rabbit~n", []), + rabbit_log:info("Resetting Rabbit~n", []), reset_gracefully(). force_reset() -> ensure_mnesia_not_running(), - rabbit_misc:local_info_msg("Resetting Rabbit forcefully~n", []), + rabbit_log:info("Resetting Rabbit forcefully~n", []), wipe(). reset_gracefully() -> @@ -254,8 +253,8 @@ update_cluster_nodes(DiscoveryNode) -> %% nodes mnesia:delete_schema([node()]), rabbit_node_monitor:write_cluster_status(Status), - rabbit_misc:local_info_msg("Updating cluster nodes from ~p~n", - [DiscoveryNode]), + rabbit_log:info("Updating cluster nodes from ~p~n", + [DiscoveryNode]), init_db_with_mnesia(AllNodes, node_type(), true, true); false -> e(inconsistent_cluster) @@ -278,7 +277,7 @@ forget_cluster_node(Node, RemoveWhenOffline) -> {true, false} -> remove_node_offline_node(Node); {true, true} -> e(online_node_offline_flag); {false, false} -> e(offline_node_no_offline_flag); - {false, true} -> rabbit_misc:local_info_msg( + {false, true} -> rabbit_log:info( "Removing node ~p from cluster~n", [Node]), case remove_node_if_mnesia_running(Node) of ok -> ok; |