diff options
author | Serge Aleynikov <[email protected]> | 2014-04-20 12:37:57 -0400 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2015-05-28 13:34:45 +0200 |
commit | 885ad5783c33d7f6115c5ad55c401102f10039d6 (patch) | |
tree | b74e9cbc55f22cb5f797ff37be50c964ca354a41 /lib/sasl | |
parent | ce96ab6d64768cd6536011ccdecc08191c238220 (diff) | |
download | otp-885ad5783c33d7f6115c5ad55c401102f10039d6.tar.gz otp-885ad5783c33d7f6115c5ad55c401102f10039d6.tar.bz2 otp-885ad5783c33d7f6115c5ad55c401102f10039d6.zip |
Customize SASL error_logger file opening modes
Include the ability to open a SASL error log file in append mode
at startup vs currently implemented "rewrite-always" mode.
Diffstat (limited to 'lib/sasl')
-rw-r--r-- | lib/sasl/doc/src/sasl_app.xml | 7 | ||||
-rw-r--r-- | lib/sasl/src/sasl.erl | 8 | ||||
-rw-r--r-- | lib/sasl/src/sasl_report_file_h.erl | 4 | ||||
-rw-r--r-- | lib/sasl/test/sasl_SUITE.erl | 31 |
4 files changed, 40 insertions, 10 deletions
diff --git a/lib/sasl/doc/src/sasl_app.xml b/lib/sasl/doc/src/sasl_app.xml index 9c3c80bd13..572e550061 100644 --- a/lib/sasl/doc/src/sasl_app.xml +++ b/lib/sasl/doc/src/sasl_app.xml @@ -92,6 +92,13 @@ <item>Installs <c>sasl_report_file_h</c> in the error logger. This makes all reports go to the file <c>FileName</c>. <c>FileName</c> is a string.</item> + <tag><c>{file,FileName,Modes}</c></tag> + <item>Same as <c>{file,FileName}</c> except that the <c>Modes</c> + allows to specify the modes used for opening the <c>FileName</c> + given to the <seealso marker="kernel:file#open/2">file:open/2</seealso> + call. When not specified, the <c>Modes</c> defaults to <c>[write]</c>. + Use <c>[append]</c> for having the <c>FileName</c> open in append mode. + <c>FileName</c> is a string.</item> <tag><c>false</c></tag> <item> <p>No SASL error logger handler is installed.</p> diff --git a/lib/sasl/src/sasl.erl b/lib/sasl/src/sasl.erl index fdea6da13e..4a220f0511 100644 --- a/lib/sasl/src/sasl.erl +++ b/lib/sasl/src/sasl.erl @@ -55,7 +55,9 @@ get_sasl_error_logger() -> case application:get_env(sasl, sasl_error_logger) of {ok, false} -> undefined; {ok, tty} -> tty; - {ok, {file, File}} when is_list(File) -> {file, File}; + {ok, {file, File}} when is_list(File) -> {file, File, [write]}; + {ok, {file, File, Modes}} when is_list(File), is_list(Modes) -> + {file, File, Modes}; {ok, Bad} -> exit({bad_config, {sasl, {sasl_error_logger, Bad}}}); _ -> undefined end. @@ -125,9 +127,9 @@ delete_sasl_error_logger(Type) -> error_logger:delete_report_handler(mod(Type)). mod(tty) -> sasl_report_tty_h; -mod({file, _File}) -> sasl_report_file_h. +mod({file, _File, _Modes}) -> sasl_report_file_h. -args({file, File}, Type) -> {File, type(Type)}; +args({file, File, Modes}, Type) -> {File, Modes, type(Type)}; args(_, Type) -> type(Type). type(error) -> error; diff --git a/lib/sasl/src/sasl_report_file_h.erl b/lib/sasl/src/sasl_report_file_h.erl index f42b4b5ff2..a5bd0ac055 100644 --- a/lib/sasl/src/sasl_report_file_h.erl +++ b/lib/sasl/src/sasl_report_file_h.erl @@ -28,9 +28,9 @@ handle_event/2, handle_call/2, handle_info/2, terminate/2]). -init({File, Type}) -> +init({File, Modes, Type}) when is_list(Modes) -> process_flag(trap_exit, true), - case file:open(File, [write]) of + case file:open(File, Modes) of {ok,Fd} -> {ok, {Fd, File, Type}}; What -> diff --git a/lib/sasl/test/sasl_SUITE.erl b/lib/sasl/test/sasl_SUITE.erl index d7b99d506e..d9ab9e551c 100644 --- a/lib/sasl/test/sasl_SUITE.erl +++ b/lib/sasl/test/sasl_SUITE.erl @@ -26,10 +26,11 @@ %% Test cases must be exported. -export([app_test/1, appup_test/1, - log_mf_h_env/1]). + log_mf_h_env/1, + log_file/1]). all() -> - [log_mf_h_env, app_test, appup_test]. + [log_mf_h_env, log_file, app_test, appup_test]. groups() -> []. @@ -151,10 +152,9 @@ check_appup([],_,_) -> log_mf_h_env(Config) -> PrivDir = ?config(priv_dir,Config), LogDir = filename:join(PrivDir,sasl_SUITE_log_dir), - ok = file:make_dir(LogDir), + ok = filelib:ensure_dir(LogDir), application:stop(sasl), - SaslEnv = application:get_all_env(sasl), - lists:foreach(fun({E,_V}) -> application:unset_env(sasl,E) end, SaslEnv), + clear_env(sasl), ok = application:set_env(sasl,error_logger_mf_dir,LogDir), match_error(missing_config,application:start(sasl)), @@ -178,6 +178,23 @@ log_mf_h_env(Config) -> ok = application:set_env(sasl,error_logger_mf_dir,LogDir), ok = application:start(sasl). +log_file(Config) -> + PrivDir = ?config(priv_dir,Config), + LogDir = filename:join(PrivDir,sasl_SUITE_log_dir), + ok = filelib:ensure_dir(LogDir), + File = filename:join(LogDir, "file.log"), + application:stop(sasl), + clear_env(sasl), + + ok = application:set_env(sasl,sasl_error_logger,{file, File}, [{persistent, true}]), + ok = application:start(sasl), + application:stop(sasl), + ok = application:set_env(sasl,sasl_error_logger,{file, File, [append]}, [{persistent, true}]), + ok = application:start(sasl), + application:stop(sasl), + ok = application:set_env(sasl,sasl_error_logger, tty, [{persistent, false}]), + ok = application:start(sasl). + %%----------------------------------------------------------------- %% Internal @@ -185,3 +202,7 @@ match_error(Expected,{error,{bad_return,{_,{'EXIT',{Expected,{sasl,_}}}}}}) -> ok; match_error(Expected,Actual) -> ?t:fail({unexpected_return,Expected,Actual}). + +clear_env(App) -> + [application:unset_env(App,Opt) || {Opt,_} <- application:get_all_env(App)], + ok. |