Skip to content

Commit 5937abd

Browse files
lxc/log.h: use more convenient wrapper function
use tag 'lxc' in logcat to browse logs. Signed-off-by: DreamConnected <1487442471@qq.com>
1 parent f91f703 commit 5937abd

1 file changed

Lines changed: 25 additions & 18 deletions

File tree

src/lxc/log.h

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@
2929
#define LXC_LOG_PREFIX_SIZE 32
3030
#define LXC_LOG_BUFFER_SIZE 4096
3131

32-
#ifndef LXC_LOG_TAG
33-
#define LXC_LOG_TAG "lxc"
34-
#endif
32+
#define LOG_TAG "lxc"
3533

3634
#ifdef USE_ANDROID_LOG
37-
#include <android/log.h>
35+
#include <android/log_macros.h>
3836
#endif
3937

4038
/* predefined lxc log priorities. */
@@ -355,54 +353,63 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
355353
#define TRACE(format, ...) do { \
356354
struct lxc_log_locinfo locinfo = LXC_LOG_LOCINFO_INIT; \
357355
LXC_TRACE(&locinfo, format, ##__VA_ARGS__); \
356+
USE_ANDROID_LOG ? ALOGV("%s:%d: %s - %m - " format, __FILE__, __LINE__, __func__, ##__VA_ARGS__) : (void)0;\
358357
} while (0)
359358

360359
#define DEBUG(format, ...) do { \
361360
struct lxc_log_locinfo locinfo = LXC_LOG_LOCINFO_INIT; \
362361
LXC_DEBUG(&locinfo, format, ##__VA_ARGS__); \
362+
USE_ANDROID_LOG ? ALOGD("%s:%d: %s - %m - " format, __FILE__, __LINE__, __func__, ##__VA_ARGS__) : (void)0;\
363363
} while (0)
364364

365365
#define INFO(format, ...) do { \
366366
struct lxc_log_locinfo locinfo = LXC_LOG_LOCINFO_INIT; \
367367
LXC_INFO(&locinfo, format, ##__VA_ARGS__); \
368+
USE_ANDROID_LOG ? ALOGI("%s:%d: %s - %m - " format, __FILE__, __LINE__, __func__, ##__VA_ARGS__) : (void)0;\
368369
} while (0)
369370

370371
#define NOTICE(format, ...) do { \
371372
struct lxc_log_locinfo locinfo = LXC_LOG_LOCINFO_INIT; \
372373
LXC_NOTICE(&locinfo, format, ##__VA_ARGS__); \
374+
USE_ANDROID_LOG ? ALOGV("%s:%d: %s - %m - " format, __FILE__, __LINE__, __func__, ##__VA_ARGS__) : (void)0;\
373375
} while (0)
374376

375377
#define WARN(format, ...) do { \
376378
struct lxc_log_locinfo locinfo = LXC_LOG_LOCINFO_INIT; \
377379
LXC_WARN(&locinfo, format, ##__VA_ARGS__); \
380+
USE_ANDROID_LOG ? ALOGW("%s:%d: %s - %m - " format, __FILE__, __LINE__, __func__, ##__VA_ARGS__) : (void)0;\
378381
} while (0)
379382

380383
#define ERROR(format, ...) do { \
381384
struct lxc_log_locinfo locinfo = LXC_LOG_LOCINFO_INIT; \
382385
LXC_ERROR(&locinfo, format, ##__VA_ARGS__); \
386+
USE_ANDROID_LOG ? ALOGE("%s:%d: %s - %m - " format, __FILE__, __LINE__, __func__, ##__VA_ARGS__) : (void)0;\
383387
} while (0)
384388

385389
#define CRIT(format, ...) do { \
386390
struct lxc_log_locinfo locinfo = LXC_LOG_LOCINFO_INIT; \
387391
LXC_CRIT(&locinfo, format, ##__VA_ARGS__); \
392+
USE_ANDROID_LOG ? ALOGE("%s:%d: %s - %m - " format, __FILE__, __LINE__, __func__, ##__VA_ARGS__) : (void)0;\
388393
} while (0)
389394

390395
#define ALERT(format, ...) do { \
391396
struct lxc_log_locinfo locinfo = LXC_LOG_LOCINFO_INIT; \
392397
LXC_ALERT(&locinfo, format, ##__VA_ARGS__); \
398+
USE_ANDROID_LOG ? ALOGW("%s:%d: %s - %m - " format, __FILE__, __LINE__, __func__, ##__VA_ARGS__) : (void)0;\
393399
} while (0)
394400

395401
#define FATAL(format, ...) do { \
396402
struct lxc_log_locinfo locinfo = LXC_LOG_LOCINFO_INIT; \
397403
LXC_FATAL(&locinfo, format, ##__VA_ARGS__); \
404+
USE_ANDROID_LOG ? ALOGE("%s:%d: %s - %m - " format, __FILE__, __LINE__, __func__, ##__VA_ARGS__) : (void)0;\
398405
} while (0)
399406

400407
#if (defined(__GNU_LIBRARY__) || defined(__MUSL__)) && !ENABLE_COVERITY_BUILD
401408
#define SYSTRACE(format, ...) \
402409
TRACE("%m - " format, ##__VA_ARGS__)
403-
#elif IS_BIONIC && USE_ANDROID_LOG
410+
#elif USE_ANDROID_LOG
404411
#define SYSTRACE(format, ...) \
405-
__android_log_print(ANDROID_LOG_VERBOSE, LXC_LOG_TAG, format, ##__VA_ARGS__)
412+
ALOGV("%s:%d: %s - %m - " format, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
406413
#else
407414
#define SYSTRACE(format, ...) \
408415
do { \
@@ -413,10 +420,10 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
413420

414421
#if (defined(__GNU_LIBRARY__) || defined(__MUSL__)) && !ENABLE_COVERITY_BUILD
415422
#define SYSDEBUG(format, ...) \
416-
DEBUG("%m - " format, ##__VA_ARGS__)
417-
#elif IS_BIONIC && USE_ANDROID_LOG
423+
DEBUG("%m - " format, ##__VA_ARGS__)
424+
#elif USE_ANDROID_LOG
418425
#define SYSDEBUG(format, ...) \
419-
__android_log_print(ANDROID_LOG_DEBUG, LXC_LOG_TAG, format, ##__VA_ARGS__)
426+
ALOGD("%s:%d: %s - %m - " format, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
420427
#else
421428
#define SYSDEBUG(format, ...) \
422429
do { \
@@ -428,10 +435,10 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
428435

429436
#if (defined(__GNU_LIBRARY__) || defined(__MUSL__)) && !ENABLE_COVERITY_BUILD
430437
#define SYSINFO(format, ...) \
431-
INFO("%m - " format, ##__VA_ARGS__)
432-
#elif IS_BIONIC && USE_ANDROID_LOG
438+
INFO("%m - " format, ##__VA_ARGS__)
439+
#elif USE_ANDROID_LOG
433440
#define SYSINFO(format, ...) \
434-
__android_log_print(ANDROID_LOG_INFO, LXC_LOG_TAG, format, ##__VA_ARGS__)
441+
ALOGI("%s:%d: %s - %m - " format, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
435442
#else
436443
#define SYSINFO(format, ...) \
437444
do { \
@@ -443,9 +450,9 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
443450
#if (defined(__GNU_LIBRARY__) || defined(__MUSL__)) && !ENABLE_COVERITY_BUILD
444451
#define SYSNOTICE(format, ...) \
445452
NOTICE("%m - " format, ##__VA_ARGS__)
446-
#elif IS_BIONIC && USE_ANDROID_LOG
453+
#elif USE_ANDROID_LOG
447454
#define SYSNOTICE(format, ...) \
448-
__android_log_print(ANDROID_LOG_INFO, LXC_LOG_TAG, format, ##__VA_ARGS__)
455+
ALOGV("%s:%d: %s - %m - " format, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
449456
#else
450457
#define SYSNOTICE(format, ...) \
451458
do { \
@@ -457,9 +464,9 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
457464
#if (defined(__GNU_LIBRARY__) || defined(__MUSL__)) && !ENABLE_COVERITY_BUILD
458465
#define SYSWARN(format, ...) \
459466
WARN("%m - " format, ##__VA_ARGS__)
460-
#elif IS_BIONIC && USE_ANDROID_LOG
467+
#elif USE_ANDROID_LOG
461468
#define SYSWARN(format, ...) \
462-
__android_log_print(ANDROID_LOG_WARN, LXC_LOG_TAG, format, ##__VA_ARGS__)
469+
ALOGW("%s:%d: %s - %m - " format, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
463470
#else
464471
#define SYSWARN(format, ...) \
465472
do { \
@@ -471,9 +478,9 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
471478
#if (defined(__GNU_LIBRARY__) || defined(__MUSL__)) && !ENABLE_COVERITY_BUILD
472479
#define SYSERROR(format, ...) \
473480
ERROR("%m - " format, ##__VA_ARGS__)
474-
#elif IS_BIONIC && USE_ANDROID_LOG
481+
#elif USE_ANDROID_LOG
475482
#define SYSERROR(format, ...) \
476-
__android_log_print(ANDROID_LOG_ERROR, LXC_LOG_TAG, format, ##__VA_ARGS__)
483+
ALOGE("%s:%d: %s - %m - " format, __FILE__, __LINE__, __func__, ##__VA_ARGS__)
477484
#else
478485
#define SYSERROR(format, ...) \
479486
do { \

0 commit comments

Comments
 (0)