Skip to content

Commit fd0bf45

Browse files
committed
Validate log.*.formatter.depth and document its floor
The `log.*.formatter.depth` mappings accept any integer, so a misconfiguration such as `depth = 0` or a negative value passes schema validation and is then silently clamped to 5. This is inconsistent with the sibling `log.error_logger_format_depth` mapping, which rejects non-positive values. Add a `formatter_depth` validator that accepts `unlimited` or a positive integer, and apply it to all four formatter depth mappings (console, exchange, syslog, file). Document in `translate_generic_conf/2` that an explicit depth is floored at 5, matching OTP's `logger_formatter:get_depth/1`, so the clamp is no longer undocumented.
1 parent 05af8b8 commit fd0bf45

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

deps/rabbit/priv/schema/rabbit.schema

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,8 @@ end}.
16611661
]}.
16621662
{mapping, "log.console.formatter.depth", "rabbit.log.console.formatter", [
16631663
{default, unlimited},
1664-
{datatype, [{atom, unlimited}, integer]}
1664+
{datatype, [{atom, unlimited}, integer]},
1665+
{validators, ["formatter_depth"]}
16651666
]}.
16661667
{mapping, "log.console.formatter.plaintext.format", "rabbit.log.console.formatter", [
16671668
{default, "$time [$level] $pid $msg"},
@@ -1704,7 +1705,8 @@ end}.
17041705
]}.
17051706
{mapping, "log.exchange.formatter.depth", "rabbit.log.exchange.formatter", [
17061707
{default, unlimited},
1707-
{datatype, [{atom, unlimited}, integer]}
1708+
{datatype, [{atom, unlimited}, integer]},
1709+
{validators, ["formatter_depth"]}
17081710
]}.
17091711
{mapping, "log.exchange.formatter.plaintext.format", "rabbit.log.exchange.formatter", [
17101712
{default, "$time [$level] $pid $msg"},
@@ -1763,7 +1765,8 @@ end}.
17631765
]}.
17641766
{mapping, "log.syslog.formatter.depth", "rabbit.log.syslog.formatter", [
17651767
{default, unlimited},
1766-
{datatype, [{atom, unlimited}, integer]}
1768+
{datatype, [{atom, unlimited}, integer]},
1769+
{validators, ["formatter_depth"]}
17671770
]}.
17681771
{mapping, "log.syslog.formatter.plaintext.format", "rabbit.log.syslog.formatter", [
17691772
{default, "$msg"},
@@ -2005,7 +2008,8 @@ end}.
20052008
]}.
20062009
{mapping, "log.file.formatter.depth", "rabbit.log.file.formatter", [
20072010
{default, unlimited},
2008-
{datatype, [{atom, unlimited}, integer]}
2011+
{datatype, [{atom, unlimited}, integer]},
2012+
{validators, ["formatter_depth"]}
20092013
]}.
20102014
{mapping, "log.file.formatter.plaintext.format", "rabbit.log.file.formatter", [
20112015
{default, "$time [$level] $pid $msg"},
@@ -3122,6 +3126,12 @@ fun(Int) when is_integer(Int) ->
31223126
Int >= 1
31233127
end}.
31243128

3129+
{validator, "formatter_depth", "should be positive integer or 'unlimited'",
3130+
fun(unlimited) -> true;
3131+
(Int) when is_integer(Int) -> Int >= 1;
3132+
(_) -> false
3133+
end}.
3134+
31253135
{validator, "positive_16_bit_unsigned_integer", "number should be between 1 and 65535",
31263136
fun(Int) when is_integer(Int) ->
31273137
(Int >= 1) and (Int =< 16#ff_ff)

deps/rabbitmq_prelaunch/src/rabbit_prelaunch_early_logging.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ translate_generic_conf(Var, Conf) ->
269269
%% sub-terms to `...'. `unlimited' (or an unset key) means "no
270270
%% explicit depth"; in that case we fall back to the deprecated
271271
%% `error_logger_format_depth' kernel variable, the same way OTP's
272-
%% `logger_formatter:get_depth/1' does.
272+
%% `logger_formatter:get_depth/1' does. As in OTP, an explicit depth
273+
%% is floored at 5, so configured values below 5 are raised to 5.
273274
Depth = case cuttlefish:conf_get(Var ++ ".depth", Conf, unlimited) of
274275
unlimited -> error_logger:get_format_depth();
275276
D -> max(5, D)

0 commit comments

Comments
 (0)