summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHubert Plociniczak <hubert@lshift.net>2008-09-03 15:44:56 +0100
committerHubert Plociniczak <hubert@lshift.net>2008-09-03 15:44:56 +0100
commit38616df03ffeac5984a3edd515e89de7be5b8db6 (patch)
tree0a6d01a0091b0ad8d5ab0ac8dbac0efaa0904c2b
parentc0c4eb35c0f0fde780603aae8f8f42b951cb5676 (diff)
downloadrabbitmq-server-38616df03ffeac5984a3edd515e89de7be5b8db6.tar.gz
Renamed logs_location/1 function to log_location/1.
Added more test cases to cover problems with logging during startup.
-rw-r--r--src/rabbit.erl16
-rw-r--r--src/rabbit_tests.erl71
2 files changed, 69 insertions, 18 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl
index 5190fd58..2d309c05 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -31,7 +31,7 @@
-export([start/2, stop/1]).
--export([logs_location/1]).
+-export([log_location/1]).
-import(application).
-import(mnesia).
@@ -59,7 +59,7 @@
[{running_applications, [{atom(), string(), string()}]} |
{nodes, [node()]} |
{running_nodes, [node()]}]).
--spec(logs_location/1 :: ('sasl' | 'kernel') -> log_location()).
+-spec(log_location/1 :: ('sasl' | 'kernel') -> log_location()).
-endif.
@@ -93,10 +93,10 @@ status() ->
rotate_logs(BinarySuffix) ->
Suffix = binary_to_list(BinarySuffix),
- log_rotation_result(rotate_logs(logs_location(kernel),
+ log_rotation_result(rotate_logs(log_location(kernel),
Suffix,
rabbit_error_logger_file_h),
- rotate_logs(logs_location(sasl),
+ rotate_logs(log_location(sasl),
Suffix,
rabbit_sasl_report_file_h)).
@@ -203,7 +203,7 @@ stop(_State) ->
%---------------------------------------------------------------------------
-logs_location(Type) ->
+log_location(Type) ->
case application:get_env(Type, case Type of
kernel -> error_logger;
sasl -> sasl_error_logger
@@ -226,7 +226,7 @@ print_banner() ->
?PROTOCOL_VERSION_MAJOR, ?PROTOCOL_VERSION_MINOR,
?COPYRIGHT_MESSAGE, ?INFORMATION_MESSAGE]),
io:format("Logging to ~p~nSASL logging to ~p~n~n",
- [logs_location(kernel), logs_location(sasl)]).
+ [log_location(kernel), log_location(sasl)]).
@@ -241,13 +241,13 @@ ensure_working_log_handlers() ->
ok = ensure_working_log_handler(error_logger_file_h,
rabbit_error_logger_file_h,
error_logger_tty_h,
- logs_location(kernel),
+ log_location(kernel),
Handlers),
ok = ensure_working_log_handler(sasl_report_file_h,
rabbit_sasl_report_file_h,
sasl_report_tty_h,
- logs_location(sasl),
+ log_location(sasl),
Handlers),
ok.
diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl
index 59bd9d70..34eebec1 100644
--- a/src/rabbit_tests.erl
+++ b/src/rabbit_tests.erl
@@ -42,6 +42,7 @@ all_tests() ->
passed = test_topic_matching(),
passed = test_log_management(),
passed = test_app_management(),
+ passed = test_log_management_during_startup(),
passed = test_cluster_management(),
passed = test_user_management(),
passed.
@@ -140,8 +141,8 @@ test_app_management() ->
passed.
test_log_management() ->
- MainLog = rabbit:logs_location(kernel),
- SaslLog = rabbit:logs_location(sasl),
+ MainLog = rabbit:log_location(kernel),
+ SaslLog = rabbit:log_location(sasl),
Suffix = ".1",
%% prepare basic logs
@@ -178,15 +179,13 @@ test_log_management() ->
ok = make_files_non_writable([MainLog]),
{error, {cannot_rotate_main_logs, _}} = control_action(rotate_logs, []),
ok = clean_logs([MainLog], Suffix),
- ok = error_logger:add_report_handler(rabbit_error_logger_file_h,
- MainLog),
+ ok = add_log_handlers([{rabbit_error_logger_file_h, MainLog}]),
%% original sasl log file is not writable
ok = make_files_non_writable([SaslLog]),
{error, {cannot_rotate_sasl_logs, _}} = control_action(rotate_logs, []),
ok = clean_logs([SaslLog], Suffix),
- ok = error_logger:add_report_handler(rabbit_sasl_report_file_h,
- SaslLog),
+ ok = add_log_handlers([{rabbit_sasl_report_file_h, SaslLog}]),
%% logs with suffix are not writable
ok = control_action(rotate_logs, [Suffix]),
@@ -215,10 +214,52 @@ test_log_management() ->
%% cleanup
ok = application:set_env(sasl, sasl_error_logger, {file, SaslLog}),
ok = application:set_env(kernel, error_logger, {file, MainLog}),
- ok = error_logger:add_report_handler(rabbit_error_logger_file_h,
- MainLog),
- ok = error_logger:add_report_handler(rabbit_sasl_report_file_h,
- SaslLog),
+ ok = add_log_handlers([{rabbit_error_logger_file_h, MainLog},
+ {rabbit_sasl_report_file_h, SaslLog}]),
+ passed.
+
+test_log_management_during_startup() ->
+ MainLog = rabbit:log_location(kernel),
+ SaslLog = rabbit:log_location(sasl),
+
+ %% start application with simple tty logging
+ ok = control_action(stop_app, []),
+ ok = application:set_env(kernel, error_logger, tty),
+ ok = application:set_env(sasl, sasl_error_logger, tty),
+ ok = add_log_handlers([{error_logger_tty_h, []},
+ {sasl_report_tty_h, []}]),
+ ok = control_action(start_app, []),
+
+ %% start application with tty logging and
+ %% proper handlers not installed
+ ok = control_action(stop_app, []),
+ ok = error_logger:tty(false),
+ ok = delete_log_handlers([sasl_report_tty_h]),
+ ok = case catch control_action(start_app, []) of
+ ok -> exit(got_success_but_expected_failure);
+ {error, {cannot_start_application, rabbit, _}} -> ok
+ end,
+
+ %% fix sasl logging
+ ok = application:set_env(sasl, sasl_error_logger,
+ {file, SaslLog}),
+
+ %% start application with logging to invalid directory
+ TmpLog = "/tmp/rabbit-tests/test.log",
+ file:delete(TmpLog),
+ ok = application:set_env(kernel, error_logger, {file, TmpLog}),
+
+ ok = delete_log_handlers([rabbit_error_logger_file_h]),
+ ok = add_log_handlers([{error_logger_file_h, MainLog}]),
+ ok = case catch control_action(start_app, []) of
+ ok -> exit(got_success_but_expected_failure);
+ {error, {cannot_start_application, rabbit, _}} -> ok
+ end,
+
+ %% cleanup
+ ok = add_log_handlers([{error_logger_file_h, MainLog}]),
+ ok = application:set_env(kernel, error_logger, {file, MainLog}),
+ ok = control_action(start_app, []),
passed.
test_cluster_management() ->
@@ -465,3 +506,13 @@ make_files_non_writable(Files) ->
[ok = file:write_file_info(File, #file_info{mode=0}) ||
File <- Files],
ok.
+
+add_log_handlers(Handlers) ->
+ [ok = error_logger:add_report_handler(Handler, Args) ||
+ {Handler, Args} <- Handlers],
+ ok.
+
+delete_log_handlers(Handlers) ->
+ [[] = error_logger:delete_report_handler(Handler) ||
+ Handler <- Handlers],
+ ok.