diff options
author | Tony Garnock-Jones <tonyg@lshift.net> | 2008-07-03 13:35:11 +0100 |
---|---|---|
committer | Tony Garnock-Jones <tonyg@lshift.net> | 2008-07-03 13:35:11 +0100 |
commit | 675869a27714307bce377638dfe8f6a5f069e757 (patch) | |
tree | e4f9872242be02145702775f5c563f2b246f57ce /src/rabbit_error_logger.erl | |
download | rabbitmq-server-git-675869a27714307bce377638dfe8f6a5f069e757.tar.gz |
Initial commit, from repo-rebase-20080703121916_default (e96543d904a2)
Diffstat (limited to 'src/rabbit_error_logger.erl')
-rw-r--r-- | src/rabbit_error_logger.erl | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/rabbit_error_logger.erl b/src/rabbit_error_logger.erl new file mode 100644 index 0000000000..0ae116bb2a --- /dev/null +++ b/src/rabbit_error_logger.erl @@ -0,0 +1,77 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License at +%% http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +%% License for the specific language governing rights and limitations +%% under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developers of the Original Code are LShift Ltd., +%% Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd. +%% +%% Portions created by LShift Ltd., Cohesive Financial Technologies +%% LLC., and Rabbit Technologies Ltd. are Copyright (C) 2007-2008 +%% LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit +%% Technologies Ltd.; +%% +%% All Rights Reserved. +%% +%% Contributor(s): ______________________________________. +%% + +-module(rabbit_error_logger). +-include("rabbit.hrl"). + +-define(LOG_EXCH_NAME, <<"amq.rabbitmq.log">>). + +-behaviour(gen_event). + +-export([init/1, terminate/2, code_change/3, handle_call/2, handle_event/2, handle_info/2]). + +init([DefaultVHost]) -> + #exchange{} = rabbit_exchange:declare( + #resource{virtual_host = DefaultVHost, + kind = realm, + name = <<"/admin">>}, + ?LOG_EXCH_NAME, + topic, true, false, []), + {ok, #resource{virtual_host = DefaultVHost, + kind = exchange, + name = ?LOG_EXCH_NAME}}. + +terminate(_Arg, _State) -> + terminated_ok. + +code_change(_OldVsn, State, _Extra) -> + {ok, State}. + +handle_call(_Request, State) -> + {ok, not_understood, State}. + +handle_event({Kind, _Gleader, {_Pid, Format, Data}}, State) -> + ok = publish(Kind, Format, Data, State), + {ok, State}; +handle_event(_Event, State) -> + {ok, State}. + +handle_info(_Info, State) -> + {ok, State}. + +publish(error, Format, Data, State) -> + publish1(<<"error">>, Format, Data, State); +publish(warning_msg, Format, Data, State) -> + publish1(<<"warning">>, Format, Data, State); +publish(info_msg, Format, Data, State) -> + publish1(<<"info">>, Format, Data, State); +publish(_Other, _Format, _Data, _State) -> + ok. + +publish1(RoutingKey, Format, Data, LogExch) -> + {ok, _QueueNames} = rabbit_exchange:simple_publish( + false, false, LogExch, RoutingKey, <<"text/plain">>, + list_to_binary(io_lib:format(Format, Data))), + ok. |