0

I'm setting up some macros for Logging purposes.

#define LOG_NETWORK_DEBUG(...)    LogMessageF(__FILE__,__LINE__,__FUNCTION__,@"Network",2,__VA_ARGS__)
#define LOG_NETWORK_INFO(...)    LogMessageF(__FILE__,__LINE__,__FUNCTION__,@"Network",1,__VA_ARGS__)
#define LOG_NETWORK_ERROR(...)    LogMessageF(__FILE__,__LINE__,__FUNCTION__,@"Network",0,__VA_ARGS__)


#define LOG_MEDIA_DEBUG(...)    LogMessageF(__FILE__,__LINE__,__FUNCTION__,@"Media",2,__VA_ARGS__)
#define LOG_MEDIA_INFO(...)    LogMessageF(__FILE__,__LINE__,__FUNCTION__,@"Media",1,__VA_ARGS__)
#define LOG_MEDIA_ERROR(...)    LogMessageF(__FILE__,__LINE__,__FUNCTION__,@"Media",0,__VA_ARGS__)

However, since my code is currently infested with with NSLog calls, I want to transfer the NSLog calls to LogMessageF calls. (till I have time to migrate all my code to above macros) My project for iOS is currently comprised of 2 sub projects: Network, Media.

I want each NSLog calls to be converted to the appropriate Macro. (NSLog calls in the Media project would be converted to LOG_MEDIA_DEBUG).

I thought about setting a preprocessor macros in Xcode for each project called PROJ_NAME that will include the project name.

My question is how to use that Macro? I want to do something like this:

#define NSLog(...) LOG_$PROJ_NAME_DEBUG(__VA_ARGS__)

1 Answer 1

1

You can use (token concatenation). HELPER macro is used to evaluate PROJ_NAME macro before concatenation.

#define PROJ_NAME NETWORK

#define LOG_DEBUG(P) LOG_##P##_DEBUG
#define HELPER(X) LOG_DEBUG(X)
#define NSLog(...) HELPER(PROJ_NAME)(__VA_ARGS__)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.