summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/osmocom/core/logging.h1
-rw-r--r--src/logging.c14
2 files changed, 15 insertions, 0 deletions
diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h
index 1e79dab3..617d78e4 100644
--- a/include/osmocom/core/logging.h
+++ b/include/osmocom/core/logging.h
@@ -224,6 +224,7 @@ enum log_target_type {
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 8cb34071..66074ea0 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -323,6 +323,14 @@ const char* log_category_name(int subsys)
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 @@ static void _output(struct log_target *target, unsigned int subsys,
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);