anchor.diff:             true ->
                   ""
           end,
  -    truncate([B,MsgStr,A],maps:get(max_size,Config)).
  +    truncate(B,MsgStr,A,maps:get(max_size,Config)).
  +
  +trim([H|T],Rev) when H==$\s; H==$\r; H==$\n ->
  +    trim(T,Rev);
  +trim([H|T],false) when is_list(H) ->
  +    case trim(H,false) of
  +        [] ->
  +            trim(T,false);
  +        TrimmedH ->
  +            [TrimmedH|T]
  +    end;
  +trim([H|T],true) when is_list(H) ->
  +    case trim(lists:reverse(H),true) of
  +        [] ->
  +            trim(T,true);
  +        TrimmedH ->
  +            [lists:reverse(TrimmedH)|T]
  +    end;
  +trim(String,_) ->
  +    String.
   
   do_format(Level,Data,[level|Format],Config) ->
       [to_string(level,Level,Config)|do_format(Level,Data,Format,Config)];
  
positive.code:             throw(Error)
      end.
  
  truncate(String,unlimited) ->
      String;
  truncate(String,Size) ->
      Length = string:length(String),
      if Length>Size ->
              case lists:reverse(lists:flatten(String)) of
                  [$\n|_] ->
                      string:slice(String,0,Size-4)++"...\n";
                  _ ->
                      string:slice(String,0,Size-3)++"..."
              end;
         true ->
              String
      end.
  
  %% SysTime is the system time in microseconds
  
negative.code:                     true ->
                          %% Trim leading and trailing whitespaces, and replace
                          %% newlines with ", "
                          T = lists:reverse(
                                trim(
                                  lists:reverse(
                                    trim(MsgStr0,false)),true)),
                          re:replace(T,",?\r?\n\s*",", ",
                                     [{return,list},global,unicode]);
                      _false ->
                          MsgStr0
  