From 31014e1022892bfcc92960feda70732fce4f9deb Mon Sep 17 00:00:00 2001
From: Stefan Iliev <46542846+StefanIliev545@users.noreply.github.com>
Date: Tue, 8 Oct 2019 10:18:19 +0100
Subject: [PATCH] CORDA-3246 - Missing logs on shutdown (#5501)

* Disabled shutdown hook on log4j2 as se are calling LogManager.shutdown manually and having multiple shutdowns breaks the logic and misses flushing out events.

* Added docs entry about shutdownHook needing to be disabled in case of a config override.

* Changes according to PR.

* More changes according to PR.

* Changed note according to PR review.
---
 config/dev/log4j2.xml               | 2 +-
 docs/source/node-administration.rst | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/config/dev/log4j2.xml b/config/dev/log4j2.xml
index 4c968cad1f..fe67301f84 100644
--- a/config/dev/log4j2.xml
+++ b/config/dev/log4j2.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<Configuration status="info" packages="net.corda.common.logging">
+<Configuration status="info" packages="net.corda.common.logging" shutdownHook="disable">
 
     <Properties>
         <Property name="log-path">${sys:log-path:-logs}</Property>
diff --git a/docs/source/node-administration.rst b/docs/source/node-administration.rst
index dd0a722858..bb44e666df 100644
--- a/docs/source/node-administration.rst
+++ b/docs/source/node-administration.rst
@@ -25,6 +25,11 @@ If you need to switch to synchronous logging (e.g. for debugging/testing purpose
 by adding ``-DLog4jContextSelector=org.apache.logging.log4j.core.selector.ClassLoaderContextSelector`` to the node's
 command line or to the ``jvmArgs`` section of the node configuration (see :doc:`corda-configuration-file`).
 
+.. warning:: Ensure that ``shutdownHook="disable"`` is set if you are overriding the log4j2 configuration file
+   otherwise logs will not be flushed properly on shutdown and loss may occur. The option is set in the ``Configuration``
+   tag of the log4j configuration file, for example ``<Configuration ... shutdownHook="disable">``. This is because
+   Corda overrides the default log4j2 shutdown logic in order to make sure it gets shut down correctly.
+
 Example
 +++++++