You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by sw...@apache.org on 2023/04/29 08:13:00 UTC
[logging-log4cxx] 01/01: Document how to send events to a fluent-bit server
This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a commit to branch fluent_bit_support
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
commit 51229847e80eef3c0c45f1cfa0dc8339a01dde18
Author: Stephen Webb <sw...@gmail.com>
AuthorDate: Sat Apr 29 18:12:30 2023 +1000
Document how to send events to a fluent-bit server
---
src/main/include/log4cxx/net/xmlsocketappender.h | 39 +++++++++++++++---------
src/test/cpp/net/xmlsocketappendertestcase.cpp | 14 +++++++++
src/test/resources/input/xml/fluent-bit.xml | 30 ++++++++++++++++++
3 files changed, 69 insertions(+), 14 deletions(-)
diff --git a/src/main/include/log4cxx/net/xmlsocketappender.h b/src/main/include/log4cxx/net/xmlsocketappender.h
index ccd72887..61b79990 100644
--- a/src/main/include/log4cxx/net/xmlsocketappender.h
+++ b/src/main/include/log4cxx/net/xmlsocketappender.h
@@ -27,21 +27,32 @@ namespace net
{
/**
-Sends LoggingEvent objects in XML format
-to a remote a log server, usually a XMLSocketNode.
-
-<p>The XMLSocketAppender has the following properties:
-
-- If sent to a XMLSocketNode, remote logging
-is non-intrusive as far as the log event is concerned. In other
-words, the event will be logged with the same time stamp,
+Sends spi::LoggingEvent elements
+to a remote a log server, usually in XML format.
+
+A configuration that writes JSON to the TCP input plugin
+of a <a href="https://docs.fluentbit.io/manual/pipeline/inputs/tcp">fluent-bit</a>
+process running on the same system as the application:
+~~~{.xml}
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+<appender name="A1" class="XMLSocketAppender">
+ <param name="RemoteHost" value="localhost" />
+ <param name="Port" value="5170" />
+ <layout class="JSONLayout"/>
+</appender>
+<root>
+ <priority value ="INFO" />
+ <appender-ref ref="A1" />
+</root>
+</log4j:configuration>
+~~~
+
+<p>XMLSocketAppender has the following properties:
+
+- The event will be logged with the same time stamp,
NDC, location info as if it were logged locally by
the client.
-- XMLSocketAppenders use exclusively an XMLLayout. They ship an
-XML stream representing a LoggingEvent object
-to the server side.
-
- Remote logging uses the TCP protocol. Consequently, if
the server is reachable, then log events will eventually arrive
at the server.
@@ -76,7 +87,7 @@ destruction problem. Most other applications can safely
ignore it.
- If the application hosting the <code>XMLSocketAppender</code>
- exits before the <code>XMLSocketAppender</code> is closed either
+exits before the <code>XMLSocketAppender</code> is closed either
explicitly or subsequent to destruction, then there might
be untransmitted data in the pipe which might be lost.
@n @n To avoid lost data, it is usually sufficient to
@@ -99,7 +110,7 @@ class LOG4CXX_EXPORT XMLSocketAppender : public SocketAppenderSkeleton
static int DEFAULT_RECONNECTION_DELAY;
/**
- An event XML stream cannot exceed 1024 bytes.
+ Unused
*/
static const int MAX_EVENT_LEN;
diff --git a/src/test/cpp/net/xmlsocketappendertestcase.cpp b/src/test/cpp/net/xmlsocketappendertestcase.cpp
index 37ae2f1e..b6131155 100644
--- a/src/test/cpp/net/xmlsocketappendertestcase.cpp
+++ b/src/test/cpp/net/xmlsocketappendertestcase.cpp
@@ -16,6 +16,7 @@
*/
#include <log4cxx/net/xmlsocketappender.h>
+#include <log4cxx/xml/domconfigurator.h>
#include "../appenderskeletontestcase.h"
#include "apr.h"
@@ -34,6 +35,7 @@ class XMLSocketAppenderTestCase : public AppenderSkeletonTestCase
//
LOGUNIT_TEST(testDefaultThreshold);
LOGUNIT_TEST(testSetOptionThreshold);
+ //LOGUNIT_TEST(test_fluent_bit);
LOGUNIT_TEST_SUITE_END();
@@ -44,6 +46,18 @@ class XMLSocketAppenderTestCase : public AppenderSkeletonTestCase
{
return new log4cxx::net::XMLSocketAppender();
}
+
+ void test_fluent_bit()
+ {
+ xml::DOMConfigurator::configure("input/xml/fluent-bit.xml");
+ auto odbc = Logger::getRootLogger();
+ for (int i = 0; i < 100; ++i)
+ {
+ LOG4CXX_INFO(odbc, "Message '" << i << "'");
+ //apr_sleep(30000);
+ }
+ LOG4CXX_INFO(odbc, "Last message");
+ }
};
LOGUNIT_TEST_SUITE_REGISTRATION(XMLSocketAppenderTestCase);
diff --git a/src/test/resources/input/xml/fluent-bit.xml b/src/test/resources/input/xml/fluent-bit.xml
new file mode 100644
index 00000000..a1f2f592
--- /dev/null
+++ b/src/test/resources/input/xml/fluent-bit.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+<appender name="A1" class="XMLSocketAppender">
+ <param name="RemoteHost" value="localhost" />
+ <param name="Port" value="5170" />
+ <layout class="JSONLayout"/>
+</appender>
+<root>
+ <priority value ="INFO" />
+ <appender-ref ref="A1" />
+</root>
+</log4j:configuration>