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/.
Max gerrit-no-reply at lists.osmocom.orgMax has uploaded this change for review. ( https://gerrit.osmocom.org/12094
Change subject: Add osmo_init_logging_std*()
......................................................................
Add osmo_init_logging_std*()
The osmo_init_logging_stdout() function is similar to
osmo_init_logging2() but uses stdout as a default log target instead of
stderr. It's expected to used by applications without vty (test code for
example).
The osmo_init_logging_stderr() is equivalent of osmo_init_logging2()
implemented on top of the same primitives as osmo_init_logging_stdout().
Logging test expanded to make sure that we only initialize logging once.
Change-Id: I0fe8dc4a41aba4e4509540266e229700e8ec083c
---
M include/osmocom/core/application.h
M src/application.c
M tests/logging/logging_vty_test.c
3 files changed, 51 insertions(+), 5 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/94/12094/1
diff --git a/include/osmocom/core/application.h b/include/osmocom/core/application.h
index edf59ed..c1e5b09 100644
--- a/include/osmocom/core/application.h
+++ b/include/osmocom/core/application.h
@@ -13,12 +13,15 @@
/*! one instance of a logging target (file, stderr, ...) */
struct log_target;
-/*! the default logging target, logging to stderr */
+/*! the default logging targets, logging to stderr or stdout */
extern struct log_target *osmo_stderr_target;
+extern struct log_target *osmo_stdout_target;
void osmo_init_ignore_signals(void);
int osmo_init_logging(const struct log_info *)
OSMO_DEPRECATED("use osmo_init_logging2() instead to avoid a NULL talloc ctx");
int osmo_init_logging2(void *ctx, const struct log_info *log_info);
+int osmo_init_logging_stdout(void *ctx, const struct log_info *log_info);
+int osmo_init_logging_stderr(void *ctx, const struct log_info *log_info);
int osmo_daemonize(void);
diff --git a/src/application.c b/src/application.c
index d912eb7..19e089b 100644
--- a/src/application.c
+++ b/src/application.c
@@ -83,6 +83,7 @@
#include <sys/stat.h>
struct log_target *osmo_stderr_target;
+struct log_target *osmo_stdout_target;
static void sighup_hdlr(int signal)
{
@@ -117,7 +118,7 @@
return osmo_init_logging2(NULL, log_info);
}
-int osmo_init_logging2(void *ctx, const struct log_info *log_info)
+static int _init_logging_std(void *ctx, const struct log_info *log_info)
{
static int logging_initialized = 0;
@@ -126,15 +127,52 @@
logging_initialized = 1;
log_init(log_info, ctx);
- osmo_stderr_target = log_target_create_stderr();
+
+ return 0;
+}
+
+static struct log_target *_add_logging_std(struct log_target *std)
+{
+ if (!std)
+ return NULL;
+
+ log_add_target(std);
+ log_set_all_filter(std, 1);
+
+ return std;
+}
+
+int osmo_init_logging_stdout(void *ctx, const struct log_info *log_info)
+{
+ int rc = _init_logging_std(ctx, log_info);
+ if (rc < 0)
+ return rc;
+
+ osmo_stdout_target = _add_logging_std(log_target_create_stdout());
+ if (!osmo_stdout_target)
+ return -1;
+
+ return 0;
+}
+
+int osmo_init_logging_stderr(void *ctx, const struct log_info *log_info)
+{
+ int rc = _init_logging_std(ctx, log_info);
+ if (rc < 0)
+ return rc;
+
+ osmo_stderr_target = _add_logging_std(log_target_create_stderr());
if (!osmo_stderr_target)
return -1;
- log_add_target(osmo_stderr_target);
- log_set_all_filter(osmo_stderr_target, 1);
return 0;
}
+int osmo_init_logging2(void *ctx, const struct log_info *log_info)
+{
+ return osmo_init_logging_stderr(ctx, log_info);
+}
+
/*! Turn the current process into a background daemon
*
* This function will fork the process, exit the parent and set umask,
diff --git a/tests/logging/logging_vty_test.c b/tests/logging/logging_vty_test.c
index 806a460..0bdb11d 100644
--- a/tests/logging/logging_vty_test.c
+++ b/tests/logging/logging_vty_test.c
@@ -242,6 +242,11 @@
osmo_init_logging2(root_ctx, &log_info);
+ if (osmo_init_logging_stderr(root_ctx, &log_info) == 0) {
+ LOGP(DLGLOBAL, LOGL_FATAL, "Subsequent logging init has not failed!\n");
+ return 3;
+ }
+
vty_commands_init();
handle_options(argc, argv);
--
To view, visit https://gerrit.osmocom.org/12094
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0fe8dc4a41aba4e4509540266e229700e8ec083c
Gerrit-Change-Number: 12094
Gerrit-PatchSet: 1
Gerrit-Owner: Max <msuraev at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181204/a42f3d5c/attachment.htm>