[erlang-questions] Logging in port drivers

Michael Truog mjtruog@REDACTED
Tue Mar 13 22:11:10 CET 2012

On 03/13/2012 11:57 AM, Alexey Romanov wrote:
> What are best practices on logging in C code for port
> drivers/NIFs/etc.? Obviously, what I currently do in
> https://github.com/alexeyr/erlang-sqlite3/blob/master/c_src/sqlite3_drv.c
> is bad (especially in multiuser environment). But how _should_ it be
> done instead
If you have a port driver that uses the async thread pool, it will be similar to the Erlang file API.  That way you don't delay the scheduler thread.  If you want a simpler way of making a port driver do this, you can use GEPD: https://github.com/okeuday/generic-erlang-port--driver-

You would just need to take care of the thread-safety concerns, which should be obvious.  You also could always create your own thread pool, but I don't see any added benefit here, just more complication.  The only problem with the async thread pool approach is you could log enough that you hog the async thread queues, which prevents usage elsewhere... the only solution to that is making the number of async threads higher.  With file writes that shouldn't get blocked (just will be randomly slow, unless there is an immediate failure) that doesn't seem to be a problem you should encounter.

- Michael

More information about the erlang-questions mailing list