Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f12c395a authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Modify log format

Always log file name and line number.
Instead of __PRETTY_FUNC_ use __func__ and log just the function name.
Logging full name with namespace, return value and parameters produces
unreadable gibberish.

This makes it easier to map log line to line that produced it.

Test: compile, look through the logs.
Change-Id: I3a72e8e498ded604fe61179191f1bc98b44c6a5c
parent ede28d03
Loading
Loading
Loading
Loading
+17 −16
Original line number Original line Diff line number Diff line
@@ -28,18 +28,19 @@


#include <log/log.h>
#include <log/log.h>


#define LOG_VERBOSE(fmt, args...) ALOGV("%s: " fmt, __PRETTY_FUNCTION__, ##args)
#define LOG_VERBOSE(fmt, args...) ALOGV("%s:%d %s: " fmt, __FILE__, __LINE__, __func__, ##args)
#define LOG_DEBUG(fmt, args...) ALOGD("%s: " fmt, __PRETTY_FUNCTION__, ##args)
#define LOG_DEBUG(fmt, args...) ALOGD("%s:%d %s: " fmt, __FILE__, __LINE__, __func__, ##args)
#define LOG_INFO(fmt, args...) ALOGI("%s: " fmt, __PRETTY_FUNCTION__, ##args)
#define LOG_INFO(fmt, args...) ALOGI("%s:%d %s: " fmt, __FILE__, __LINE__, __func__, ##args)
#define LOG_WARN(fmt, args...) ALOGW("%s: " fmt, __PRETTY_FUNCTION__, ##args)
#define LOG_WARN(fmt, args...) ALOGW("%s:%d %s: " fmt, __FILE__, __LINE__, __func__, ##args)
#define LOG_ERROR(fmt, args...) ALOGE("%s: " fmt, __PRETTY_FUNCTION__, ##args)
#define LOG_ERROR(fmt, args...) ALOGE("%s:%d %s: " fmt, __FILE__, __LINE__, __func__, ##args)


#else
#else


/* syslog didn't work well here since we would be redefining LOG_DEBUG. */
/* syslog didn't work well here since we would be redefining LOG_DEBUG. */
#include <stdio.h>
#include <stdio.h>


#define LOGWRAPPER(fmt, args...) fprintf(stderr, "%s - %s: " fmt "\n", LOG_TAG, __PRETTY_FUNCTION__, ##args)
#define LOGWRAPPER(fmt, args...) \
  fprintf(stderr, "%s - %s:%d - %s: " fmt "\n", LOG_TAG, __FILE__, __LINE__, __func__, ##args)


#define LOG_VERBOSE(...) LOGWRAPPER(__VA_ARGS__)
#define LOG_VERBOSE(...) LOGWRAPPER(__VA_ARGS__)
#define LOG_DEBUG(...) LOGWRAPPER(__VA_ARGS__)
#define LOG_DEBUG(...) LOGWRAPPER(__VA_ARGS__)
@@ -57,13 +58,13 @@
#define ASSERT(condition)                                    \
#define ASSERT(condition)                                    \
  do {                                                       \
  do {                                                       \
    if (!(condition)) {                                      \
    if (!(condition)) {                                      \
      LOG_ALWAYS_FATAL("%s:%d assertion '" #condition "' failed", __FILE__, __LINE__); \
      LOG_ALWAYS_FATAL("assertion '" #condition "' failed"); \
    }                                                        \
    }                                                        \
  } while (false)
  } while (false)


#define ASSERT_LOG(condition, fmt, args...)                                 \
#define ASSERT_LOG(condition, fmt, args...)                                 \
  do {                                                                      \
  do {                                                                      \
    if (!(condition)) {                                                     \
    if (!(condition)) {                                                     \
      LOG_ALWAYS_FATAL("%s:%d assertion '" #condition "' failed - " fmt, __FILE__, __LINE__, ##args); \
      LOG_ALWAYS_FATAL("assertion '" #condition "' failed - " fmt, ##args); \
    }                                                                       \
    }                                                                       \
  } while (false)
  } while (false)