boot: zephyr: migrate to new log subystem

The old log subsystem has been deprecated in Zephyr.
Migrate to the new subsystem to avoid compilation warnings.

In-place log processing is selected as it is required as MCUBoot is
one thread application.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
diff --git a/boot/boot_serial/src/boot_serial.c b/boot/boot_serial/src/boot_serial.c
index 32b3eb1..449a979 100644
--- a/boot/boot_serial/src/boot_serial.c
+++ b/boot/boot_serial/src/boot_serial.c
@@ -59,6 +59,8 @@
 #include "bootutil_priv.h"
 #endif
 
+MCUBOOT_LOG_MODULE_DECLARE(mcuboot);
+
 #define BOOT_SERIAL_INPUT_MAX   512
 #define BOOT_SERIAL_OUT_MAX	80
 
@@ -71,8 +73,8 @@
 
 #define ntohs(x) sys_be16_to_cpu(x)
 #define htons(x) sys_cpu_to_be16(x)
-
 #endif
+
 static char in_buf[BOOT_SERIAL_INPUT_MAX + 1];
 static char dec_buf[BOOT_SERIAL_INPUT_MAX + 1];
 const struct boot_uart_funcs *boot_uf;
diff --git a/boot/bootutil/src/bootutil_misc.c b/boot/bootutil/src/bootutil_misc.c
index 75c1dd9..c7c0962 100644
--- a/boot/bootutil/src/bootutil_misc.c
+++ b/boot/bootutil/src/bootutil_misc.c
@@ -33,6 +33,8 @@
 #include "bootutil/enc_key.h"
 #endif
 
+MCUBOOT_LOG_MODULE_DECLARE(mcuboot);
+
 int boot_current_slot;
 
 const uint32_t boot_img_magic[] = {
diff --git a/boot/bootutil/src/loader.c b/boot/bootutil/src/loader.c
index f6f9d92..a2b2379 100644
--- a/boot/bootutil/src/loader.c
+++ b/boot/bootutil/src/loader.c
@@ -40,6 +40,8 @@
 
 #include "mcuboot_config/mcuboot_config.h"
 
+MCUBOOT_LOG_MODULE_DECLARE(mcuboot);
+
 static struct boot_loader_state boot_data;
 
 #if defined(MCUBOOT_VALIDATE_SLOT0) && !defined(MCUBOOT_OVERWRITE_ONLY)
diff --git a/boot/mynewt/mcuboot_config/include/mcuboot_config/mcuboot_logging.h b/boot/mynewt/mcuboot_config/include/mcuboot_config/mcuboot_logging.h
index 26f36d5..9d97106 100644
--- a/boot/mynewt/mcuboot_config/include/mcuboot_config/mcuboot_logging.h
+++ b/boot/mynewt/mcuboot_config/include/mcuboot_config/mcuboot_logging.h
@@ -38,6 +38,9 @@
 #define MCUBOOT_LOG_LEVEL MYNEWT_VAL(BOOTUTIL_LOG_LEVEL)
 #endif
 
+#define MCUBOOT_LOG_MODULE_DECLARE(domain)	/* ignore */
+#define MCUBOOT_LOG_MODULE_REGISTER(domain)	/* ignore */
+
 #if !((MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_OFF) && \
       (MCUBOOT_LOG_LEVEL <= MCUBOOT_LOG_LEVEL_DEBUG))
 #error "Invalid MCUBOOT_LOG_LEVEL config."
diff --git a/boot/zephyr/Kconfig b/boot/zephyr/Kconfig
index e87db5a..2ce1b2d 100644
--- a/boot/zephyr/Kconfig
+++ b/boot/zephyr/Kconfig
@@ -132,10 +132,11 @@
 config BOOT_HAVE_LOGGING
 	bool "MCUboot have logging enabled"
 	default y
-	select SYS_LOG
+	select LOG
+	select LOG_INPLACE_PROCESS
 	help
 	  If y, enables logging on the serial port. The log level can
-	  be defined by setting `SYS_LOG_DEFAULT_LEVEL`.
+	  be defined by setting `LOG_DEFAULT_LEVEL`.
 	  If unsure, leave at the default value.
 
 menuconfig MCUBOOT_SERIAL
diff --git a/boot/zephyr/boards/nrf52840_pca10059.conf b/boot/zephyr/boards/nrf52840_pca10059.conf
index bf63bf7..89cc154 100644
--- a/boot/zephyr/boards/nrf52840_pca10059.conf
+++ b/boot/zephyr/boards/nrf52840_pca10059.conf
@@ -25,6 +25,3 @@
 CONFIG_USB_CDC_ACM=y
 CONFIG_USB_COMPOSITE_DEVICE=n
 CONFIG_USB_MASS_STORAGE=n
-
-# Logging
-CONFIG_SYS_LOG_DEFAULT_LEVEL=1
diff --git a/boot/zephyr/flash_map_extended.c b/boot/zephyr/flash_map_extended.c
index b7fa610..db2f94b 100644
--- a/boot/zephyr/flash_map_extended.c
+++ b/boot/zephyr/flash_map_extended.c
@@ -15,6 +15,8 @@
 
 #include "bootutil/bootutil_log.h"
 
+MCUBOOT_LOG_MODULE_DECLARE(mcuboot);
+
 #if (!defined(CONFIG_XTENSA) && defined(DT_FLASH_DEV_NAME))
 #define FLASH_DEVICE_ID SOC_FLASH_0_ID
 #elif (defined(CONFIG_XTENSA) && defined(DT_SPI_NOR_DRV_NAME))
diff --git a/boot/zephyr/flash_map_legacy.c b/boot/zephyr/flash_map_legacy.c
index 69803fe..b217947 100644
--- a/boot/zephyr/flash_map_legacy.c
+++ b/boot/zephyr/flash_map_legacy.c
@@ -49,6 +49,8 @@
 #define FLASH_AREA_IMAGE_SECTOR_SIZE FLASH_AREA_IMAGE_SCRATCH_SIZE
 #endif
 
+MCUBOOT_LOG_MODULE_DECLARE(mcuboot);
+
 /*
  * Lookup the sector map for a given flash area.  This should fill in
  * `ret` with all of the sectors in the area.  `*cnt` will be set to
diff --git a/boot/zephyr/include/mcuboot_config/mcuboot_logging.h b/boot/zephyr/include/mcuboot_config/mcuboot_logging.h
index 8ee5378..5077451 100644
--- a/boot/zephyr/include/mcuboot_config/mcuboot_logging.h
+++ b/boot/zephyr/include/mcuboot_config/mcuboot_logging.h
@@ -12,38 +12,17 @@
 /*
  * When building for targets running Zephyr, delegate to its native
  * logging subsystem.
- *
- * In this case:
- *
- * - MCUBOOT_LOG_LEVEL determines SYS_LOG_LEVEL,
- * - MCUBOOT_LOG_ERR() and friends are SYS_LOG_ERR() etc.
- * - SYS_LOG_DOMAIN is unconditionally set to "MCUBOOT"
  */
-#define MCUBOOT_LOG_LEVEL_OFF      SYS_LOG_LEVEL_OFF
-#define MCUBOOT_LOG_LEVEL_ERROR    SYS_LOG_LEVEL_ERROR
-#define MCUBOOT_LOG_LEVEL_WARNING  SYS_LOG_LEVEL_WARNING
-#define MCUBOOT_LOG_LEVEL_INFO     SYS_LOG_LEVEL_INFO
-#define MCUBOOT_LOG_LEVEL_DEBUG    SYS_LOG_LEVEL_DEBUG
 
-/* Treat MCUBOOT_LOG_LEVEL equivalently to SYS_LOG_LEVEL. */
-#ifndef MCUBOOT_LOG_LEVEL
-#define MCUBOOT_LOG_LEVEL CONFIG_SYS_LOG_DEFAULT_LEVEL
-#elif (MCUBOOT_LOG_LEVEL < CONFIG_SYS_LOG_OVERRIDE_LEVEL)
-#undef MCUBOOT_LOG_LEVEL
-#define MCUBOOT_LOG_LEVEL CONFIG_SYS_LOG_OVERRIDE_LEVEL
-#endif
+#define MCUBOOT_LOG_MODULE_DECLARE(domain)	LOG_MODULE_DECLARE(domain)
+#define MCUBOOT_LOG_MODULE_REGISTER(domain)	LOG_MODULE_REGISTER(domain)
 
-#define SYS_LOG_LEVEL MCUBOOT_LOG_LEVEL
+#define MCUBOOT_LOG_ERR(...) LOG_ERR(__VA_ARGS__)
+#define MCUBOOT_LOG_WRN(...) LOG_WRN(__VA_ARGS__)
+#define MCUBOOT_LOG_INF(...) LOG_INF(__VA_ARGS__)
+#define MCUBOOT_LOG_DBG(...) LOG_DBG(__VA_ARGS__)
 
-#undef SYS_LOG_DOMAIN
-#define SYS_LOG_DOMAIN "MCUBOOT"
-
-#define MCUBOOT_LOG_ERR(...) SYS_LOG_ERR(__VA_ARGS__)
-#define MCUBOOT_LOG_WRN(...) SYS_LOG_WRN(__VA_ARGS__)
-#define MCUBOOT_LOG_INF(...) SYS_LOG_INF(__VA_ARGS__)
-#define MCUBOOT_LOG_DBG(...) SYS_LOG_DBG(__VA_ARGS__)
-
-#include <logging/sys_log.h>
+#include <logging/log.h>
 
 #endif /* !__BOOTSIM__ */
 
diff --git a/boot/zephyr/main.c b/boot/zephyr/main.c
index 345b449..f4bc4ab 100644
--- a/boot/zephyr/main.c
+++ b/boot/zephyr/main.c
@@ -40,6 +40,8 @@
 };
 #endif
 
+MCUBOOT_LOG_MODULE_REGISTER(mcuboot);
+
 void os_heap_init(void);
 
 #if defined(CONFIG_ARM)
diff --git a/boot/zephyr/prj.conf b/boot/zephyr/prj.conf
index 8a88abc..3bc1e02 100644
--- a/boot/zephyr/prj.conf
+++ b/boot/zephyr/prj.conf
@@ -1,5 +1,4 @@
 CONFIG_CONSOLE_HANDLER=y
-CONFIG_SYS_LOG=y
 CONFIG_DEBUG=y
 CONFIG_SYSTEM_CLOCK_DISABLE=y
 CONFIG_SYS_POWER_MANAGEMENT=n
diff --git a/boot/zephyr/serial_adapter.c b/boot/zephyr/serial_adapter.c
index fc39f71..14adb45 100644
--- a/boot/zephyr/serial_adapter.c
+++ b/boot/zephyr/serial_adapter.c
@@ -25,6 +25,8 @@
 #error Zephyr UART console must been disabled if serial_adapter module is used.
 #endif
 
+MCUBOOT_LOG_MODULE_REGISTER(serial_adapter);
+
 /** @brief Console input representation
  *
  * This struct is used to represent an input line from a serial interface.