diff options
author | Geoff Gustafson <geoff@linux.intel.com> | 2016-12-22 13:16:49 -0800 |
---|---|---|
committer | Geoff Gustafson <geoff@linux.intel.com> | 2016-12-22 14:57:06 -0800 |
commit | 85e8072cdf7307e358826f04ea525da276e00f79 (patch) | |
tree | 97c431064d380300ec8d3bfbc5a84e8cf658b0ba /src/zjs_common.h | |
parent | 6fb4b9c0c1df1cde92f146be7f3e30a00746ce47 (diff) |
[general] Shorten file paths and improve dbg/err output format (#569)
Signed-off-by: Geoff Gustafson <geoff@linux.intel.com>
Diffstat (limited to 'src/zjs_common.h')
-rw-r--r-- | src/zjs_common.h | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/zjs_common.h b/src/zjs_common.h index b9bdc82..9ee29b5 100644 --- a/src/zjs_common.h +++ b/src/zjs_common.h @@ -9,23 +9,32 @@ #define ZJS_PRINT printf +/** + * Return a pointer to the filename portion of a string plus one parent dir + * + * @param filepath A valid null-terminated string + * @returns A pointer to a substring of filepath, namely the character right + * after the second to last slash, or filepath itself if not found. + */ +char *zjs_shorten_filepath(char *filepath); + #ifdef DEBUG_BUILD int zjs_get_sec(void); int zjs_get_ms(void); #define DBG_PRINT \ - ZJS_PRINT("[%u.%3.3u][INFO] %s:%d %s(): ", zjs_get_sec(), zjs_get_ms(), __FILE__, __LINE__, __func__); \ + ZJS_PRINT("\n%u.%3.3u %s:%d %s():\n[INFO] ", zjs_get_sec(), zjs_get_ms(), zjs_shorten_filepath(__FILE__), __LINE__, __func__); \ ZJS_PRINT #define ERR_PRINT \ - ZJS_PRINT("[%u.%3.3u][ERROR] %s:%d %s(): ", zjs_get_sec(), zjs_get_ms(), __FILE__, __LINE__, __func__); \ + ZJS_PRINT("\n%u.%3.3u %s:%d %s():\n[ERROR] ", zjs_get_sec(), zjs_get_ms(), zjs_shorten_filepath(__FILE__), __LINE__, __func__); \ ZJS_PRINT #else #define DBG_PRINT(fmat ...) do {} while(0); #define ERR_PRINT \ - ZJS_PRINT("[ERROR] %s:%d %s(): ", __FILE__, __LINE__, __func__); \ + ZJS_PRINT("\n%s:%d %s():\n[ERROR] ", zjs_shorten_filepath(__FILE__), __LINE__, __func__); \ ZJS_PRINT #endif |