summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2012-09-11 11:24:51 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2012-09-11 11:24:51 +0200
commitdb1533651f6a8684f3c1551e32c96f9a0ad83116 (patch)
treec4faea374c16859bb5bbecd6f49321b40c404f91
parent314c01073313c45e5da3b88eaf79b11d273c9383 (diff)
logging: Introduce a print_filename flag for the logtarget
Introduce a print_filename attribute for each logtarget. Initialize it with 1 to be backward compatible with earlier versions. The bit is taken from an existint bitfield. There were at least six bits left of the byte.
-rw-r--r--include/osmocom/core/logging.h3
-rw-r--r--src/logging.c22
2 files changed, 20 insertions, 5 deletions
diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h
index 28f7549d..655f7a44 100644
--- a/include/osmocom/core/logging.h
+++ b/include/osmocom/core/logging.h
@@ -134,6 +134,8 @@ struct log_target {
unsigned int use_color:1;
/*! \brief should log messages be prefixed with a timestamp? */
unsigned int print_timestamp:1;
+ /*! \brief should log messages be prefixed with a filename? */
+ unsigned int print_filename:1;
/*! \brief the type of this log taget */
enum log_target_type type;
@@ -179,6 +181,7 @@ void log_set_all_filter(struct log_target *target, int);
void log_set_use_color(struct log_target *target, int);
void log_set_print_timestamp(struct log_target *target, int);
+void log_set_print_filename(struct log_target *target, int);
void log_set_log_level(struct log_target *target, int log_level);
void log_parse_category_mask(struct log_target *target, const char* mask);
int log_parse_level(const char *lvl);
diff --git a/src/logging.c b/src/logging.c
index eed0b26c..0816570e 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -242,11 +242,13 @@ static void _output(struct log_target *target, unsigned int subsys,
goto err;
OSMO_SNPRINTF_RET(ret, rem, offset, len);
}
- ret = snprintf(buf + offset, rem, "<%4.4x> %s:%d ",
- subsys, file, line);
- if (ret < 0)
- goto err;
- OSMO_SNPRINTF_RET(ret, rem, offset, len);
+ if (target->print_filename) {
+ ret = snprintf(buf + offset, rem, "<%4.4x> %s:%d ",
+ subsys, file, line);
+ if (ret < 0)
+ goto err;
+ OSMO_SNPRINTF_RET(ret, rem, offset, len);
+ }
}
ret = vsnprintf(buf + offset, rem, format, ap);
if (ret < 0)
@@ -409,6 +411,15 @@ void log_set_print_timestamp(struct log_target *target, int print_timestamp)
target->print_timestamp = print_timestamp;
}
+/*! \brief Enable or disable printing of the filename while logging
+ * \param[in] target Log target to be affected
+ * \param[in] print_filename Enable (1) or disable (0) filenames
+ */
+void log_set_print_filename(struct log_target *target, int print_filename)
+{
+ target->print_filename = print_filename;
+}
+
/*! \brief Set the global log level for a given log target
* \param[in] target Log target to be affected
* \param[in] log_level New global log level
@@ -464,6 +475,7 @@ struct log_target *log_target_create(void)
/* global settings */
target->use_color = 1;
target->print_timestamp = 0;
+ target->print_filename = 1;
/* global log level */
target->loglevel = 0;