aharren / LibComponentLogging-Core

A small logging library for Objective-C applications (Mac OS X and iPhone OS/iOS) which provides conditional logging based on log levels and log components. Additionally, different logging strategies can be used, e.g. writing log messages to a file or sending them to the system log, while using the same logging interface.
http://0xc0.de/LibComponentLogging
110 stars 11 forks source link

Support namespacing for multiple libraries? #22

Closed djMax closed 6 months ago

djMax commented 11 years ago

I'm trying to use LibComponentLogging in a library/framework that is used by an app that also wants to use LCL. I'm not sure it's currently possible to have both the library and the app define components and use LCL properly... Would be nice if it worked.

aharren commented 11 years ago

You can run lcl_embed on the LibComponentLogging files of your library/framework, see http://0xc0.de/LibComponentLogging#embedded. lcl_embed will add your unique namespace prefix to all symbols such that the LibComponentLogging version in your library/framework doesn't conflict with an application that uses your library/framework and LibComponentLogging.

djMax commented 11 years ago

Is there any way to do this with a preprocessor macro instead? If not I'll close the issue, but seems like it'd be nice to use one version of the code.

aharren commented 11 years ago

When using LibComponentLogging privately in a framework, then it's usually enough to just use the preprocessor macro of the back-end's config file to rename the Objective-C class of the back-end, e.g. the #define LCLLogFile <UniquePrefix>LCLLogFile in your framework's LCLLogFileConfig.h file. If the application also brings a copy of LibComponentLogging and LCLLogFile, then you would get 2 log files: one for the application, and one for your framework. Problems arise when you want to expose the log macros to your framework's users, e.g. then you might get 2 definitions of the lcl_log macros. Here, the renaming via lcl_embed would help.