diff options
Diffstat (limited to 'fluent-bit/examples/hello_world')
-rw-r--r-- | fluent-bit/examples/hello_world/CMakeLists.txt | 9 | ||||
-rw-r--r-- | fluent-bit/examples/hello_world/README.md | 6 | ||||
-rw-r--r-- | fluent-bit/examples/hello_world/hello_world.c | 60 |
3 files changed, 75 insertions, 0 deletions
diff --git a/fluent-bit/examples/hello_world/CMakeLists.txt b/fluent-bit/examples/hello_world/CMakeLists.txt new file mode 100644 index 00000000..2e55b75f --- /dev/null +++ b/fluent-bit/examples/hello_world/CMakeLists.txt @@ -0,0 +1,9 @@ +set(src + ${src} + hello_world.c + ) + +find_package (Threads) +add_executable(hello_world ${src}) +target_link_libraries(hello_world fluent-bit-shared) +target_link_libraries(hello_world ${CMAKE_THREAD_LIBS_INIT}) diff --git a/fluent-bit/examples/hello_world/README.md b/fluent-bit/examples/hello_world/README.md new file mode 100644 index 00000000..f9fc5a4e --- /dev/null +++ b/fluent-bit/examples/hello_world/README.md @@ -0,0 +1,6 @@ +# Fluent Bit / Hello World + +This tool uses the Fluent Bit library version to flush data to one of the +registered outputs. + +When using Fluent Bit as a library means the caller becomes the input. diff --git a/fluent-bit/examples/hello_world/hello_world.c b/fluent-bit/examples/hello_world/hello_world.c new file mode 100644 index 00000000..f4925bf6 --- /dev/null +++ b/fluent-bit/examples/hello_world/hello_world.c @@ -0,0 +1,60 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* Fluent Bit Demo + * =============== + * 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 <fluent-bit.h> + +int main() +{ + int i; + int n; + char tmp[256]; + flb_ctx_t *ctx; + int in_ffd; + int out_ffd; + + /* Initialize library */ + ctx = flb_create(); + if (!ctx) { + exit(EXIT_FAILURE); + } + + in_ffd = flb_input(ctx, "lib", NULL); + flb_input_set(ctx, in_ffd, "tag", "test", NULL); + + out_ffd = flb_output(ctx, "stdout", NULL); + flb_output_set(ctx, out_ffd, "match", "test", NULL); + + /* Start the background worker */ + flb_start(ctx); + + /* Push some data */ + for (i = 0; i < 100; i++) { + n = snprintf(tmp, sizeof(tmp) - 1, + "[%f, {\"key\": \"val %i\"}]", + flb_time_now(), i); + flb_lib_push(ctx, in_ffd, tmp, n); + } + + flb_stop(ctx); + + /* Release Resources */ + flb_destroy(ctx); + + return 0; +} |