diff options
author | Philipp Maier <pmaier@sysmocom.de> | 2022-01-19 11:43:05 +0100 |
---|---|---|
committer | Philipp Maier <pmaier@sysmocom.de> | 2022-01-25 17:49:20 +0100 |
commit | 4c44d46308ffc365b49cfe08fdee39239180ebcc (patch) | |
tree | c843b01bfa48e0c88ca8cbfdebc0d12a61088b4a /src/logging.c | |
parent | fca15ebf995bcc8e00263619c0e366384f94881c (diff) |
logging: log to stderr when logging is not initialized
When the logging framework is not initialized we get an error:
"ERROR: osmo_log_info == NULL! You must call log_init() before
using logging in ..."
There are sometimes situations where some code tries to log before
logging was initialied. This is a problem because the actual log
line with the debug info we need is covered up by the error message
from the logging framework.
Lets introduce a fallback logging function that is called when the
the logging framework is not available. This function can just use
fprintf to output to stderr.
Change-Id: I9b1b0988e02322e3e44fd4ceea3e1bc2d4df3c45
Diffstat (limited to 'src/logging.c')
-rw-r--r-- | src/logging.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/logging.c b/src/logging.c index 94d183fe..148bb272 100644 --- a/src/logging.c +++ b/src/logging.c @@ -754,6 +754,18 @@ void logp2(int subsys, unsigned int level, const char *file, int line, int cont, TRACE(LIBOSMOCORE_LOG_DONE()); } +/* This logging function is used as a fallback when the logging framework is + * not is not properly initialized. */ +void logp_stub(const char *file, int line, int cont, const char *format, ...) +{ + va_list ap; + if (!cont) + fprintf(stderr, "%s:%d ", file, line); + va_start(ap, format); + vfprintf(stderr, format, ap); + va_end(ap); +} + /*! Register a new log target with the logging core * \param[in] target Log target to be registered */ |