This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Neels Hofmeyr gerrit-no-reply at lists.osmocom.orgNeels Hofmeyr has submitted this change and it was merged. Change subject: logging: allow to log only the basename of each source ...................................................................... logging: allow to log only the basename of each source In the C API, add another enum log_file_type value, and when set print only the basename of the source file path. Rationale: especially when not building directly in the source dir, the paths to the source files can become rather long. Usually, just the basename of the file is sufficient to identify the source line. Change-Id: If3e4d5fb2066f8bf86e59c82d1752b1a843cf58e --- M include/osmocom/core/logging.h M src/logging.c 2 files changed, 15 insertions(+), 0 deletions(-) Approvals: Harald Welte: Looks good to me, approved Jenkins Builder: Verified diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h index 1e79dab..617d78e 100644 --- a/include/osmocom/core/logging.h +++ b/include/osmocom/core/logging.h @@ -224,6 +224,7 @@ enum log_filename_type { LOG_FILENAME_NONE, LOG_FILENAME_PATH, + LOG_FILENAME_BASENAME, }; /*! structure representing a logging target */ diff --git a/src/logging.c b/src/logging.c index 8cb3407..66074ea 100644 --- a/src/logging.c +++ b/src/logging.c @@ -323,6 +323,14 @@ return NULL; } +static const char *const_basename(const char *path) +{ + const char *bn = strrchr(path, '/'); + if (!bn || !bn[1]) + return path; + return bn + 1; +} + static void _output(struct log_target *target, unsigned int subsys, unsigned int level, const char *file, int line, int cont, const char *format, va_list ap) @@ -400,6 +408,12 @@ goto err; OSMO_SNPRINTF_RET(ret, rem, offset, len); break; + case LOG_FILENAME_BASENAME: + ret = snprintf(buf + offset, rem, "%s:%d ", const_basename(file), line); + if (ret < 0) + goto err; + OSMO_SNPRINTF_RET(ret, rem, offset, len); + break; } } ret = vsnprintf(buf + offset, rem, format, ap); -- To view, visit https://gerrit.osmocom.org/5814 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: merged Gerrit-Change-Id: If3e4d5fb2066f8bf86e59c82d1752b1a843cf58e Gerrit-PatchSet: 4 Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de> Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>