I'm trying to create a log helper, and want to concatenate the line number to the log info.
I want to accomplish a Log like this: (" -l:" + LINE + args)
05-22 15:04:16.626 21270-22699/com.mydomain.myproject D/myfile.c: -l:5 myloginfo ...
This is what I have in my loghelper.h file:
#ifdef __ANDROID__
#include <android/log.h>
#define FILETAG (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#define LINEIDENTIFIER ' -l:'
#define TOKENAPPEND(x, y, z) x##y##z
#define APPENDLINE(x, y, z) TOKENAPPEND(x, y, z)
#define printf(fmt,args...) __android_log_print(ANDROID_LOG_DEBUG, FILETAG , fmt, APPENDLINE(LINEIDENTIFIER, __LINE__, ##args))
#define printfe(fmt,args...) __android_log_print(ANDROID_LOG_ERROR, FILETAG, fmt, APPENDLINE(LINEIDENTIFIER, __LINE__, ##args))
#define printfw(fmt,args...) __android_log_print(ANDROID_LOG_WARN, FILETAG, fmt, APPENDLINE(LINEIDENTIFIER, __LINE__, ##args))
#endif
calling from myfile.c like this:
#include "loghelper.h"
...
printf(" myloginfo %s", "...");
I'm getting the following error:
error: pasting formed '' -l:'52', an invalid preprocessing token
error: expected ')'
error: too many arguments provided to function-like macro invocation
error: use of undeclared identifier 'APPENDLINE'
error: pasting formed '57"success!"', an invalid preprocessing token
error: expected ')'
Q: What am I doing wrong? What should I change to make it work?