You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/10/20 16:18:32 UTC
[2/4] incubator-mynewt-core git commit: MYNEWT-444 - Configure log
level per-module
MYNEWT-444 - Configure log level per-module
Add argument to log_register specifying the log level (e.g, LOG_WARN, etc) to be
accepted in the log. A new field was added to log structure to store the log level.
New define LOG_SYSLEVEL is the "defined" system log level.
Bonus fixes for log and nimble unit tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/4ae25f3a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4ae25f3a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4ae25f3a
Branch: refs/heads/develop
Commit: 4ae25f3a3a77c4a9f5704b6194b72e02dbea89a7
Parents: 8334ab2
Author: Peter Snyder <gi...@peterfs.com>
Authored: Mon Oct 17 17:56:20 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Oct 20 09:05:34 2016 -0700
----------------------------------------------------------------------
apps/blecent/src/main.c | 2 +-
apps/bleprph/src/main.c | 2 +-
apps/bletiny/src/main.c | 2 +-
apps/ffs2native/src/main.c | 2 +-
apps/slinky/src/main.c | 2 +-
apps/splitty/src/main.c | 2 +-
net/nimble/host/src/ble_hs.c | 8 ++++++-
net/oic/src/port/mynewt/log.c | 2 +-
sys/log/include/log/log.h | 11 +++++++--
sys/log/src/log.c | 16 ++++++++++++-
sys/log/test/src/log_test.c | 11 ---------
sys/log/test/src/testcases/log_flush_fcb.c | 30 +++++++++++++++++++++++++
sys/log/test/src/testcases/log_setup_fcb.c | 2 +-
sys/reboot/src/log_reboot.c | 2 +-
14 files changed, 70 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4ae25f3a/apps/blecent/src/main.c
----------------------------------------------------------------------
diff --git a/apps/blecent/src/main.c b/apps/blecent/src/main.c
index 96fb434..0033e51 100755
--- a/apps/blecent/src/main.c
+++ b/apps/blecent/src/main.c
@@ -505,7 +505,7 @@ main(void)
sysinit();
/* Initialize the blecent log. */
- log_register("blecent", &blecent_log, &log_console_handler, NULL);
+ log_register("blecent", &blecent_log, &log_console_handler, NULL, LOG_SYSLEVEL);
/* Initialize the eventq for the application task. */
os_eventq_init(&blecent_evq);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4ae25f3a/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index 321b7cb..40680f4 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -305,7 +305,7 @@ main(void)
sysinit();
/* Initialize the bleprph log. */
- log_register("bleprph", &bleprph_log, &log_console_handler, NULL);
+ log_register("bleprph", &bleprph_log, &log_console_handler, NULL, LOG_SYSLEVEL);
/* Initialize eventq */
os_eventq_init(&bleprph_evq);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4ae25f3a/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 4491137..fcb94fa 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1623,7 +1623,7 @@ main(void)
assert(rc == 0);
/* Initialize the logging system. */
- log_register("bletiny", &bletiny_log, &log_console_handler, NULL);
+ log_register("bletiny", &bletiny_log, &log_console_handler, NULL, LOG_SYSLEVEL);
/* Initialize eventq for the application task. */
os_eventq_init(&bletiny_evq);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4ae25f3a/apps/ffs2native/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ffs2native/src/main.c b/apps/ffs2native/src/main.c
index 661e5ca..5c322c4 100644
--- a/apps/ffs2native/src/main.c
+++ b/apps/ffs2native/src/main.c
@@ -672,7 +672,7 @@ main(int argc, char **argv)
sysinit();
- log_register("nffs-log", &nffs_log, &log_console_handler, NULL);
+ log_register("nffs-log", &nffs_log, &log_console_handler, NULL, LOG_SYSLEVEL);
file_scratch_idx = MAX_AREAS + 1;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4ae25f3a/apps/slinky/src/main.c
----------------------------------------------------------------------
diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c
index 383db97..dcf993b 100755
--- a/apps/slinky/src/main.c
+++ b/apps/slinky/src/main.c
@@ -264,7 +264,7 @@ main(int argc, char **argv)
assert(rc == 0);
cbmem_init(&cbmem, cbmem_buf, MAX_CBMEM_BUF);
- log_register("log", &my_log, &log_cbmem_handler, &cbmem);
+ log_register("log", &my_log, &log_cbmem_handler, &cbmem, LOG_SYSLEVEL);
stats_init(STATS_HDR(g_stats_gpio_toggle),
STATS_SIZE_INIT_PARMS(g_stats_gpio_toggle, STATS_SIZE_32),
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4ae25f3a/apps/splitty/src/main.c
----------------------------------------------------------------------
diff --git a/apps/splitty/src/main.c b/apps/splitty/src/main.c
index b9a4259..47c1ac9 100755
--- a/apps/splitty/src/main.c
+++ b/apps/splitty/src/main.c
@@ -193,7 +193,7 @@ main(int argc, char **argv)
sysinit();
cbmem_init(&cbmem, cbmem_buf, MAX_CBMEM_BUF);
- log_register("log", &my_log, &log_cbmem_handler, &cbmem);
+ log_register("log", &my_log, &log_cbmem_handler, &cbmem, LOG_SYSLEVEL);
stats_init(STATS_HDR(g_stats_gpio_toggle),
STATS_SIZE_INIT_PARMS(g_stats_gpio_toggle, STATS_SIZE_32),
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4ae25f3a/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index 57c3e70..9b65984 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -563,7 +563,13 @@ ble_hs_init(void)
int rc;
log_init();
- log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL);
+#if 0
+ /*
+ * XXX This call to log_register should either move to an app or
+ * be configured in the BSP
+ */
+ log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL, LOG_SYSLEVEL);
+#endif
/* Create memory pool of OS events */
rc = os_mempool_init(&ble_hs_hci_ev_pool, BLE_HS_HCI_EVT_COUNT,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4ae25f3a/net/oic/src/port/mynewt/log.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/log.c b/net/oic/src/port/mynewt/log.c
index 8c76fc9..1fa9060 100644
--- a/net/oic/src/port/mynewt/log.c
+++ b/net/oic/src/port/mynewt/log.c
@@ -36,7 +36,7 @@ oc_log_init(void) {
}
cbmem_init(&cbmem, cbmem_buf, MAX_CBMEM_BUF);
- log_register("iot", &oc_log, &log_cbmem_handler, &cbmem);
+ log_register("iot", &oc_log, &log_cbmem_handler, &cbmem, LOG_SYSLEVEL);
LOG_INFO(&oc_log, LOG_MODULE_IOTIVITY, "OC Init");
return 0;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4ae25f3a/sys/log/include/log/log.h
----------------------------------------------------------------------
diff --git a/sys/log/include/log/log.h b/sys/log/include/log/log.h
index a074de8..31d058f 100644
--- a/sys/log/include/log/log.h
+++ b/sys/log/include/log/log.h
@@ -143,7 +143,7 @@ struct log_entry_hdr {
#define LOG_INFO(__l, __mod, ...) IGNORE(__VA_ARGS__)
#endif
-#if MYNEWT_VAL(LOG_LEVEL) <= LOG_LEVEL_INFO
+#if MYNEWT_VAL(LOG_LEVEL) <= LOG_LEVEL_WARN
#define LOG_WARN(__l, __mod, __msg, ...) log_printf(__l, __mod, \
LOG_LEVEL_WARN, __msg, ##__VA_ARGS__)
#else
@@ -164,11 +164,18 @@ struct log_entry_hdr {
#define LOG_CRITICAL(__l, __mod, ...) IGNORE(__VA_ARGS__)
#endif
+#ifndef MYNEWT_VAL_LOG_LEVEL
+#define LOG_SYSLEVEL ((uint8_t)0xff)
+#else
+#define LOG_SYSLEVEL ((uint8_t)MYNEWT_VAL_LOG_LEVEL)
+#endif
+
struct log {
char *l_name;
struct log_handler *l_log;
void *l_arg;
STAILQ_ENTRY(log) l_next;
+ uint8_t l_level;
};
/* Newtmgr Log opcodes */
@@ -185,7 +192,7 @@ struct log *log_list_get_next(struct log *);
/* Log functions, manipulate a single log */
int log_register(char *name, struct log *log, const struct log_handler *,
- void *arg);
+ void *arg, uint8_t level);
int log_append(struct log *, uint16_t, uint16_t, void *, uint16_t);
#define LOG_PRINTF_MAX_ENTRY_LEN (128)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4ae25f3a/sys/log/src/log.c
----------------------------------------------------------------------
diff --git a/sys/log/src/log.c b/sys/log/src/log.c
index 53b8362..b8209ea 100644
--- a/sys/log/src/log.c
+++ b/sys/log/src/log.c
@@ -107,11 +107,16 @@ log_registered(struct log *log)
*/
int
log_register(char *name, struct log *log, const struct log_handler *lh,
- void *arg)
+ void *arg, uint8_t level)
{
log->l_name = name;
log->l_log = (struct log_handler *)lh;
log->l_arg = arg;
+ if (level == 0) {
+ log->l_level = LOG_SYSLEVEL;
+ } else {
+ log->l_level = level;
+ }
assert(!log_registered(log));
STAILQ_INSERT_TAIL(&g_log_list, log, l_next);
@@ -132,6 +137,15 @@ log_append(struct log *log, uint16_t module, uint16_t level, void *data,
goto err;
}
+ /*
+ * If the log message is below what this log instance is
+ * configured to accept, then just drop it.
+ */
+ if (level > log->l_level) {
+ rc = -1;
+ goto err;
+ }
+
ue = (struct log_entry_hdr *) data;
/* Could check for li_index wraparound here */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4ae25f3a/sys/log/test/src/log_test.c
----------------------------------------------------------------------
diff --git a/sys/log/test/src/log_test.c b/sys/log/test/src/log_test.c
index ff411e8..674b1bb 100644
--- a/sys/log/test/src/log_test.c
+++ b/sys/log/test/src/log_test.c
@@ -80,17 +80,6 @@ log_test_walk2(struct log *log, void *arg, void *dptr, uint16_t len)
return 0;
}
-TEST_CASE(log_flush_fcb)
-{
- int rc;
-
- rc = log_flush(&my_log);
- TEST_ASSERT(rc == 0);
-
- rc = log_walk(&my_log, log_test_walk2, NULL);
- TEST_ASSERT(rc == 0);
-}
-
TEST_CASE_DECL(log_setup_fcb)
TEST_CASE_DECL(log_append_fcb)
TEST_CASE_DECL(log_walk_fcb)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4ae25f3a/sys/log/test/src/testcases/log_flush_fcb.c
----------------------------------------------------------------------
diff --git a/sys/log/test/src/testcases/log_flush_fcb.c b/sys/log/test/src/testcases/log_flush_fcb.c
new file mode 100644
index 0000000..97705a5
--- /dev/null
+++ b/sys/log/test/src/testcases/log_flush_fcb.c
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include "log_test.h"
+
+TEST_CASE(log_flush_fcb)
+{
+ int rc;
+
+ rc = log_flush(&my_log);
+ TEST_ASSERT(rc == 0);
+
+ rc = log_walk(&my_log, log_test_walk2, NULL);
+ TEST_ASSERT(rc == 0);
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4ae25f3a/sys/log/test/src/testcases/log_setup_fcb.c
----------------------------------------------------------------------
diff --git a/sys/log/test/src/testcases/log_setup_fcb.c b/sys/log/test/src/testcases/log_setup_fcb.c
index fde174d..c66c971 100644
--- a/sys/log/test/src/testcases/log_setup_fcb.c
+++ b/sys/log/test/src/testcases/log_setup_fcb.c
@@ -35,5 +35,5 @@ TEST_CASE(log_setup_fcb)
rc = fcb_init(&log_fcb);
TEST_ASSERT(rc == 0);
- log_register("log", &my_log, &log_fcb_handler, &log_fcb);
+ log_register("log", &my_log, &log_fcb_handler, &log_fcb, LOG_SYSLEVEL);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4ae25f3a/sys/reboot/src/log_reboot.c
----------------------------------------------------------------------
diff --git a/sys/reboot/src/log_reboot.c b/sys/reboot/src/log_reboot.c
index 41cb1d7..1a0a346 100644
--- a/sys/reboot/src/log_reboot.c
+++ b/sys/reboot/src/log_reboot.c
@@ -116,7 +116,7 @@ reboot_init_handler(int log_store_type, uint8_t entries)
rc = log_register("reboot_log", &reboot_log,
(struct log_handler *)reboot_log_handler,
- arg);
+ arg, LOG_SYSLEVEL);
if (rc != 0) {
return rc;
}