Linux自定義printf/printk函式LOG_TAG
阿新 • • 發佈:2018-12-20
1.printf()自定義函式 #define DEBUG #define LOG_TAG "MIC_DEBUG" #ifdef DEBUG #include <stdio.h> #define debug(fmt, x...) printf("%s: %s() line: %d "fmt, LOG_TAG, __FUNCTION__, __LINE__, ##x); #else #define debug(fmt, x...) #endif int main() { int num = 4567; debug("num = %d\n", num); } 2.printk()自定義函式 1、定義 #define LOG_TAG "[Camera]: %s() line: %d " #define Camera_ERR(fmt, args...) printk(KERN_ERR LOG_TAG fmt, __FUNCTION__, __LINE__, ##args) 2、列印函式 void test(){ Camera_ERR("%s\n", __func__); } 3、輸出log為: [Camera] test