FluentLogger: fluent-logger-mbed A structured logger for Fluentd (mbed)
Dependents: FluentLogger_Hello SNIC-FluentLogger-example
FluentLogger
What is this ?
You can logging to Fluentd server.
This library included subset of MassagePack library.
Supported MessagePack formats(encode only)
format name | first byte (in hex) |
---|---|
positive fixint | 0x00 - 0x7f |
fixmap | 0x80 - 0x8f |
fixarray | 0x90 - 0x9f |
fixstr | 0xa0 - 0xbf |
nil | 0xc0 |
false | 0xc2 |
true | 0xc3 |
float 32 | 0xca |
float 64 | 0xcb |
uint 8 | 0xcc |
uint 16 | 0xcd |
uint 32 | 0xce |
uint 64 | 0xcf |
int 8 | 0xd0 |
int 16 | 0xd1 |
int 32 | 0xd2 |
int 64 | 0xd3 |
str 8 | 0xd9 |
negative fixint | 0xe0 - 0xff |
これは何?
Fluentd サーバにログを送信するためのライブラリです。
サブセット版のMassagePackライブラリも同梱しています。
サーバ側ダウン時の再接続機能は限定的に実装されています。 現時点での実装は送信時に切断を検知し、次回送信時に再接続する仕様です。
Diff: FluentLogger.h
- Revision:
- 0:b4815a079a4b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FluentLogger.h Tue Nov 11 02:14:44 2014 +0000 @@ -0,0 +1,85 @@ +/* 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