Repository: logging-log4j2 Updated Branches: refs/heads/master 5f41d97ca -> a019ba878
[LOG4J2-946][docs] Using Log4j 2 in Web Applications: Update example (Log4jWebLifeCycle is not visible). Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/a019ba87 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a019ba87 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a019ba87 Branch: refs/heads/master Commit: a019ba878e1ae0d8a48423f26cec9f34e913c31e Parents: 5f41d97 Author: Gary Gregory <[email protected]> Authored: Thu Jan 29 11:21:53 2015 -0500 Committer: Gary Gregory <[email protected]> Committed: Thu Jan 29 11:21:53 2015 -0500 ---------------------------------------------------------------------- src/changes/changes.xml | 3 +++ src/site/xdoc/manual/webapp.xml | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a019ba87/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index afa67fa..0f10f2d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -77,6 +77,9 @@ <action issue="LOG4J2-891" dev="ggregory" type="fix"> AbstractLifecycle should not implement equals() and hashCode(). </action> + <action issue="LOG4J2-946" dev="ggregory" type="fix" due-to="artemonster"> + [docs] Using Log4j 2 in Web Applications: Update example (Log4jWebLifeCycle is not visible). + </action> <action issue="LOG4J2-901" dev="ggregory" type="update" due-to="Tihomir MeÅ¡ÄiÄ, Siegfried Greisinger"> Update docs for SyslogAppender: "No structured id name was supplied" </action> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a019ba87/src/site/xdoc/manual/webapp.xml ---------------------------------------------------------------------- diff --git a/src/site/xdoc/manual/webapp.xml b/src/site/xdoc/manual/webapp.xml index 1b86d45..57fea45 100644 --- a/src/site/xdoc/manual/webapp.xml +++ b/src/site/xdoc/manual/webapp.xml @@ -314,10 +314,11 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.web.WebLoggerContextUtils; public class TestAsyncServlet extends HttpServlet { + @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final AsyncContext asyncContext = req.startAsync(); - asyncContext.start(WebLoggerContextUtils.wrapExecutionContext(getServletContext(), new Runnable() { + asyncContext.start(WebLoggerContextUtils.wrapExecutionContext(this.getServletContext(), new Runnable() { @Override public void run() { final Logger logger = LogManager.getLogger(TestAsyncServlet.class); @@ -325,6 +326,21 @@ public class TestAsyncServlet extends HttpServlet { } })); } + + @Override + protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { + final AsyncContext asyncContext = req.startAsync(); + asyncContext.start(new Runnable() { + @Override + public void run() { + final Log4jWebSupport webSupport = + WebLoggerContextUtils.getWebLifeCycle(TestAsyncServlet.this.getServletContext()); + webSupport.setLoggerContext(); + // do stuff + webSupport.clearLoggerContext(); + } + }); + } } ]]></pre> <p>
