diff --git a/CMakeLists.txt b/CMakeLists.txt index f962a806b45..9a9de7e496e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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 diff --git a/lib/msgpack-0.5.9/CMakeLists.txt b/lib/msgpack-0.5.9/CMakeLists.txt index 79c40d0b4cc..0b65cda193d 100644 --- a/lib/msgpack-0.5.9/CMakeLists.txt +++ b/lib/msgpack-0.5.9/CMakeLists.txt @@ -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) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index c26691a4632..584e6516354 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -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( diff --git a/plugins/out_stdout/CMakeLists.txt b/plugins/out_stdout/CMakeLists.txt new file mode 100644 index 00000000000..40bee51bb61 --- /dev/null +++ b/plugins/out_stdout/CMakeLists.txt @@ -0,0 +1,5 @@ +set(src + stdout.c) + +FLB_PLUGIN(out_stdout "${src}" "") +target_link_libraries(flb-plugin-out_stdout msgpack) diff --git a/plugins/out_stdout/stdout.c b/plugins/out_stdout/stdout.c new file mode 100644 index 00000000000..6d7fe0d1444 --- /dev/null +++ b/plugins/out_stdout/stdout.c @@ -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 + +#include +#include + +#include + +#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 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, +}; diff --git a/plugins/out_stdout/stdout.h b/plugins/out_stdout/stdout.h new file mode 100644 index 00000000000..9c7501bde63 --- /dev/null +++ b/plugins/out_stdout/stdout.h @@ -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