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

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

FluentLogger.h

Committer:
YuuichiAkagawa
Date:
2014-12-15
Revision:
1:6b1268731465
Parent:
0:b4815a079a4b

File content as of revision 1:6b1268731465:

/* fluent-logger-mbed 
 * Copyright (c) 2014 Yuuichi Akagawa
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef FLUENT_LOGGER_MBED_H
#define FLUENT_LOGGER_MBED_H

#include "TCPSocketConnection.h"
#include "uMP.h"

/** Fluent Logger for mbed
 *
 */
class FluentLogger {
public:
    /** Create a FluentLogger instance
     *
     * @param host fluentd server hostname/ipaddress
     * @param port fluentd server port (default: 24224)
     * @param bufsize message buffer length (default: 128)
     */
    FluentLogger(const char *host, const int port = 24224, uint32_t bufsize = 128);

    /** Open connection (automatically called on log)
     *
     * @retval 0 Success
     * @retval -1 Failure
     */
    int open();

    /** Close connection (if you want)
     *
     * @retval 0 Success
     * @retval -1 Failure
     */
    int close();

    /** Send simple string message to fluent server with tag.
     *
     * @param tag tag
     * @param msg null terminated string
     * @retval 0 Success
     * @retval -1 Failure
     */
    int log(const char *tag, const char *msg);

    /** Send MassagePacked message to fluent server with tag.
     *
     * @param tag tag
     * @param msg MessagePacked message
     * @retval 0 Success
     * @retval -1 Failure
     */
    int log(const char *tag, uMP &msg);

private:
    /** FluentLogger
     */
    FluentLogger();
    /** send message via TCP
     * @retval 0 Success
     * @retval -1 Failure
     */
    int send();

    TCPSocketConnection *_sock;
    const char *_host;
    const int  _port;
    int        _timeout;
    uMP        *_mp;
};

#endif