libosmocore / logging from within libraries
meierk at informatik.uni-freiburg.de
Mon Jun 27 11:32:58 UTC 2011
27.06.2011 11:00, schrieb Harald Welte:
> As more and more code is moving into libraries (like I just did with the
> LAPDm code, and like pablo is working on with libosmo-abis), we needed a
> solution how to allocate and use the LOGP subsystem constants like DRSL,
> DRR, ... from within libraries.
> The existing logging code wasn't really prepared for that. I've now
> come um with a hack to extend it while preserving compatibility to
> * we use negative numbers starting from -1 for library-internal
> * those numbers get converted to a positive index into the various
> arrays at run-time. So -1 ends up one entry higher in the array
> than the last application-providede log category/subsystem.
> As part of this change, the array allocations are now dynamic, i.e there
> is no maximum limit for the number of log categories that an application
> can register with the core.
> Only for libraries (even outside libosmocore), we have compile-time
> registration, i.e. the 'struct log_info_cat' and the D* constant need to
> be defined inside libosmocore. I think this is an acceptable
> Furthermore, if LOGP()/DEBUGP() ever see a subsystem number that it
> doesn't know, it will assign it to the new 'DLGLOBAL' (Debug Library
> GLOBAL) category, i.e. there cna be no array overflows.
> This ensures that even an external library using a 'newer' D* constant
> will not crash or otherwise fail, it will simply log in a slightly
> different way.
Quick fix for openbsc:
index 6800021..fb5ce7a 100644
@@ -25,7 +25,7 @@ int main(int argc, char **argv)
struct log_target *stderr_target;
+ log_init(&log_info, NULL);
stderr_target = log_target_create_stderr();
More information about the baseband-devel