shorten file path in logs

Couldn't figure out how to do it at compile-time on Android.
This commit is contained in:
Eric House 2023-10-29 08:08:34 -07:00
parent 2331cde2e7
commit 28318eb38a
3 changed files with 14 additions and 3 deletions

View file

@ -979,7 +979,11 @@ void
android_debugff(const char* func, const char* file, const char* fmt, ...) android_debugff(const char* func, const char* file, const char* fmt, ...)
{ {
char buf[256]; char buf[256];
snprintf( buf, sizeof(buf), "%s:%s(): %s", file, func, fmt ); const char* shortPath = 1 + strrchr(file, '/');
if ( !shortPath ) {
shortPath = file;
}
snprintf( buf, sizeof(buf), "%s:%s(): %s", shortPath, func, fmt );
va_list ap; va_list ap;
va_start( ap, fmt ); va_start( ap, fmt );

View file

@ -251,6 +251,8 @@ ifdef USE_SQLITE
LIBS += -lsqlite3 LIBS += -lsqlite3
LIBS += -lmosquitto LIBS += -lmosquitto
DEFINES += -DUSE_SQLITE DEFINES += -DUSE_SQLITE
DEFINES += -DSHORTFILE=\"$(notdir $<)\"
endif endif
# Turn this off for now. I apparently have a memory problem, but it # Turn this off for now. I apparently have a memory problem, but it
# doesn't make the app unusable for testing while crash on boot does. # doesn't make the app unusable for testing while crash on boot does.

View file

@ -77,12 +77,17 @@ extern void linux_debugf(const char*, ...)
__attribute__ ((format (printf, 1, 2))); __attribute__ ((format (printf, 1, 2)));
# define XP_DEBUGF(...) linux_debugf(__VA_ARGS__) # define XP_DEBUGF(...) linux_debugf(__VA_ARGS__)
#ifndef SHORTFILE
# define SHORTFILE __FILE__
#endif
extern void linux_debugff(const char* func, const char* file, int line, const char* fmt, ...) extern void linux_debugff(const char* func, const char* file, int line, const char* fmt, ...)
__attribute__ ((format (printf, 4, 5))); __attribute__ ((format (printf, 4, 5)));
# define XP_LOGFF( FMT, ... ) \ # define XP_LOGFF( FMT, ... ) \
linux_debugff( __func__, __FILE__, __LINE__, FMT, ##__VA_ARGS__ ) linux_debugff( __func__, SHORTFILE, __LINE__, FMT, ##__VA_ARGS__ )
#define XP_LOG(STR) \ #define XP_LOG(STR) \
linux_debugff( __func__, __FILE__, "%s", STR ) linux_debugff( __func__, SHORTFILE, "%s", STR )
#else #else
# define XP_DEBUGF(ch,...) # define XP_DEBUGF(ch,...)