FluentLogger: fluent-logger-mbed A structured logger for Fluentd (mbed)

Dependents:   FluentLogger_Hello SNIC-FluentLogger-example

FluentLogger

Fluentd Logo

What is this ?

You can logging to Fluentd server.
This library included subset of MassagePack library.

Supported MessagePack formats(encode only)

format namefirst byte (in hex)
positive fixint0x00 - 0x7f
fixmap0x80 - 0x8f
fixarray0x90 - 0x9f
fixstr0xa0 - 0xbf
nil0xc0
false0xc2
true0xc3
float 320xca
float 640xcb
uint 80xcc
uint 160xcd
uint 320xce
uint 640xcf
int 80xd0
int 160xd1
int 320xd2
int 640xd3
str 80xd9
negative fixint0xe0 - 0xff

これは何?

Fluentd サーバにログを送信するためのライブラリです。
サブセット版のMassagePackライブラリも同梱しています。

サーバ側ダウン時の再接続機能は限定的に実装されています。 現時点での実装は送信時に切断を検知し、次回送信時に再接続する仕様です。

Files at this revision

API Documentation at this revision

Comitter:
YuuichiAkagawa
Date:
Mon Dec 15 15:37:23 2014 +0000
Parent:
0:b4815a079a4b
Commit message:
rename uMP functions(set_array->start_array, set_map->start_map); add uMP map functions

Changed in this revision

FluentLogger.cpp Show annotated file Show diff for this revision Revisions of this file
uMP.cpp Show annotated file Show diff for this revision Revisions of this file
uMP.h Show annotated file Show diff for this revision Revisions of this file
diff -r b4815a079a4b -r 6b1268731465 FluentLogger.cpp
--- a/FluentLogger.cpp	Tue Nov 11 02:14:44 2014 +0000
+++ b/FluentLogger.cpp	Mon Dec 15 15:37:23 2014 +0000
@@ -61,7 +61,7 @@
     _mp->init();
 
     // tag, timestamp, message
-    if (!_mp->set_array(3)) {
+    if (!_mp->start_array(3)) {
         return -1;
     }
     if (!_mp->set_str(tag, strlen(tag))) {
@@ -84,7 +84,7 @@
 
 int FluentLogger::log(const char *tag, uMP &mpmsg)
 {
-    if (!_sock->is_connected()) {
+    if (_sock == NULL || !_sock->is_connected()) {
         if (open() < 0) {
             return -1;
         }
@@ -92,7 +92,7 @@
     _mp->init();
 
     // tag, timestamp, message
-    if (!_mp->set_array(3)) {
+    if (!_mp->start_array(3)) {
         return -1;
     }
     if (!_mp->set_str(tag, strlen(tag))) {
diff -r b4815a079a4b -r 6b1268731465 uMP.cpp
--- a/uMP.cpp	Tue Nov 11 02:14:44 2014 +0000
+++ b/uMP.cpp	Mon Dec 15 15:37:23 2014 +0000
@@ -50,7 +50,7 @@
     return set_buffer(TAG_FALSE);
 }
 
-bool uMP::set_array(uint32_t size)
+bool uMP::start_array(uint32_t size)
 {
     if (size <= 0x0f) {
         return set_buffer((uint8_t)(TAG_FIXARRAY | size));
@@ -58,7 +58,7 @@
     return false;
 }
 
-bool uMP::set_map(uint32_t size)
+bool uMP::start_map(uint32_t size)
 {
     if (size <= 0x0f) {
         return set_buffer((uint8_t)(TAG_FIXMAP | size));
@@ -195,6 +195,11 @@
     return false;
 }
 
+bool uMP::set_str(const std::string& str)
+{
+    return set_str(str.c_str(), (uint32_t)str.size());
+}
+
 bool uMP::set_fixstr(const char *data, uint8_t size)
 {
     if (size > 0x1f) {
@@ -307,3 +312,74 @@
     *(x+1) = h;
     return t;
 }
+
+// map functions
+bool uMP::map(const std::string& k, uint8_t v)
+{
+    if( set_str(k) == false )
+        return false;
+    return set_u8(v);
+}
+
+bool uMP::map(const std::string& k, uint16_t v)
+{
+    if( set_str(k) == false )
+        return false;
+    return set_u16(v);
+}
+
+bool uMP::map(const std::string& k, uint32_t v)
+{
+    if( set_str(k) == false )
+        return false;
+    return set_uint(v);
+}
+
+bool uMP::map(const std::string& k, int8_t v)
+{
+    if( set_str(k) == false )
+        return false;
+    return set_s8(v);
+}
+
+bool uMP::map(const std::string& k, int16_t v)
+{
+    if( set_str(k) == false )
+        return false;
+    return set_s16(v);
+}
+
+bool uMP::map(const std::string& k, int32_t v)
+{
+    if( set_str(k) == false )
+        return false;
+    return set_sint(v);
+}
+
+bool uMP::map(const std::string& k, float v)
+{
+    if( set_str(k) == false )
+        return false;
+    return set_float(v);
+}
+
+bool uMP::map(const std::string& k, double v)
+{
+    if( set_str(k) == false )
+        return false;
+    return set_double(v);
+}
+
+bool uMP::map(const std::string& k, const char *v)
+{
+    if( set_str(k) == false )
+        return false;
+    return set_str(v);
+}
+
+bool uMP::map(const std::string& k, const std::string& v)
+{
+    if( set_str(k) == false )
+        return false;
+    return set_str(v);
+}
diff -r b4815a079a4b -r 6b1268731465 uMP.h
--- a/uMP.h	Tue Nov 11 02:14:44 2014 +0000
+++ b/uMP.h	Mon Dec 15 15:37:23 2014 +0000
@@ -19,6 +19,7 @@
 
 #include <stdint.h>
 #include <string.h>
+#include <string>
 
 /** Subset of MessagePack implementation.
  *
@@ -57,7 +58,7 @@
      * @retval true Success
      * @retval false Failure
      */
-    bool set_array(uint32_t size);
+    bool start_array(uint32_t size);
 
     /** Start map format
      *
@@ -65,7 +66,7 @@
      * @retval true Success
      * @retval false Failure
      */
-    bool set_map(uint32_t size);
+    bool start_map(uint32_t size);
 
     /** Set NIL message
      *
@@ -199,6 +200,16 @@
      */
     bool set_str(const char *data, uint32_t size);
 
+    /** Set string message
+     *
+     * Auto route the optimal function.
+     *
+     * @param str string of message string
+     * @retval true Success
+     * @retval false Failure
+     */
+    bool set_str(const std::string& str);
+
     /** Set string message (upto 31 bytes)
      *
      * @param data Pointer of message string
@@ -229,6 +240,105 @@
      */
     bool set_raw(const char *data, uint8_t size);
 
+    /** associate a key with value (bool)
+     *
+     * @param k key string
+     * @param v bool value(true/false)
+     * @retval true Success
+     * @retval false Failure
+     */
+    bool map(const std::string& k, bool v);
+
+    /** associate a key with value (uint8_t)
+     *
+     * @param k key string
+     * @param v value
+     * @retval true Success
+     * @retval false Failure
+     */
+    bool map(const std::string& k, uint8_t v);
+
+    /** associate a key with value (uint16_t)
+     *
+     * @param k key string
+     * @param v value
+     * @retval true Success
+     * @retval false Failure
+     */
+    bool map(const std::string& k, uint16_t v);
+
+    /** associate a key with value (uint32_t)
+     *
+     * @param k key string
+     * @param v value
+     * @retval true Success
+     * @retval false Failure
+     */
+    bool map(const std::string& k, uint32_t v);
+
+    /** associate a key with value (int8_t)
+     *
+     * @param k key string
+     * @param v value
+     * @retval true Success
+     * @retval false Failure
+     */
+    bool map(const std::string& k, int8_t v);
+
+    /** associate a key with value (int16_t)
+     *
+     * @param k key string
+     * @param v value
+     * @retval true Success
+     * @retval false Failure
+     */
+    bool map(const std::string& k, int16_t v);
+
+    /** associate a key with value (int32_t)
+     *
+     * @param k key string
+     * @param v value
+     * @retval true Success
+     * @retval false Failure
+     */
+    bool map(const std::string& k, int32_t v);
+
+    /** associate a key with value (float)
+     *
+     * @param k key string
+     * @param v value
+     * @retval true Success
+     * @retval false Failure
+     */
+    bool map(const std::string& k, float v);
+
+    /** associate a key with value (double)
+     *
+     * @param k key string
+     * @param v value
+     * @retval true Success
+     * @retval false Failure
+     */
+    bool map(const std::string& k, double v);
+
+    /** associate a key with value (char * string)
+     *
+     * @param k key string
+     * @param v value
+     * @retval true Success
+     * @retval false Failure
+     */
+    bool map(const std::string& k, const char *v);
+
+    /** associate a key with value (string)
+     *
+     * @param k key string
+     * @param v value
+     * @retval true Success
+     * @retval false Failure
+     */
+    bool map(const std::string& k, const std::string& v);
+
 private:
     enum MpTag{
         TAG_POSITIVE_FIXNUM = 0x00,