diff --git a/examples/CC3200/main.c b/examples/CC3200/main.c
index d67475b62612a24ec3d23148de1f4385b4d046b7..7101b8347137b68be2d8345049f073edb3cf188d 100644
--- a/examples/CC3200/main.c
+++ b/examples/CC3200/main.c
@@ -366,6 +366,7 @@ int main() {
 
   setvbuf(stdout, NULL, _IONBF, 0);
   setvbuf(stderr, NULL, _IONBF, 0);
+  cs_log_set_file(stdout);
   cs_log_set_level(LL_INFO);
 
   MAP_PinTypeI2C(PIN_01, PIN_MODE_1); /* SDA */
diff --git a/mongoose.c b/mongoose.c
index 5de0bc6821f45752edfbc366e4eb8a447b3f0048..5748f4fdd135180732ce2b133878865d9cc3449b 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -346,41 +346,52 @@ int cs_base64_decode(const unsigned char *s, int len, char *dst) {
 
 /* Amalgamated: #include "common/cs_time.h" */
 
-enum cs_log_level s_cs_log_level =
+enum cs_log_level cs_log_level =
 #ifdef CS_ENABLE_DEBUG
     LL_VERBOSE_DEBUG;
 #else
     LL_ERROR;
 #endif
 
+#ifndef CS_DISABLE_STDIO
+
+FILE *cs_log_file = NULL;
+
 #ifdef CS_LOG_TS_DIFF
 double cs_log_ts;
 #endif
 
-#ifndef CS_DISABLE_STDIO
 void cs_log_printf(const char *fmt, ...) {
   va_list ap;
 #ifdef CS_LOG_TS_DIFF
   double now = cs_time();
-  fprintf(stderr, "%7u ", (unsigned int) ((now - cs_log_ts) * 1000000));
+#endif
+
+  if (cs_log_file == NULL) cs_log_file = stderr;
+#ifdef CS_LOG_TS_DIFF
+  fprintf(cs_log_file, "%7u ", (unsigned int) ((now - cs_log_ts) * 1000000));
 #endif
   va_start(ap, fmt);
-  vfprintf(stderr, fmt, ap);
+  vfprintf(cs_log_file, fmt, ap);
   va_end(ap);
-  fputc('\n', stderr);
+  fputc('\n', cs_log_file);
 #ifdef CS_LOG_TS_DIFF
   cs_log_ts = now;
 #endif
-  fflush(stderr);
+  fflush(cs_log_file);
 }
 #endif /* !CS_DISABLE_STDIO */
 
 void cs_log_set_level(enum cs_log_level level) {
-  s_cs_log_level = level;
-#ifdef CS_LOG_TS_DIFF
+  cs_log_level = level;
+#if defined(CS_LOG_TS_DIFF) && !defined(CS_DISABLE_STDIO)
   cs_log_ts = cs_time();
 #endif
 }
+
+void cs_log_set_file(FILE *file) {
+  cs_log_file = file;
+}
 #ifdef MG_MODULE_LINES
 #line 1 "./src/../../common/cs_dirent.c"
 #endif
diff --git a/mongoose.h b/mongoose.h
index 2a827edf2b68c8ca46f5fc0f7377750912eab373..e5b39b5d14234ad5e341d80bf736dd7b89e79ff8 100644
--- a/mongoose.h
+++ b/mongoose.h
@@ -637,29 +637,29 @@ enum cs_log_level {
   _LL_MAX = 5,
 };
 
-extern enum cs_log_level s_cs_log_level;
 void cs_log_set_level(enum cs_log_level level);
 
 #ifndef CS_DISABLE_STDIO
 
-#ifdef CS_LOG_TS_DIFF
-extern double cs_log_ts;
-#endif
+#include <stdio.h>
+
+void cs_log_set_file(FILE *file);
 
+extern enum cs_log_level cs_log_level;
 void cs_log_printf(const char *fmt, ...);
 
-#define LOG(l, x)                        \
-  if (s_cs_log_level >= l) {             \
-    fprintf(stderr, "%-20s ", __func__); \
-    cs_log_printf x;                     \
+#define LOG(l, x)                      \
+  if (cs_log_level >= l) {             \
+    cs_log_printf("%-20s ", __func__); \
+    cs_log_printf x;                   \
   }
 
 #ifndef CS_NDEBUG
 
-#define DBG(x)                              \
-  if (s_cs_log_level >= LL_VERBOSE_DEBUG) { \
-    fprintf(stderr, "%-20s ", __func__);    \
-    cs_log_printf x;                        \
+#define DBG(x)                            \
+  if (cs_log_level >= LL_VERBOSE_DEBUG) { \
+    cs_log_printf("%-20s ", __func__);    \
+    cs_log_printf x;                      \
   }
 
 #else /* NDEBUG */