Yuuichi Akagawa / FluentLogger

Dependents:   FluentLogger_Hello SNIC-FluentLogger-example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FluentLogger.h Source File

FluentLogger.h

00001 /* fluent-logger-mbed 
00002  * Copyright (c) 2014 Yuuichi Akagawa
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef FLUENT_LOGGER_MBED_H
00018 #define FLUENT_LOGGER_MBED_H
00019 
00020 #include "TCPSocketConnection.h"
00021 #include "uMP.h"
00022 
00023 /** Fluent Logger for mbed
00024  *
00025  */
00026 class FluentLogger {
00027 public:
00028     /** Create a FluentLogger instance
00029      *
00030      * @param host fluentd server hostname/ipaddress
00031      * @param port fluentd server port (default: 24224)
00032      * @param bufsize message buffer length (default: 128)
00033      */
00034     FluentLogger(const char *host, const int port = 24224, uint32_t bufsize = 128);
00035 
00036     /** Open connection (automatically called on log)
00037      *
00038      * @retval 0 Success
00039      * @retval -1 Failure
00040      */
00041     int open();
00042 
00043     /** Close connection (if you want)
00044      *
00045      * @retval 0 Success
00046      * @retval -1 Failure
00047      */
00048     int close();
00049 
00050     /** Send simple string message to fluent server with tag.
00051      *
00052      * @param tag tag
00053      * @param msg null terminated string
00054      * @retval 0 Success
00055      * @retval -1 Failure
00056      */
00057     int log(const char *tag, const char *msg);
00058 
00059     /** Send MassagePacked message to fluent server with tag.
00060      *
00061      * @param tag tag
00062      * @param msg MessagePacked message
00063      * @retval 0 Success
00064      * @retval -1 Failure
00065      */
00066     int log(const char *tag, uMP &msg);
00067 
00068 private:
00069     /** FluentLogger
00070      */
00071     FluentLogger();
00072     /** send message via TCP
00073      * @retval 0 Success
00074      * @retval -1 Failure
00075      */
00076     int send();
00077 
00078     TCPSocketConnection *_sock;
00079     const char *_host;
00080     const int  _port;
00081     int        _timeout;
00082     uMP        *_mp;
00083 };
00084 
00085 #endif