Short source code path vs Absolute source code path, returned by MFU_LOG function in mfu_util.h
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 200
- Forks
- 85
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 2
Description
The MFU_LOG function gives some debuging informations such as the full or absolute path of the source code. Here is an example:
[XXX ~]$ dbcast
[2022-03-09T11:06:23] [0] [/stck/montreui/rpmbuild/BUILD/mpiFileUtils-0.11.1/mpifileutils-0.11.1/src/dbcast/dbcast.c:550] ERROR: Failed to find source and/or destination file names
Usage: dbcast [options] <SRC> <DEST>
...
Well, in a context of deploying on a HPC calculator, I found a bit tricky to have in this example the absolute path with my user name. I would rather see a short source code path such as :
[XXX ~]$ dbcast
[2022-03-09T11:06:23] [0] [src/dbcast/dbcast.c:550] ERROR: Failed to find source and/or destination file names
Usage: dbcast [options] <SRC> <DEST>
...
I have test a modification in the source code :
#define MFU_LOG(level, ...) do { \
if (mfu_initialized && level <= mfu_debug_level) { \
char timestamp[256]; \
char *longfilename=__FILE__; \
char shortfilename[256]; \
char *buildpath="/stck/montreui/rpmbuild/BUILD/mpiFileUtils-0.11.1/mpifileutils--0.11.1"; \
time_t ltime = time(NULL); \
struct tm *ttime = localtime(<ime); \
strftime(timestamp, sizeof(timestamp), \
"%Y-%m-%dT%H:%M:%S", ttime); \
strncpy(shortfilename,&longfilename[strlen(buildpath)],256-strlen(buildpath)); \
if(level == MFU_LOG_DBG) { \
fprintf(mfu_debug_stream,"[%s] [%d] [%s:%d] ", \
timestamp, mfu_rank, \
shortfilename, __LINE__); \
} else if(level <= MFU_LOG_ERR) { \
fprintf(mfu_debug_stream,"[%s] [%d] [%s:%d] ERROR: ", \
timestamp, mfu_rank, \
shortfilename, __LINE__); \
} else { \
fprintf(mfu_debug_stream,"[%s] ", \
timestamp); \
} \
fprintf(mfu_debug_stream, __VA_ARGS__); \
fprintf(mfu_debug_stream, "\n"); \
fflush(mfu_debug_stream); \
} \
} while (0)
So my idea here is to shorten the path to code source to avoid the guy's username path that have compile the library.
What ever the way of doing that... Changing the mfu_debug_level at MFU_LOG_NONE is a pity because those informations are interesting however. I did not find any way in compile options or whatsoever to avoid the long path source code.
Does it sound right or silly ?
It is my firt post, so, be cool and don't upset yoursef, please ;-)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in mfu_util.h at the MFU_LOG macro and inspect how FILE is currently formatted in debug and error output. Review the reported path-shortening example and determine a portable way to omit the build-directory prefix without hiding useful source locations. Done means MFU_LOG output uses a short source path while retaining the existing timestamp, rank, line, and message information.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100