ccollins476ad closed pull request #1246: sys/log/common: Package for common log 
API
URL: https://github.com/apache/mynewt-core/pull/1246
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/sys/log/full/include/log/ignore.h 
b/sys/log/common/include/log_common/ignore.h
similarity index 100%
rename from sys/log/full/include/log/ignore.h
rename to sys/log/common/include/log_common/ignore.h
diff --git a/sys/log/common/include/log_common/log_common.h 
b/sys/log/common/include/log_common/log_common.h
new file mode 100644
index 0000000000..fc3d214f23
--- /dev/null
+++ b/sys/log/common/include/log_common/log_common.h
@@ -0,0 +1,111 @@
+/*
+ * 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.
+ */
+
+#ifndef H_LOG_COMMON_
+#define H_LOG_COMMON_
+
+#include "os/mynewt.h"
+#include "log_common/ignore.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define LOG_VERSION_V3  3
+#define LOG_VERSION_V2  2
+#define LOG_VERSION_V1  1
+
+#define LOG_TYPE_STREAM  (0)
+#define LOG_TYPE_MEMORY  (1)
+#define LOG_TYPE_STORAGE (2)
+
+#define LOG_LEVEL_DEBUG    (0)
+#define LOG_LEVEL_INFO     (1)
+#define LOG_LEVEL_WARN     (2)
+#define LOG_LEVEL_ERROR    (3)
+#define LOG_LEVEL_CRITICAL (4)
+/* Up to 7 custom log levels. */
+#define LOG_LEVEL_MAX      (UINT8_MAX)
+
+#define LOG_LEVEL_STR(level) \
+    (LOG_LEVEL_DEBUG    == level ? "DEBUG"    :\
+    (LOG_LEVEL_INFO     == level ? "INFO"     :\
+    (LOG_LEVEL_WARN     == level ? "WARN"     :\
+    (LOG_LEVEL_ERROR    == level ? "ERROR"    :\
+    (LOG_LEVEL_CRITICAL == level ? "CRITICAL" :\
+     "UNKNOWN")))))
+
+/* Log module, eventually this can be a part of the filter. */
+#define LOG_MODULE_DEFAULT          (0)
+#define LOG_MODULE_OS               (1)
+#define LOG_MODULE_NEWTMGR          (2)
+#define LOG_MODULE_NIMBLE_CTLR      (3)
+#define LOG_MODULE_NIMBLE_HOST      (4)
+#define LOG_MODULE_NFFS             (5)
+#define LOG_MODULE_REBOOT           (6)
+#define LOG_MODULE_IOTIVITY         (7)
+#define LOG_MODULE_TEST             (8)
+#define LOG_MODULE_PERUSER          (64)
+#define LOG_MODULE_MAX              (255)
+
+#define LOG_ETYPE_STRING         (0)
+#if MYNEWT_VAL(LOG_VERSION) > 2
+#define LOG_ETYPE_CBOR           (1)
+#define LOG_ETYPE_BINARY         (2)
+#endif
+
+/* Logging medium */
+#define LOG_STORE_CONSOLE    1
+#define LOG_STORE_CBMEM      2
+#define LOG_STORE_FCB        3
+
+/* UTC Timestamp for Jan 2016 00:00:00 */
+#define UTC01_01_2016    1451606400
+
+#define LOG_NAME_MAX_LEN    (64)
+
+#ifndef MYNEWT_VAL_LOG_LEVEL
+#define LOG_SYSLEVEL    ((uint8_t)0xff)
+#else
+#define LOG_SYSLEVEL    ((uint8_t)MYNEWT_VAL_LOG_LEVEL)
+#endif
+
+/* Newtmgr Log opcodes */
+#define LOGS_NMGR_OP_READ         (0)
+#define LOGS_NMGR_OP_CLEAR        (1)
+#define LOGS_NMGR_OP_APPEND       (2)
+#define LOGS_NMGR_OP_MODULE_LIST  (3)
+#define LOGS_NMGR_OP_LEVEL_LIST   (4)
+#define LOGS_NMGR_OP_LOGS_LIST    (5)
+
+#define LOG_PRINTF_MAX_ENTRY_LEN (128)
+
+/* Global log info */
+struct log_info {
+    uint32_t li_next_index;
+    uint8_t li_version;
+};
+
+extern struct log_info g_log_info;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/sys/log/common/pkg.yml b/sys/log/common/pkg.yml
new file mode 100644
index 0000000000..b3a5466d58
--- /dev/null
+++ b/sys/log/common/pkg.yml
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+pkg.name: sys/log/common
+pkg.description: API common to both the full and stub log implementations.
+pkg.author: "Apache Mynewt <d...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/";
+pkg.keywords:
+    - logging
diff --git a/sys/log/full/include/log/log.h b/sys/log/full/include/log/log.h
index eacfaf5864..778eb25180 100644
--- a/sys/log/full/include/log/log.h
+++ b/sys/log/full/include/log/log.h
@@ -20,24 +20,13 @@
 #define __SYS_LOG_FULL_H__
 
 #include "os/mynewt.h"
-#include "log/ignore.h"
 #include "cbmem/cbmem.h"
+#include "log_common/log_common.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-/* Global log info */
-struct log_info {
-    uint32_t li_next_index;
-    uint8_t li_version;
-};
-#define LOG_VERSION_V3  3
-#define LOG_VERSION_V2  2
-#define LOG_VERSION_V1  1
-
-extern struct log_info g_log_info;
-
 struct log;
 struct log_entry_hdr;
 
@@ -85,10 +74,6 @@ typedef int (*lh_walk_func_t)(struct log *,
 typedef int (*lh_flush_func_t)(struct log *);
 typedef int (*lh_registered_func_t)(struct log *);
 
-#define LOG_TYPE_STREAM  (0)
-#define LOG_TYPE_MEMORY  (1)
-#define LOG_TYPE_STORAGE (2)
-
 struct log_handler {
     int log_type;
     lh_read_func_t log_read;
@@ -124,53 +109,8 @@ struct log_entry_hdr {
 
 #define LOG_ENTRY_HDR_SIZE (sizeof(struct log_entry_hdr))
 
-#define LOG_LEVEL_DEBUG    (0)
-#define LOG_LEVEL_INFO     (1)
-#define LOG_LEVEL_WARN     (2)
-#define LOG_LEVEL_ERROR    (3)
-#define LOG_LEVEL_CRITICAL (4)
-/* Up to 7 custom log levels. */
-#define LOG_LEVEL_MAX      (UINT8_MAX)
-
-#define LOG_LEVEL_STR(level) \
-    (LOG_LEVEL_DEBUG    == level ? "DEBUG"    :\
-    (LOG_LEVEL_INFO     == level ? "INFO"     :\
-    (LOG_LEVEL_WARN     == level ? "WARN"     :\
-    (LOG_LEVEL_ERROR    == level ? "ERROR"    :\
-    (LOG_LEVEL_CRITICAL == level ? "CRITICAL" :\
-     "UNKNOWN")))))
-
-/* Log module, eventually this can be a part of the filter. */
-#define LOG_MODULE_DEFAULT          (0)
-#define LOG_MODULE_OS               (1)
-#define LOG_MODULE_NEWTMGR          (2)
-#define LOG_MODULE_NIMBLE_CTLR      (3)
-#define LOG_MODULE_NIMBLE_HOST      (4)
-#define LOG_MODULE_NFFS             (5)
-#define LOG_MODULE_REBOOT           (6)
-#define LOG_MODULE_IOTIVITY         (7)
-#define LOG_MODULE_TEST             (8)
-#define LOG_MODULE_PERUSER          (64)
-#define LOG_MODULE_MAX              (255)
-
 #define LOG_MODULE_STR(module)      log_module_get_name(module)
 
-#define LOG_ETYPE_STRING         (0)
-#if MYNEWT_VAL(LOG_VERSION) > 2
-#define LOG_ETYPE_CBOR           (1)
-#define LOG_ETYPE_BINARY         (2)
-#endif
-
-/* Logging medium */
-#define LOG_STORE_CONSOLE    1
-#define LOG_STORE_CBMEM      2
-#define LOG_STORE_FCB        3
-
-/* UTC Timestamp for Jan 2016 00:00:00 */
-#define UTC01_01_2016    1451606400
-
-#define LOG_NAME_MAX_LEN    (64)
-
 #if MYNEWT_VAL(LOG_LEVEL) <= LOG_LEVEL_DEBUG
 #define LOG_DEBUG(__l, __mod, __msg, ...) log_printf(__l, __mod, \
         LOG_LEVEL_DEBUG, __msg, ##__VA_ARGS__)
@@ -206,12 +146,6 @@ 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;
     const struct log_handler *l_log;
@@ -220,14 +154,6 @@ struct log {
     uint8_t l_level;
 };
 
-/* Newtmgr Log opcodes */
-#define LOGS_NMGR_OP_READ         (0)
-#define LOGS_NMGR_OP_CLEAR        (1)
-#define LOGS_NMGR_OP_APPEND       (2)
-#define LOGS_NMGR_OP_MODULE_LIST  (3)
-#define LOGS_NMGR_OP_LEVEL_LIST   (4)
-#define LOGS_NMGR_OP_LOGS_LIST    (5)
-
 /* Log system level functions (for all logs.) */
 void log_init(void);
 struct log *log_list_get_next(struct log *);
@@ -500,7 +426,6 @@ log_append_mbuf(struct log *log, uint8_t module, uint8_t 
level,
     return log_append_mbuf_typed(log, module, level, LOG_ETYPE_STRING, om);
 }
 
-#define LOG_PRINTF_MAX_ENTRY_LEN (128)
 void log_printf(struct log *log, uint8_t module, uint8_t level,
         const char *msg, ...);
 int log_read(struct log *log, void *dptr, void *buf, uint16_t off,
diff --git a/sys/log/full/pkg.yml b/sys/log/full/pkg.yml
index a8ea78fcc6..235d67a8d2 100644
--- a/sys/log/full/pkg.yml
+++ b/sys/log/full/pkg.yml
@@ -27,6 +27,7 @@ pkg.keywords:
 pkg.deps:
     - kernel/os
     - sys/flash_map
+    - sys/log/common
     - util/cbmem
 pkg.deps.LOG_FCB:
     - hw/hal
diff --git a/sys/log/stub/include/log/ignore.h 
b/sys/log/stub/include/log/ignore.h
deleted file mode 100644
index 46282a0298..0000000000
--- a/sys/log/stub/include/log/ignore.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.
- */
-
-#ifndef H_IGNORE_
-#define H_IGNORE_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * These macros prevent the "set but not used" warnings for log writes below
- * the log level.
- */
-
-#define IGN_1(X) ((void)(X))
-#define IGN_2(X, ...) ((void)(X));IGN_1(__VA_ARGS__)
-#define IGN_3(X, ...) ((void)(X));IGN_2(__VA_ARGS__)
-#define IGN_4(X, ...) ((void)(X));IGN_3(__VA_ARGS__)
-#define IGN_5(X, ...) ((void)(X));IGN_4(__VA_ARGS__)
-#define IGN_6(X, ...) ((void)(X));IGN_5(__VA_ARGS__)
-#define IGN_7(X, ...) ((void)(X));IGN_6(__VA_ARGS__)
-#define IGN_8(X, ...) ((void)(X));IGN_7(__VA_ARGS__)
-#define IGN_9(X, ...) ((void)(X));IGN_8(__VA_ARGS__)
-#define IGN_10(X, ...) ((void)(X));IGN_9(__VA_ARGS__)
-#define IGN_11(X, ...) ((void)(X));IGN_10(__VA_ARGS__)
-#define IGN_12(X, ...) ((void)(X));IGN_11(__VA_ARGS__)
-#define IGN_13(X, ...) ((void)(X));IGN_12(__VA_ARGS__)
-#define IGN_14(X, ...) ((void)(X));IGN_13(__VA_ARGS__)
-#define IGN_15(X, ...) ((void)(X));IGN_14(__VA_ARGS__)
-#define IGN_16(X, ...) ((void)(X));IGN_15(__VA_ARGS__)
-#define IGN_17(X, ...) ((void)(X));IGN_16(__VA_ARGS__)
-#define IGN_18(X, ...) ((void)(X));IGN_17(__VA_ARGS__)
-#define IGN_19(X, ...) ((void)(X));IGN_18(__VA_ARGS__)
-#define IGN_20(X, ...) ((void)(X));IGN_19(__VA_ARGS__)
-
-#define GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, \
-                  _13, _14, _15, _16, _17, _18, _19, _20, NAME, ...) NAME
-#define IGNORE(...) \
-    GET_MACRO(__VA_ARGS__, IGN_20, IGN_19, IGN_18, IGN_17, IGN_16, IGN_15, \
-              IGN_14, IGN_13, IGN_12, IGN_11, IGN_10, IGN_9, IGN_8, IGN_7, \
-              IGN_6, IGN_5, IGN_4, IGN_3, IGN_2, IGN_1)(__VA_ARGS__)
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/sys/log/stub/include/log/log.h b/sys/log/stub/include/log/log.h
index ef9cba995e..35e1409de1 100644
--- a/sys/log/stub/include/log/log.h
+++ b/sys/log/stub/include/log/log.h
@@ -21,7 +21,7 @@
 
 #include <inttypes.h>
 #include "os/mynewt.h"
-#include "log/ignore.h"
+#include "log_common/log_common.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -33,28 +33,6 @@ extern "C" {
 #define LOG_ERROR(__l, __mod, ...) IGNORE(__VA_ARGS__)
 #define LOG_CRITICAL(__l, __mod, ...) IGNORE(__VA_ARGS__)
 
-#define LOG_LEVEL_DEBUG         0
-#define LOG_LEVEL_INFO          1
-#define LOG_LEVEL_WARN          2
-#define LOG_LEVEL_ERROR         3
-#define LOG_LEVEL_CRITICAL      4
-/* Up to 7 custom log levels. */
-#define LOG_LEVEL_MAX           UINT8_MAX
-#define LOG_SYSLEVEL            UINT8_MAX
-
-/* Logging medium */
-#define LOG_STORE_CONSOLE    1
-#define LOG_STORE_CBMEM      2
-#define LOG_STORE_FCB        3
-
-/* Global log info */
-struct log_info {
-    uint32_t li_next_index;
-    uint8_t li_version;
-};
-
-struct log_info g_log_info;
-
 struct log {
 };
 
diff --git a/sys/log/stub/pkg.yml b/sys/log/stub/pkg.yml
index 4f42892e90..d57c0f27b5 100644
--- a/sys/log/stub/pkg.yml
+++ b/sys/log/stub/pkg.yml
@@ -25,5 +25,7 @@ pkg.keywords:
     - logging
 
 pkg.deps:
+    - sys/log/common
+
 pkg.apis:
     - log
diff --git a/sys/log/stub/src/log.c b/sys/log/stub/src/log.c
new file mode 100644
index 0000000000..a4f6779183
--- /dev/null
+++ b/sys/log/stub/src/log.c
@@ -0,0 +1,23 @@
+/*
+ * 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 "os/mynewt.h"
+#include "log/log.h"
+
+struct log_info g_log_info;


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to