libcgi
libcgi copied to clipboard
rewrite logging
Currently there's libcgi_error()
which is used in numerous places around the whole library. If the global variable cgi_display_errors
contains true it prints HTML markup to stdout containing the error message. If the passed error code is E_FATAL
or E_MEMORY
(defined in src/error.h
) it even calls cgi_end()
and exit()
.
Besides the obvious sudden exit which may be bad (do we need this?) I consider it bad to print anything to stdout where my content should go to. The used HTML tags could be invalid if not printed at the right time or even break correct markup. (They do e.g. when using sessions if there's a session cookie but no session file.)
A flexible solution could work like in libabc or we could just print to stderr, which some webservers can append to their logfiles (others return HTTP status 500 or mix stdout/stderr and return it to the browser).
I really like the idea to rework the logging mechanism in the way libabc does. I want to implement this. But I would like to know if you would like to have a library context which is passed to every function or to have this globally.
Also this would fix #53 as well, right?
Introducing a library handle or context would be nice in the long run, but most probably an API change and therefor topic for API v2 which would be major rework. Although not that elegant, I would opt for a solution keeping the current API for now.
I can not answer the question on error handling from the top of my head. Must look into this deeper.