Cyril Plisko wrote:
> While browsing sources under usr/src/uts I noticed that many
> modules are reimplementing some sort of debug printf-like
> functionality all over again. In many cases it looks like one
> framework copying the defines from the other changing only
> a prefix. Wouldn't it be beneficial for the kernel to have some
> sort of generic DPRINTF/dprintf functionality, available to all
> the components ? IMHO, besides overall cleanness it will
> also allow developers to concentrate on their specific tasks
> instead of re-inventing the wheel again and again.
> 
> May be there is something similar on the way already ?

The mozilla codebase uses an interesting example (see
http://lxr.mozilla.org/seamonkey/source/nsprpub/pr/include/prlog.h for
the main header) which creates a "logging handle" (via
|PR_NewLogModule("module_name1");|) at (component/module) startup if a
matching environment variable is set (e.g.
"NSPR_LOG_MODULES=module_name1:debug_level,module_name2:debug_level").

After setting this handle up consumers can use things like
|PR_LOG(loghandle, PR_LOG_DEBUG, (printf_list_fmt_string, more, args,
come, here, ...));| to log debug messages.

The design has the advantage that the logging infratructure gets setup
only once, including optional rediction to files etc. If no logging is
requested  the |handle| remains |NULL| and no resources and (almost) no
CPU overhead is required (many other |mydebug_printf()| implementations
don't care about this detail and always calculate arguments (which may
be expensive in some cases)).

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [EMAIL PROTECTED]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 7950090
 (;O/ \/ \O;)
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to