[OPEN-ILS-DEV] PATCH: log.[ch] (some cleanup; defaulting to stderr)

Scott McKellar mck9 at swbell.net
Sun Jun 24 22:51:25 EDT 2007


With this patch, the logging package will write log messages to
standard error if the application has not specified some other
log type.

1. In log.h I added another macro OSRF_LOG_TYPE_STDERR by which the
application can specifically request logging to standard error.

2. In log.c I initialze _osrfLogType to OSRF_LOG_TYPE_STDERR so that
the application can issue a log message even if it hasn't called 
osrfLogInit() yet.

3. I added the const qualifier to the parameters of the functions
_osrfLogToFile() and _osrfLogSetXid().

4. In osrfLogCleanup() I set _osrfLogAppname and _osrfLogFile to
NULL after freeing them.  Otherwise the application could cause
needless mischief by calling this function twice.

5. Also in osrfLogCleanup() I set _osrfLogType back to the default
OSRF_LOG_TYPE_STDERR so that the application can still issue a
message after calling osrfLogCleanup().

6. I rewrote osrfLogSetType() to use switch/case instead of an "if".
Now that we have three valid values to check instead of two, a
switch/case is a little tidier.  Also the default branch applies
the default log type OSRF_LOG_TYPE_STDERR.

7. _osrfLogDetail() had a local variable named "l" (lower case L).
I renamed it to "label" because "l" looks too much like a digit.

8.Also in _osrfLogDetail(): I added a branch to write a message to
stderr when _osrfLogType is OSRF_LOG_TYPE_STDERR.

9. The existing _osrfLogToFile function sizes and declares a buffer
named "buf", fills it with zeros, and then doesn't do anything with
it.  This buffer is probably a relic of some earlier version. I
eliminated it.

10. A few lines thereafter, I eliminated a useless call to bzero().

11. The call to strftime() contained a hard-coded buffer size.  I
changed it to use the sizeof operator, so that the buffer size is
defined in only one place.

12. If we can't open the log file, we write a message to stderr.
In this message I changed "file" to "log file" to make the meaning
more clear to a benighted and panicky user.

13. If after writing the message we can't close the file, the
existing code logs an error message by calling osrfLogWarning().
However in this circumstance this latter message will probably meet
the same fate, and no one will ever see it.  I changed the code so
as to write this message to stderr.

-------

I have not yet provided a way for the application to temporarily
route log messages to standard output, for convenience in development
and debugging.  I expect to do that in a later patch.

Scott McKellar
http://home.swbell.net/mck9/aargh/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: log_h_2.patch
Type: text/x-patch
Size: 335 bytes
Desc: 765534414-log_h_2.patch
Url : http://list.georgialibraries.org/pipermail/open-ils-dev/attachments/20070624/601bea06/log_h_2.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: log_c_3.patch
Type: text/x-patch
Size: 6591 bytes
Desc: 2243590157-log_c_3.patch
Url : http://list.georgialibraries.org/pipermail/open-ils-dev/attachments/20070624/601bea06/log_c_3.bin


More information about the Open-ils-dev mailing list