Skip to content

Commit fac28a9

Browse files
committed
Fix #473: handle log_wrap_size of 0
Setting log_wrap_size to 0 is supposed to disable log rotation, but logger_std_h requires max_no_bytes to be set to the atom infinity for this case. Adjust yaws_log to handle size 0 correctly. Add a new test to gconf_SUITE that covers this case.
1 parent 5bb41c2 commit fac28a9

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

src/yaws_log.erl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,9 @@ code_change(_OldVsn, Data, _Extra) ->
401401
%%%----------------------------------------------------------------------
402402
report_logger_config(File, RotateSize) ->
403403
RotateConf =
404-
case is_integer(RotateSize) of
405-
true ->
404+
case RotateSize of
405+
0 -> #{max_no_bytes => infinity};
406+
I when is_integer(I), I > 0 ->
406407
#{
407408
max_no_bytes => RotateSize,
408409
max_no_files => 2

testsuite/gconf_SUITE.erl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ all() ->
88
[
99
setup_default_gconf,
1010
set_gc_flags,
11-
setup_mime_types_info
11+
setup_mime_types_info,
12+
log_wrap_size_zero
1213
].
1314

1415
groups() ->
@@ -28,9 +29,23 @@ init_per_group(_Group, Config) ->
2829
end_per_group(_Group, _Config) ->
2930
ok.
3031

32+
init_per_testcase(log_wrap_size_zero, Config) ->
33+
WWW = filename:join(?tempdir(?MODULE), "www"),
34+
ok = testsuite:create_dir(WWW),
35+
Id = "testsuite-server",
36+
YConf = filename:join(?tempdir(?MODULE), "yaws.conf"),
37+
application:load(yaws),
38+
application:set_env(yaws, id, Id),
39+
application:set_env(yaws, conf, YConf),
40+
ok = yaws:start(),
41+
[{yaws_id, Id}, {yaws_config, YConf} | Config];
3142
init_per_testcase(_Test, Config) ->
3243
Config.
3344

45+
end_per_testcase(log_wrap_size_zero, _Config) ->
46+
ok = application:stop(yaws),
47+
ok = application:unload(yaws),
48+
ok;
3449
end_per_testcase(_Test, _Config) ->
3550
ok.
3651

@@ -104,6 +119,12 @@ setup_mime_types_info(_Config) ->
104119
?assertEqual("/etc/mime.types", MI),
105120
ok.
106121

122+
log_wrap_size_zero(_Config) ->
123+
%% Nothing to do. If we get here, init succeeded, which means the
124+
%% log_wrap_size configuration value of 0 was accepted. See bug
125+
%% #473.
126+
ok.
127+
107128
%% =======================================================================
108129
get_gconf_attr(Name, GConf) ->
109130
Fun = list_to_atom("gconf_" ++ atom_to_list(Name)),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
logdir = $logdir$
2+
3+
ebin_dir = $data_builddir$
4+
5+
# Verify 0 as a valid log_wrap_size (bug #473)
6+
log_wrap_size = 0
7+
log_resolve_hostname = false
8+
fail_on_bind_err = true
9+
pick_first_virthost_on_nomatch = true
10+
keepalive_timeout = 10000
11+
12+
<server localhost>
13+
listen = 127.0.0.1
14+
port = $yaws_port1$
15+
docroot = $tempdir$/www
16+
</server>

0 commit comments

Comments
 (0)