Helpful logging and error format

Dependents:   Waldo_Embed_V2

Inspired by this blog post.

Work in Progress

Revision:
1:491d2a7f4207
Parent:
0:3054bbdace4c
Child:
2:c54746c59ba4
--- a/LogUtil.h	Fri Mar 29 17:36:50 2013 +0000
+++ b/LogUtil.h	Fri Mar 29 20:02:18 2013 +0000
@@ -3,7 +3,7 @@
  * @brief   Utility to log messages during runtime
  * @author  sam grove
  * @version 1.0
- * @see     http://www.drdobbs.com/cpp/a-lightweight-logger-for-c/240147505?pgno=2
+ * @see     http://www.drdobbs.com/cpp/a-lightweight-logger-for-c/240147505
  *
  * Copyright (c) 2013
  *
@@ -32,7 +32,9 @@
     fprintf(STREAM, ##__VA_ARGS__)
 #define ERROR(...)  \
     fprintf(STREAM, "ERROR: %s L#%d ", __PRETTY_FUNCTION__, __LINE__); \
-    fprintf(STREAM, ##__VA_ARGS__)
+    fprintf(STREAM, ##__VA_ARGS__); \
+    fflush(STREAM); \
+    exit(1)
  
 /** Using the LogUtil class
  *
@@ -41,25 +43,22 @@
  *  #include "mbed.h"
  *  #include "LogUtil.h"
  *  
- *  LogUtil log;
+ *  LogUtil logger;
  *
  *  int main()
  *  {
  *     LOG("This is a log\n");
  *     WARN("This is a warning\n");
- *     ERROR("This is an error\n");
  *
- *     for(int i=0; i<10; ++i) {
+ *     for(int i=0; i<3; ++i) {
  *         LOG("Log message #%d\n", i);
  *     }
  *
- *     for(int i=0; i<10; ++i) {
+ *     for(int i=0; i<3; ++i) {
  *         WARN("Warn message #%d\n", i);
  *     }
  *
- *     for(int i=0; i<10; ++i) {
- *         ERROR("Error message #%d\n", i);
- *     }
+ *     ERROR("This is an error\n");
  *  }
  * @endcode
  */