Closed dangra closed 1 year ago
What we'll want to do here is not use that fprintf
, but instead we'll need to take that error string that is emitted by sqlite, and notify erlang somehow with the message.
There is a function in the sqlite3_nif.c
called make_binary(env, the_string, length_of_string)
. This will return the ERL_NIF_TERM
which we can then enif_send
to a pid.
We'll need to stand up a listener for this.
This does tie into #192 somewhat where we should probably spin up one process instance.
@dangra What are you thinking about with consuming the log messages? Were you just wanting to dump to Logger
and friends? Or were you wanting to monitor the events pushed out via a handler of some sort?
@warmwaffles I haven't had the time to look at it and honestly lack the experience with NIFs and Elixir, to me it is all new stuff. Not making excuses! just setting expectations here, if the open PR bothers you, I am ok closing it for now and resubmit once I have something that integrates your feedback.
that said, my only goal was to log the messages so in case of this type of errors, I can tail logs and see what sqlite3.c function and line have error'ed. I don't have the need to push the events to a handler of any type.
@dangra I was going to implement this using the methods I outlined above. We shouldn't be printing to stdout using the NIF. We risk interleaving output in a highly concurrent environment.
👋
I've opened a PR with the suggested changes (send binary to pid): https://github.com/elixir-sqlite/exqlite/pull/266 (merged)
I mostly wanted to make sure this feature would work after https://github.com/elixir-sqlite/exqlite/issues/192 and one way to do that was to add set_log_hook/1
in master
with some tests :)
I am submitting this change looking for directions on what could be the best way to integrate it into official exqlite release. This particular change has been extremely useful when debugging errors on applications that use LiteFS and I am sure could be useful to others.
From sqlite docs: