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ライブラリも同梱しています。

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

Committer:
YuuichiAkagawa
Date:
Tue Nov 11 02:14:44 2014 +0000
Revision:
0:b4815a079a4b
Initial release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
YuuichiAkagawa 0:b4815a079a4b 1 /* fluent-logger-mbed
YuuichiAkagawa 0:b4815a079a4b 2 * Copyright (c) 2014 Yuuichi Akagawa
YuuichiAkagawa 0:b4815a079a4b 3 *
YuuichiAkagawa 0:b4815a079a4b 4 * Licensed under the Apache License, Version 2.0 (the "License");
YuuichiAkagawa 0:b4815a079a4b 5 * you may not use this file except in compliance with the License.
YuuichiAkagawa 0:b4815a079a4b 6 * You may obtain a copy of the License at
YuuichiAkagawa 0:b4815a079a4b 7 *
YuuichiAkagawa 0:b4815a079a4b 8 * http://www.apache.org/licenses/LICENSE-2.0
YuuichiAkagawa 0:b4815a079a4b 9 *
YuuichiAkagawa 0:b4815a079a4b 10 * Unless required by applicable law or agreed to in writing, software
YuuichiAkagawa 0:b4815a079a4b 11 * distributed under the License is distributed on an "AS IS" BASIS,
YuuichiAkagawa 0:b4815a079a4b 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
YuuichiAkagawa 0:b4815a079a4b 13 * See the License for the specific language governing permissions and
YuuichiAkagawa 0:b4815a079a4b 14 * limitations under the License.
YuuichiAkagawa 0:b4815a079a4b 15 */
YuuichiAkagawa 0:b4815a079a4b 16
YuuichiAkagawa 0:b4815a079a4b 17 #ifndef FLUENT_LOGGER_MBED_H
YuuichiAkagawa 0:b4815a079a4b 18 #define FLUENT_LOGGER_MBED_H
YuuichiAkagawa 0:b4815a079a4b 19
YuuichiAkagawa 0:b4815a079a4b 20 #include "TCPSocketConnection.h"
YuuichiAkagawa 0:b4815a079a4b 21 #include "uMP.h"
YuuichiAkagawa 0:b4815a079a4b 22
YuuichiAkagawa 0:b4815a079a4b 23 /** Fluent Logger for mbed
YuuichiAkagawa 0:b4815a079a4b 24 *
YuuichiAkagawa 0:b4815a079a4b 25 */
YuuichiAkagawa 0:b4815a079a4b 26 class FluentLogger {
YuuichiAkagawa 0:b4815a079a4b 27 public:
YuuichiAkagawa 0:b4815a079a4b 28 /** Create a FluentLogger instance
YuuichiAkagawa 0:b4815a079a4b 29 *
YuuichiAkagawa 0:b4815a079a4b 30 * @param host fluentd server hostname/ipaddress
YuuichiAkagawa 0:b4815a079a4b 31 * @param port fluentd server port (default: 24224)
YuuichiAkagawa 0:b4815a079a4b 32 * @param bufsize message buffer length (default: 128)
YuuichiAkagawa 0:b4815a079a4b 33 */
YuuichiAkagawa 0:b4815a079a4b 34 FluentLogger(const char *host, const int port = 24224, uint32_t bufsize = 128);
YuuichiAkagawa 0:b4815a079a4b 35
YuuichiAkagawa 0:b4815a079a4b 36 /** Open connection (automatically called on log)
YuuichiAkagawa 0:b4815a079a4b 37 *
YuuichiAkagawa 0:b4815a079a4b 38 * @retval 0 Success
YuuichiAkagawa 0:b4815a079a4b 39 * @retval -1 Failure
YuuichiAkagawa 0:b4815a079a4b 40 */
YuuichiAkagawa 0:b4815a079a4b 41 int open();
YuuichiAkagawa 0:b4815a079a4b 42
YuuichiAkagawa 0:b4815a079a4b 43 /** Close connection (if you want)
YuuichiAkagawa 0:b4815a079a4b 44 *
YuuichiAkagawa 0:b4815a079a4b 45 * @retval 0 Success
YuuichiAkagawa 0:b4815a079a4b 46 * @retval -1 Failure
YuuichiAkagawa 0:b4815a079a4b 47 */
YuuichiAkagawa 0:b4815a079a4b 48 int close();
YuuichiAkagawa 0:b4815a079a4b 49
YuuichiAkagawa 0:b4815a079a4b 50 /** Send simple string message to fluent server with tag.
YuuichiAkagawa 0:b4815a079a4b 51 *
YuuichiAkagawa 0:b4815a079a4b 52 * @param tag tag
YuuichiAkagawa 0:b4815a079a4b 53 * @param msg null terminated string
YuuichiAkagawa 0:b4815a079a4b 54 * @retval 0 Success
YuuichiAkagawa 0:b4815a079a4b 55 * @retval -1 Failure
YuuichiAkagawa 0:b4815a079a4b 56 */
YuuichiAkagawa 0:b4815a079a4b 57 int log(const char *tag, const char *msg);
YuuichiAkagawa 0:b4815a079a4b 58
YuuichiAkagawa 0:b4815a079a4b 59 /** Send MassagePacked message to fluent server with tag.
YuuichiAkagawa 0:b4815a079a4b 60 *
YuuichiAkagawa 0:b4815a079a4b 61 * @param tag tag
YuuichiAkagawa 0:b4815a079a4b 62 * @param msg MessagePacked message
YuuichiAkagawa 0:b4815a079a4b 63 * @retval 0 Success
YuuichiAkagawa 0:b4815a079a4b 64 * @retval -1 Failure
YuuichiAkagawa 0:b4815a079a4b 65 */
YuuichiAkagawa 0:b4815a079a4b 66 int log(const char *tag, uMP &msg);
YuuichiAkagawa 0:b4815a079a4b 67
YuuichiAkagawa 0:b4815a079a4b 68 private:
YuuichiAkagawa 0:b4815a079a4b 69 /** FluentLogger
YuuichiAkagawa 0:b4815a079a4b 70 */
YuuichiAkagawa 0:b4815a079a4b 71 FluentLogger();
YuuichiAkagawa 0:b4815a079a4b 72 /** send message via TCP
YuuichiAkagawa 0:b4815a079a4b 73 * @retval 0 Success
YuuichiAkagawa 0:b4815a079a4b 74 * @retval -1 Failure
YuuichiAkagawa 0:b4815a079a4b 75 */
YuuichiAkagawa 0:b4815a079a4b 76 int send();
YuuichiAkagawa 0:b4815a079a4b 77
YuuichiAkagawa 0:b4815a079a4b 78 TCPSocketConnection *_sock;
YuuichiAkagawa 0:b4815a079a4b 79 const char *_host;
YuuichiAkagawa 0:b4815a079a4b 80 const int _port;
YuuichiAkagawa 0:b4815a079a4b 81 int _timeout;
YuuichiAkagawa 0:b4815a079a4b 82 uMP *_mp;
YuuichiAkagawa 0:b4815a079a4b 83 };
YuuichiAkagawa 0:b4815a079a4b 84
YuuichiAkagawa 0:b4815a079a4b 85 #endif