Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

out_stdout: new STDOUT Output Plugin. #5

Merged
merged 1 commit into from
Jun 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ option(WITH_IN_CPU "Enable CPU input plugin" Yes)
option(WITH_IN_KMSG "Enable Kernel log input plugin" Yes)
option(WITH_OUT_FLUENTD "Enable Fluentd output plugin" Yes)
option(WITH_OUT_TD "Enable Treasure Data output plugin" Yes)
option(WITH_OUT_STDOUT "Enable STDOUT output plugin" Yes)

# Enable all features
if(WITH_ALL)
Expand All @@ -29,6 +30,7 @@ if(WITH_ALL)
set(WITH_IN_CPU 1)
set(WITH_OUT_FLUENTD 1)
set(WITH_OUT_TD 1)
set(WITH_OUT_STDOUT 1)
endif()

# Enable Debug symbols if specified
Expand Down
1 change: 1 addition & 0 deletions lib/msgpack-0.5.9/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SET (prefix ${CMAKE_INSTALL_PREFIX})
SET (exec_prefix "\${prefix}")
SET (libdir "\${exec_prefix}/lib")
SET (includedir "\${prefix}/include")
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")

FIND_PACKAGE (GTest)
FIND_PACKAGE (ZLIB)
Expand Down
1 change: 1 addition & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ REGISTER_IN_PLUGIN("in_cpu")
REGISTER_IN_PLUGIN("in_kmsg")
REGISTER_OUT_PLUGIN("out_fluentd")
REGISTER_OUT_PLUGIN("out_td")
REGISTER_OUT_PLUGIN("out_stdout")

# Generate the header from the template
configure_file(
Expand Down
5 changes: 5 additions & 0 deletions plugins/out_stdout/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(src
stdout.c)

FLB_PLUGIN(out_stdout "${src}" "")
target_link_libraries(flb-plugin-out_stdout msgpack)
86 changes: 86 additions & 0 deletions plugins/out_stdout/stdout.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2015 Treasure Data Inc.
*
* 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.
*/

#include <stdio.h>

#include <fluent-bit/flb_output.h>
#include <fluent-bit/flb_utils.h>

#include <msgpack.h>

#include "stdout.h"

int cb_stdout_init(struct flb_config *config)
{
/* do nothing */
return 0;
}

int cb_stdout_flush(void *data, size_t bytes, void *out_context,
struct flb_config *config)
{
msgpack_unpacked result;
size_t off = 0, cnt = 0;

(void) out_context;
(void) config;
/* See: in_forward.rb of fluentd.
*
* message Entry {
* 1: long time
* 2: object record
* }
*
* message Forward {
* 1: string tag
* 2: list<Entry> entries
* 3: object option (optional)
* }
*
* message PackedForward {
* 1: string tag
* 2: raw entries # msgpack stream of Entry
* 3: object option (optional)
* }
*
* message Message {
* 1: string tag
* 2: long? time
* 3: object record
* 4: object option (optional)
* }
*/
msgpack_unpacked_init(&result);
while (msgpack_unpack_next(&result, data, bytes, &off)) {
/* FIXME: lazy output */
printf("[%zd] ", cnt++);
msgpack_object_print(stdout, result.data);
printf("\n");
}
msgpack_unpacked_destroy(&result);
return bytes;
}

struct flb_output_plugin out_stdout_plugin = {
.name = "stdout",
.description = "Prints events to STDOUT",
.cb_init = cb_stdout_init,
.cb_flush = cb_stdout_flush,
.flags = FLB_OUTPUT_NOPROT,
};
23 changes: 23 additions & 0 deletions plugins/out_stdout/stdout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2015 Treasure Data Inc.
*
* 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 FLB_OUT_STDOUT
#define FLB_OUT_STDOUT

#endif