You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2018/01/11 16:02:14 UTC
logging-log4j2 git commit: [LOG4J2-2179] The MongoDB Appender should
use keys and values from a Log4j MapMessage. Fix compile. Doc it!
Repository: logging-log4j2
Updated Branches:
refs/heads/master 3378d7357 -> e78d205cc
[LOG4J2-2179]
The MongoDB Appender should use keys and values from a Log4j MapMessage.
Fix compile. Doc it!
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/e78d205c
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/e78d205c
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/e78d205c
Branch: refs/heads/master
Commit: e78d205ccc7869ef0d8a1dc84b7edd2f005eb84b
Parents: 3378d73
Author: Gary Gregory <gg...@apache.org>
Authored: Thu Jan 11 09:02:11 2018 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Thu Jan 11 09:02:11 2018 -0700
----------------------------------------------------------------------
src/site/xdoc/manual/appenders.xml | 199 ++++++++++++++++++--------------
src/site/xdoc/manual/messages.xml | 23 +++-
2 files changed, 131 insertions(+), 91 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e78d205c/src/site/xdoc/manual/appenders.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/appenders.xml b/src/site/xdoc/manual/appenders.xml
index bdfeddd..a9c27f5 100644
--- a/src/site/xdoc/manual/appenders.xml
+++ b/src/site/xdoc/manual/appenders.xml
@@ -1957,9 +1957,11 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
</subsection>
<a name="NoSQLAppender"/>
<subsection name="NoSQLAppender">
- <p>The NoSQLAppender writes log events to a NoSQL database using an internal lightweight provider interface.
+ <p>
+ The NoSQLAppender writes log events to a NoSQL database using an internal lightweight provider interface.
Provider implementations currently exist for MongoDB and Apache CouchDB, and writing a custom provider is
- quite simple.</p>
+ quite simple.
+ </p>
<table>
<caption align="top">NoSQLAppender Parameters</caption>
<tr>
@@ -2003,7 +2005,69 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
<code><CouchDb></code>. To create your own custom provider, read the JavaDoc for the
<code>NoSQLProvider</code>, <code>NoSQLConnection</code>, and <code>NoSQLObject</code> classes and the
documentation about creating Log4j plugins. We recommend you review the source code for the MongoDB and
- CouchDB providers as a guide for creating your own provider.</p>
+ CouchDB providers as a guide for creating your own provider.
+ </p>
+ <p>
+ The following example demonstrates how log events are persisted in NoSQL databases if represented in a JSON
+ format:
+ </p>
+ <pre class="prettyprint lang-javascript"><![CDATA[{
+ "level": "WARN",
+ "loggerName": "com.example.application.MyClass",
+ "message": "Something happened that you might want to know about.",
+ "source": {
+ "className": "com.example.application.MyClass",
+ "methodName": "exampleMethod",
+ "fileName": "MyClass.java",
+ "lineNumber": 81
+ },
+ "marker": {
+ "name": "SomeMarker",
+ "parent" {
+ "name": "SomeParentMarker"
+ }
+ },
+ "threadName": "Thread-1",
+ "millis": 1368844166761,
+ "date": "2013-05-18T02:29:26.761Z",
+ "thrown": {
+ "type": "java.sql.SQLException",
+ "message": "Could not insert record. Connection lost.",
+ "stackTrace": [
+ { "className": "org.example.sql.driver.PreparedStatement$1", "methodName": "responder", "fileName": "PreparedStatement.java", "lineNumber": 1049 },
+ { "className": "org.example.sql.driver.PreparedStatement", "methodName": "executeUpdate", "fileName": "PreparedStatement.java", "lineNumber": 738 },
+ { "className": "com.example.application.MyClass", "methodName": "exampleMethod", "fileName": "MyClass.java", "lineNumber": 81 },
+ { "className": "com.example.application.MainClass", "methodName": "main", "fileName": "MainClass.java", "lineNumber": 52 }
+ ],
+ "cause": {
+ "type": "java.io.IOException",
+ "message": "Connection lost.",
+ "stackTrace": [
+ { "className": "java.nio.channels.SocketChannel", "methodName": "write", "fileName": null, "lineNumber": -1 },
+ { "className": "org.example.sql.driver.PreparedStatement$1", "methodName": "responder", "fileName": "PreparedStatement.java", "lineNumber": 1032 },
+ { "className": "org.example.sql.driver.PreparedStatement", "methodName": "executeUpdate", "fileName": "PreparedStatement.java", "lineNumber": 738 },
+ { "className": "com.example.application.MyClass", "methodName": "exampleMethod", "fileName": "MyClass.java", "lineNumber": 81 },
+ { "className": "com.example.application.MainClass", "methodName": "main", "fileName": "MainClass.java", "lineNumber": 52 }
+ ]
+ }
+ },
+ "contextMap": {
+ "ID": "86c3a497-4e67-4eed-9d6a-2e5797324d7b",
+ "username": "JohnDoe"
+ },
+ "contextStack": [
+ "topItem",
+ "anotherItem",
+ "bottomItem"
+ ]
+}]]></pre>
+ </subsection>
+ <a name="NoSQLAppenderMongoDB"/>
+ <subsection name="NoSQLAppender for MongoDB">
+ <p>
+ The NoSQLAppender writes log events to a NoSQL database using an internal lightweight provider interface.
+ This section details specializations for MongoDB.
+ </p>
<table>
<caption align="top">MongoDB Provider Parameters</caption>
<tr>
@@ -2087,6 +2151,49 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
linked above for more information.</td>
</tr>
</table>
+ <p>
+ This appender is <a href="messages.html#MapMessage">MapMessage</a>-aware.
+ </p>
+ <p>
+ Here are a few sample configurations for the NoSQLAppender and MongoDB provider:
+ </p>
+
+ <pre class="prettyprint linenums lang-xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="error">
+ <Appenders>
+ <NoSql name="databaseAppender">
+ <MongoDb databaseName="applicationDb" collectionName="applicationLog" server="mongo.example.org"
+ username="loggingUser" password="abc123" />
+ </NoSql>
+ </Appenders>
+ <Loggers>
+ <Root level="warn">
+ <AppenderRef ref="databaseAppender"/>
+ </Root>
+ </Loggers>
+</Configuration>]]></pre>
+
+ <pre class="prettyprint linenums lang-xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="error">
+ <Appenders>
+ <NoSql name="databaseAppender">
+ <MongoDb collectionName="applicationLog" factoryClassName="org.example.db.ConnectionFactory"
+ factoryMethodName="getNewMongoClient" />
+ </NoSql>
+ </Appenders>
+ <Loggers>
+ <Root level="warn">
+ <AppenderRef ref="databaseAppender"/>
+ </Root>
+ </Loggers>
+</Configuration>]]></pre>
+ </subsection>
+ <a name="NoSQLAppenderApacheCouchDB"/>
+ <subsection name="NoSQLAppender for Apache CouchDB">
+ <p>
+ The NoSQLAppender writes log events to a NoSQL database using an internal lightweight provider interface.
+ This section details specializations for Apache CouchDB.
+ </p>
<table>
<caption align="top">CouchDB Provider Parameters</caption>
<tr>
@@ -2145,43 +2252,13 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
</tr>
</table>
<p>
- Here are a few sample configurations for the NoSQLAppender:
+ Here are a few sample configurations for the NoSQLAppender and CouchDB provider:
</p>
<pre class="prettyprint linenums lang-xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="error">
<Appenders>
<NoSql name="databaseAppender">
- <MongoDb databaseName="applicationDb" collectionName="applicationLog" server="mongo.example.org"
- username="loggingUser" password="abc123" />
- </NoSql>
- </Appenders>
- <Loggers>
- <Root level="warn">
- <AppenderRef ref="databaseAppender"/>
- </Root>
- </Loggers>
-</Configuration>]]></pre>
-
- <pre class="prettyprint linenums lang-xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
-<Configuration status="error">
- <Appenders>
- <NoSql name="databaseAppender">
- <MongoDb collectionName="applicationLog" factoryClassName="org.example.db.ConnectionFactory"
- factoryMethodName="getNewMongoClient" />
- </NoSql>
- </Appenders>
- <Loggers>
- <Root level="warn">
- <AppenderRef ref="databaseAppender"/>
- </Root>
- </Loggers>
-</Configuration>]]></pre>
-
- <pre class="prettyprint linenums lang-xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
-<Configuration status="error">
- <Appenders>
- <NoSql name="databaseAppender">
<CouchDb databaseName="applicationDb" protocol="https" server="couch.example.org"
username="loggingUser" password="abc123" />
</NoSql>
@@ -2192,60 +2269,6 @@ public class JpaLogEntity extends AbstractLogEventWrapperEntity {
</Root>
</Loggers>
</Configuration>]]></pre>
- <p>
- The following example demonstrates how log events are persisted in NoSQL databases if represented in a JSON
- format:
- </p>
- <pre class="prettyprint lang-javascript"><![CDATA[{
- "level": "WARN",
- "loggerName": "com.example.application.MyClass",
- "message": "Something happened that you might want to know about.",
- "source": {
- "className": "com.example.application.MyClass",
- "methodName": "exampleMethod",
- "fileName": "MyClass.java",
- "lineNumber": 81
- },
- "marker": {
- "name": "SomeMarker",
- "parent" {
- "name": "SomeParentMarker"
- }
- },
- "threadName": "Thread-1",
- "millis": 1368844166761,
- "date": "2013-05-18T02:29:26.761Z",
- "thrown": {
- "type": "java.sql.SQLException",
- "message": "Could not insert record. Connection lost.",
- "stackTrace": [
- { "className": "org.example.sql.driver.PreparedStatement$1", "methodName": "responder", "fileName": "PreparedStatement.java", "lineNumber": 1049 },
- { "className": "org.example.sql.driver.PreparedStatement", "methodName": "executeUpdate", "fileName": "PreparedStatement.java", "lineNumber": 738 },
- { "className": "com.example.application.MyClass", "methodName": "exampleMethod", "fileName": "MyClass.java", "lineNumber": 81 },
- { "className": "com.example.application.MainClass", "methodName": "main", "fileName": "MainClass.java", "lineNumber": 52 }
- ],
- "cause": {
- "type": "java.io.IOException",
- "message": "Connection lost.",
- "stackTrace": [
- { "className": "java.nio.channels.SocketChannel", "methodName": "write", "fileName": null, "lineNumber": -1 },
- { "className": "org.example.sql.driver.PreparedStatement$1", "methodName": "responder", "fileName": "PreparedStatement.java", "lineNumber": 1032 },
- { "className": "org.example.sql.driver.PreparedStatement", "methodName": "executeUpdate", "fileName": "PreparedStatement.java", "lineNumber": 738 },
- { "className": "com.example.application.MyClass", "methodName": "exampleMethod", "fileName": "MyClass.java", "lineNumber": 81 },
- { "className": "com.example.application.MainClass", "methodName": "main", "fileName": "MainClass.java", "lineNumber": 52 }
- ]
- }
- },
- "contextMap": {
- "ID": "86c3a497-4e67-4eed-9d6a-2e5797324d7b",
- "username": "JohnDoe"
- },
- "contextStack": [
- "topItem",
- "anotherItem",
- "bottomItem"
- ]
-}]]></pre>
</subsection>
<a name="OutputStreamAppender"/>
<subsection name="OutputStreamAppender">
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e78d205c/src/site/xdoc/manual/messages.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/messages.xml b/src/site/xdoc/manual/messages.xml
index 84a6622..fccd538 100644
--- a/src/site/xdoc/manual/messages.xml
+++ b/src/site/xdoc/manual/messages.xml
@@ -199,9 +199,26 @@ public class MyApp {
<h4>MapMessage</h4>
<a name="MapMessage"/>
<p>
- A MapMessage contains a Map of String keys and values. MapMessage implements FormattedMessage and accepts
- a format specifier of "XML", in which case the Map will be formatted as XML. Otherwise, the Map will be
- formatted as "key1=value1 key2=value2...".
+ A <code>MapMessage</code> contains a Map of String keys and values. <code>MapMessage</code> implements
+ <code>FormattedMessage</code> and accepts a format specifier of "XML", in which case the Map will be
+ formatted as XML. Otherwise, the Map will be formatted as <code>"key1=value1 key2=value2 ..."</code>.
+ </p>
+ <p>
+ Some Appenders make special use of <code>MapMessage</code> objects:
+ </p>
+ <ul>
+ <li>
+ When a <a href="appenders.html#JMSAppender">JMS Appender</a> is configured with a <code>MessageLayout</code>, it converts a Log4j
+ <code>MapMessage</code> to a JMS <code>javax.jms.MapMessage</code>.
+ </li>
+ <li>
+ When a <a href="appenders.html#NoSQLAppenderMongoDB">MongoDB Appender</a> is configured with a <code>MessageLayout</code>, it converts a Log4j
+ <code>MapMessage</code> to fields in a MongoDB object.
+ </li>
+ </ul>
+ <p>
+ When an Appender is <code>MessageLayout</code>-aware, the object Log4j sends to target is not a Log4j Log
+ Event but a custom object.
</p>
<h4>MessageFormatMessage</h4>
<a name="MessageFormatMessage"/>