]> granicus.if.org Git - esp-idf/commitdiff
return old handler from esp_log_set_vprintf()
authorAndrew Dikarev <phonec@mail.ru>
Sat, 18 Nov 2017 14:27:06 +0000 (16:27 +0200)
committerIvan Grokhotkov <ivan@espressif.com>
Wed, 22 Nov 2017 03:01:43 +0000 (11:01 +0800)
Merges #1286

components/log/include/esp_log.h
components/log/log.c

index 085970c51ebc9ae4d642d166151abc36e43d55f7..e525bca3c0a042557ed3055279c84d6b80da6629 100644 (file)
@@ -55,11 +55,14 @@ void esp_log_level_set(const char* tag, esp_log_level_t level);
  * @brief Set function used to output log entries
  *
  * By default, log output goes to UART0. This function can be used to redirect log
- * output to some other destination, such as file or network.
+ * output to some other destination, such as file or network. Returns the original
+ * log handler, which may be necessary to return output to the previous destination.
  *
- * @param func Function used for output. Must have same signature as vprintf.
+ * @param func new Function used for output. Must have same signature as vprintf.
+ *
+ * @return func old Function used for output.
  */
-void esp_log_set_vprintf(vprintf_like_t func);
+vprintf_like_t esp_log_set_vprintf(vprintf_like_t func);
 
 /**
  * @brief Function which returns timestamp to be used in log output
index 038e8e16357b2d89c0e1eb0ea0c30e474de8d2af..370c8b01cef54a24dbbe16d97dacab8776037e55 100644 (file)
@@ -106,9 +106,18 @@ static inline void heap_swap(int i, int j);
 static inline bool should_output(esp_log_level_t level_for_message, esp_log_level_t level_for_tag);
 static inline void clear_log_level_list();
 
-void esp_log_set_vprintf(vprintf_like_t func)
+vprintf_like_t esp_log_set_vprintf(vprintf_like_t func)
 {
+    if (!s_log_mutex) {
+        s_log_mutex = xSemaphoreCreateMutex();
+    }
+    xSemaphoreTake(s_log_mutex, portMAX_DELAY);
+
+    vprintf_like_t orig_func = s_log_print_func;
     s_log_print_func = func;
+
+    xSemaphoreGive(s_log_mutex);
+    return orig_func;
 }
 
 void esp_log_level_set(const char* tag, esp_log_level_t level)