Truncate logs that is too long

This commit is contained in:
terry-xiaoyu 2019-04-19 16:33:48 +08:00 committed by turtleDeng
parent bcbb4b68e9
commit a8d2497480
2 changed files with 17 additions and 1 deletions

View File

@ -368,6 +368,12 @@ log.dir = {{ platform_log_dir }}
## Default: emqx.log
log.file = emqx.log
## Limits the total number of characters printed for each log event.
##
## Value: Integer
## Default: 1024
log.chars_limit = 1024
## Maximum size of each log file.
##
## Value: Number

View File

@ -420,6 +420,11 @@ end}.
{datatype, file}
]}.
{mapping, "log.chars_limit", "log.chars_limit", [
{default, 1024},
{datatype, integer}
]}.
{mapping, "log.rotation.size", "kernel.logger", [
{default, "10MB"},
{datatype, bytesize}
@ -464,6 +469,10 @@ end}.
{translation, "kernel.logger", fun(Conf) ->
LogTo = cuttlefish:conf_get("log.to", Conf),
LogLevel = cuttlefish:conf_get("log.level", Conf),
CharsLimit = case cuttlefish:conf_get("log.chars_limit", Conf) of
-1 -> unlimited;
V -> V
end,
Formatter = {emqx_logger_formatter,
#{template =>
[time," [",level,"] ",
@ -474,7 +483,8 @@ end}.
[{peername,
[peername," "],
[]}]},
msg,"\n"]}},
msg,"\n"],
chars_limit => CharsLimit}},
FileConf = fun(Filename) ->
#{type => wrap,
file => filename:join(cuttlefish:conf_get("log.dir", Conf), Filename),