Nebo15 / logger_json

JSON logger formatter with support for Google Cloud, DataDog and other for Elixir.

Home Page:https://nebo15.github.io/logger_json/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash on Jason.encode_to_iodata/2

damboscolo opened this issue · comments

Hello!

I am converting maps and tuples to string with data |> Kernel.inspect () before sending to Logger and I am having some crashes

I would like to send the logs in json format also, do you think it would be possible to change Jason.encode_to_iodata / 2 to Jason.decode or is there any way to log in as json?

Crashes

Jason.EncodeError
(Jason.EncodeError) invalid byte 0xE7 in <<67, 104, 101, 99, 107, 111, 117, 116, 115, 46, 68, 105, 112, 108, 111, 109, 97, 116, 46, 77, 101, 115, 115, 97, 103, 101, 115, 46, 79, 114, 100, 101, 114, 115, 32, 58, 111, 114, 100, 101, 114, 115, 32, 114, 101, 99, 101, 105, 118, 101, ...>>

and

ErlangError
(ErlangError) Erlang error: {:EXIT, {%Jason.EncodeError{message: "invalid byte 0xE7 in <<67, 104, 101, 99, 107, 111, 117, 116, 115, 46, 68, 105, 112, 108, 111, 109, 97, 116, 46, 77, 101, 115, 115, 97, 103, 101, 115, 46, 79, 114, 100, 101, 114, 115, 32, 58, 111, 114, 100, 101, 114, 115, 32, 114, 101, 99, 101, 105, 118, 101, ...>>"}, [{Jason, :encode_to_iodata!, 2, [file: 'lib/jason.ex', line: 199]}, {LoggerJSON, :format_event, 5, [file: 'lib/logger_json.ex', line: 299]}, {LoggerJSON, :log_event, 5, [file: 'lib/logger_json.ex', line: 234]}, {LoggerJSON, :handle_event, 2, [file: 'lib/logger_json.ex', line: 139]}, {:gen_event, :server_update, 4, [file: 'gen_event.erl', line: 577]}, {:gen_event, :server_notify, 4, [file: 'gen_event.erl', line: 559]}, {:gen_event, :handle_msg, 6, [file: 'gen_event.erl', line: 300]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}}

@damboscolo Hello. Can you provide a code snippet where you log something which leads to crash? I'll take look into it, just need a way to reproduce first :).

hey!

im formatting the log string before calling Logger.info () or Logger.error () like this:

  def format(env, map, key) when env in [:prod, :stag] and is_map(map), do:
    map
    |> Map.put(:key, key)
    |> Kernel.inspect()

  def format(env, value, key) when env in [:prod, :stag], do:
    "#{key}: #{Kernel.inspect(value)}"

these are the logs that generated the crashes, maybe these null values caused the problem? 🤔

{"cid":"aU9uVHJzZz0.dWZQNw","log":"Checkouts.Diplomat.Messages.Orders :orders received unexpected message in handle_info/2: {#Reference<0.4097939000.1447821313.2842>, {:ok, 1559947157}}\n","logging.googleapis.com/sourceLocation":{"file":null,"line":0,"function":null},"severity":"ERROR","time":"2019-06-07T17:39:18.413Z","user_uid":"13"}

{"cid":"aU9uVHJzZz0.dWZQNw","log":"Checkouts.Diplomat.Messages.Orders :orders received unexpected message in handle_info/2: {:DOWN, #Reference<0.4097939000.1447821313.2842>, :process, #PID<0.9685.0>, :normal}\n","logging.googleapis.com/sourceLocation":{"file":null,"line":0,"function":null},"severity":"ERROR","time":"2019-06-07T17:39:18.413Z","user_uid":"13"}

{"cid":"aU9uVHJzZz0.dWZQNw","log":"Checkouts.Diplomat.Messages.Orders :orders received unexpected message in handle_info/2: {:DOWN, #Reference<0.4097939000.1447821313.2839>, :process, #PID<0.9682.0>, :normal}\n","logging.googleapis.com/sourceLocation":{"file":null,"line":0,"function":null},"severity":"ERROR","time":"2019-06-07T17:39:18.413Z","user_uid":"13"}

Hey @damboscolo. Sorry for taking so long to respond. nils should be fine, it is more likely that some value not supported by Jason sneaked in, eg. pid, tuple or reference in the metadata.