Преглед на файлове

Truncate logs that is too long

terry-xiaoyu преди 6 години
родител
ревизия
a8d2497480
променени са 2 файла, в които са добавени 17 реда и са изтрити 1 реда
  1. 6 0
      etc/emqx.conf
  2. 11 1
      priv/emqx.schema

+ 6 - 0
etc/emqx.conf

@@ -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

+ 11 - 1
priv/emqx.schema

@@ -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),