Sample for the FluentLogger library.

Dependencies:   EthernetInterface FluentLogger mbed-rtos mbed

Fluentd Logo

Example for simple message logging.

main.cpp

#include "mbed.h"
#include "rtos.h"
#include "EthernetInterface.h"
#include "FluentLogger.h"

EthernetInterface eth;
FluentLogger logger("192.168.0.1");  // please set your Fluentd server

int main() 
{
    eth.init(); //Use DHCP
    eth.connect();

    while(1) {
        logger.log("debug.mbed", "Hello mbed"); //message body is simple string
        wait_ms(10000);
    }
    logger.close();
    eth.disconnect();  
}

Server Configuration

Fluentd daemon must be lauched with the following configuration:

<source>
  type tcp
  port 24224
</source>

<match debug.**>
  type stdout
</match>

Files at this revision

API Documentation at this revision

Comitter:
YuuichiAkagawa
Date:
Mon Dec 15 15:41:47 2014 +0000
Parent:
0:160f68fca7a0
Commit message:
update sample

Changed in this revision

FluentLogger.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 160f68fca7a0 -r 4c31b3159209 FluentLogger.lib
--- a/FluentLogger.lib	Tue Nov 11 12:59:34 2014 +0000
+++ b/FluentLogger.lib	Mon Dec 15 15:41:47 2014 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/YuuichiAkagawa/code/FluentLogger/#b4815a079a4b
+http://developer.mbed.org/users/YuuichiAkagawa/code/FluentLogger/#6b1268731465
diff -r 160f68fca7a0 -r 4c31b3159209 main.cpp
--- a/main.cpp	Tue Nov 11 12:59:34 2014 +0000
+++ b/main.cpp	Mon Dec 15 15:41:47 2014 +0000
@@ -15,7 +15,6 @@
  */
 
 #include "mbed.h"
-#include "rtos.h"
 #include "EthernetInterface.h"
 #include "FluentLogger.h"
 
@@ -24,47 +23,64 @@
 
 int main() 
 {
-    uMP mp(64); //Message body
-    eth.init(); //Use DHCP
+    eth.init();     //Use DHCP
     eth.connect();
+    uMP mp(64);     //Message body
+    
+    logger.open();  //connect to fluentd server (omissible)
 
-#if 0
-//test
-    mp.init(); // need init every time
-    mp.set_array(7);
-    mp.set_str("sint", 4);
-    mp.set_sint(0);
-    mp.set_sint(1);
-    mp.set_sint(-1);
-    mp.set_sint(-128);
-    mp.set_sint(-32768);
-    mp.set_sint(-2147483648);
-    logger.log("debug.mbed", mp);
+//sample
+    //array sample with primitive functions
+    //YYYY-MM-DD HH:MM:SS zzzzz debug.test: ["sint",0,1,-1,-128,-32768,-2147483648]
+    mp.init();                    // need init every time
+    mp.start_array(7);            // declare array for seven elements. it can mixed type.
+    mp.set_str("sint", 4);        // 1st element
+    mp.set_sint(0);               // 2nd element
+    mp.set_sint(1);               // 3rd element
+    mp.set_sint(-1);              // 4th element
+    mp.set_sint(-128);            // 5th element
+    mp.set_sint(-32768);          // 6th element
+    mp.set_sint(-2147483648);     // 7th element
+    logger.log("debug.test", mp); // emit
 
-    mp.init(); // need init every time
-    mp.set_array(7);
-    mp.set_str("uint", 4);
-    mp.set_uint(0);
-    mp.set_uint(1);
-    mp.set_uint(128);
-    mp.set_uint(0xff);
-    mp.set_uint(0xffff);
-    mp.set_uint(0xffffffff);
-    logger.log("debug.mbed", mp);
+    //array sample with primitive functions
+    //YYYY-MM-DD HH:MM:SS zzzzz debug.test: ["uint",0,1,128,255,65535,4294967295]
+    mp.init();                    // need init every time
+    mp.start_array(7);            // declare array for seven elements. it can mixed type.
+    mp.set_str("uint", 4);        // 1st element
+    mp.set_uint(0);               // 2nd element
+    mp.set_uint(1);               // 3rd element
+    mp.set_uint(128);             // 4th element
+    mp.set_uint(0xff);            // 5th element
+    mp.set_uint(0xffff);          // 6th element
+    mp.set_uint(0xffffffff);      // 7th element
+    logger.log("debug.test", mp);
 
-    mp.init(); // need init every time
-    mp.set_map(2);
-    mp.set_str("float", 5);
-    mp.set_float(1.0/3);
-    mp.set_str("double", 6);
-    mp.set_double(1.0/3);
-    logger.log("debug.mbed", mp);
-#endif
+    //map sample with primitive functions
+    //YYYY-MM-DD HH:MM:SS zzzzz debug.test: {"string":"Hi!","float":0.3333333432674408,"double":0.3333333333333333}
+    mp.init();                         // need init every time
+    mp.start_map(3);                   // declare map for three paires.
+    mp.set_str("string", 6);           // 1st key 
+    mp.set_str("Hi!", 3);              // 1st value
+    mp.set_str("float", 5);            // 2nd key 
+    mp.set_float(1.0/3);               // 2nd value
+    mp.set_str("double", 6);           // 3rd key
+    mp.set_double(1.0/3);              // 3rd value
+    logger.log("debug.test", mp);      // emit
+
+    //map sample with simple method. same as prev sample (but need more CPU cycle)
+    //YYYY-MM-DD HH:MM:SS zzzzz debug.test: {"string":"Hi!","float":0.3333333432674408,"double":0.3333333333333333}
+    mp.init();                         // need init every time
+    mp.start_map(3);                   // declare map for two paires.
+    mp.map("string", "Hi!");           // 1st key/value pair
+    mp.map("float", (float)(1.0/3));   // 2nd key/value pair
+    mp.map("double", (double)(1.0/3)); // 3rd key/value pair
+    logger.log("debug.mbed", mp);      // emit
 
     while(1) {
         logger.log("debug.mbed", "Hello mbed"); //message body is simple string
+        logger.close();            //close a connection (if you want)
         wait_ms(10000);
     }
-    logger.close();
     eth.disconnect();  
 }