You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2018/08/05 06:26:25 UTC

svn commit: r1033526 - /websites/production/logging/content/log4j/log4j-2.11.1/manual/usage.html

Author: rgoers
Date: Sun Aug  5 06:26:25 2018
New Revision: 1033526

Log:
Update based on feedback

Modified:
    websites/production/logging/content/log4j/log4j-2.11.1/manual/usage.html

Modified: websites/production/logging/content/log4j/log4j-2.11.1/manual/usage.html
==============================================================================
--- websites/production/logging/content/log4j/log4j-2.11.1/manual/usage.html (original)
+++ websites/production/logging/content/log4j/log4j-2.11.1/manual/usage.html Sun Aug  5 06:26:25 2018
@@ -15,11 +15,11 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 -->
-<!-- Generated by Apache Maven Doxia at 2018-08-03 -->
+<!-- Generated by Apache Maven Doxia at 2018-08-04 -->
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 	<head>
 		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-		<title>Log4j &#x2013; Log4j 2 Architecture - Apache Log4j 2</title>
+		<title>Log4j &#x2013; Log4j 2 Usage - Apache Log4j 2</title>
 		<link rel="stylesheet" href="../css/bootstrap.min.css" type="text/css" />
 		<link rel="stylesheet" href="../css/site.css" type="text/css" />
 		<script type="text/javascript" src="../js/jquery.min.js"></script>
@@ -27,7 +27,7 @@
 		<script type="text/javascript" src="../js/prettify.min.js"></script>
 		<script type="text/javascript" src="../js/site.js"></script>
 			<meta name="author" content="Ralph Goers" />
-		<meta name="Date-Revision-yyyymmdd" content="20180803" />
+		<meta name="Date-Revision-yyyymmdd" content="20180804" />
 		<meta http-equiv="Content-Language" content="en" />
 		
 				</head>
@@ -380,8 +380,8 @@
 
         
 <p>The base class creates a static Logger and a logger variable that is initialized as that same Logger.
-          It has a method that performs logging, but provides access to two Loggers, one that is static and one that
-          can be overridden.
+          It has a method that performs logging, but provides access to two Loggers, one that is static and one
+          that can be overridden.
         </p>
 
 
@@ -397,12 +397,12 @@
   /**
   *
   */
-  public abstract class MySuperClass {
+  public abstract class Parent {
 
-      // The name of this Logger will be &quot;org.apache.logging.MySuperClass&quot;
-      protected static final Logger LOGGER = LogManager.getLogger();
+      // The name of this Logger will be &quot;org.apache.logging.Parent&quot;
+      protected static final Logger parentLogger = LogManager.getLogger();
 
-      private Logger logger = LOGGER;
+      private Logger logger = parentLogger;
 
       protected Logger getLogger() {
           return logger;
@@ -413,16 +413,17 @@
       }
 
 
-      protected void demoLog(Marker marker) {
-          logger.debug(marker,&quot;MySuperClass log message&quot;);
+      public void log(Marker marker) {
+          logger.debug(marker,&quot;Parent log message&quot;);
       }
   }
 </pre></div>
 
         
 <p>
-          This class extends the base class. It provides its own logger and has two methods, one that uses the
-          the base class logger that can be overridden and one that uses the static logger from the base class.
+          This class extends the base class. It provides its own logger and has three methods, one that uses the
+          logger in this class,one that uses the static logger from the base class, and one that where the logger
+          may be set to either the parent or the child.
         </p>
 
 
@@ -437,17 +438,21 @@
   /**
   *
   */
-  public class MyClass extends MySuperClass {
+  public class Child extends Parent {
 
-      // The name of this Logge will be &quot;org.apache.logging.MyClass&quot;
-      public Logger logger = LogManager.getLogger();
+      // The name of this Logge will be &quot;org.apache.logging.Child&quot;
+      public Logger childLogger = LogManager.getLogger();
 
-      public void log1(Marker marker) {
-          logger.debug(marker,&quot;MyClass logger message&quot;);
+      public void childLog(Marker marker) {
+          childLogger.debug(marker,&quot;Child logger message&quot;);
       }
 
-      public void log2(Marker marker) {
-          LOGGER.debug(marker,&quot;MySuperClass logger message from MyClass&quot;);
+      public void logFromChild(Marker marker) {
+          getLogger().debug(marker,&quot;Log message from Child&quot;);
+      }
+
+      public void parentLog(Marker marker) {
+          parentLogger.debug(marker,&quot;Parent logger, message from Child&quot;);
       }
   }
 </pre></div>
@@ -471,25 +476,23 @@
 
       public static void main( String[] args ) {
           Marker marker = MarkerManager.getMarker(&quot;CLASS&quot;);
-          MyClass myclass = new MyClass();
+          Child child = new Child();
 
-          System.out.println(&quot;------- MySuperClass Logger ----------&quot;);
-          myclass.demoLog(null);
-          myclass.demoLog(marker);
-          myclass.log1(null);
-          myclass.log1(marker);
-          myclass.log2(null);
-          myclass.log2(marker);
-
-          myclass.setLogger(myclass.logger);
-
-          System.out.println(&quot;------- MySuperClass Logger set to MyClass Logger ----------&quot;);
-          myclass.demoLog(null);
-          myclass.demoLog(marker);
-          myclass.log1(null);
-          myclass.log1(marker);
-          myclass.log2(null);
-          myclass.log2(marker);
+          System.out.println(&quot;------- Parent Logger ----------&quot;);
+          child.log(null);
+          child.log(marker);
+          child.logFromChild(null);
+          child.logFromChild(marker);
+          child.parentLog(null);
+          child.parentLog(marker);
+
+          child.setLogger(child.childLogger);
+
+          System.out.println(&quot;------- Parent Logger set to Child Logger ----------&quot;);
+          child.log(null);
+          child.log(marker);
+          child.logFromChild(null);
+          child.logFromChild(marker);
       }
   }</pre></div>
 
@@ -506,8 +509,8 @@
   &lt;Appenders&gt;
     &lt;Console name=&quot;Console&quot; target=&quot;SYSTEM_OUT&quot;&gt;
       &lt;PatternLayout&gt;
-        &lt;MarkerPatternSelector defaultPattern=&quot;%sn. Logger name %c %msg%n&quot;&gt;
-          &lt;PatternMatch key=&quot;CLASS&quot; pattern=&quot;%sn. Class name %C %msg%n&quot;/&gt;
+        &lt;MarkerPatternSelector defaultPattern=&quot;%sn. %msg: Logger=%logger%n&quot;&gt;
+          &lt;PatternMatch key=&quot;CLASS&quot; pattern=&quot;%sn. %msg: Class=%class%n&quot;/&gt;
         &lt;/MarkerPatternSelector&gt;
       &lt;/PatternLayout&gt;
     &lt;/Console&gt;
@@ -528,63 +531,55 @@
           </p>
 <ol style="list-style-type: decimal">
             
-<li>Logging is performed in the base class using the static logger with the Logger name pattern. The
-            logger name matches the name of the base class.</li>
+<li>Logging is performed in the parent class using the static logger with the Logger name pattern. The
+            logger name matches the name of the parent class.</li>
             
-<li>Logging is performed in the base class using the static logger with the Class name pattern. Although
-              the method was called against the MyClass instance it is implemented in MySuperClass so that is what
+<li>Logging is performed in the parent class using the static logger with the Class name pattern. Although
+              the method was called against the Child instance it is implemented in Parent so that is what
               appears.</li>
             
-<li>Logging is performed in the subclass using the logger in the subclass, so the name of the
-              subclass is printed as the logger name.</li>
+<li>Logging is performed in Child using the logger in the parent, so the name of the
+              parent is printed as the logger name.</li>
             
-<li>Logging is performed in the subclass using the logger in the subclass, so the name of the subclass
-              is printed since that is where the method exists.</li>
+<li>Logging is performed in Child using the logger in the parent. Since the method calling the logging
+              method is in Child that is the class name that appears.</li>
             
-<li>Logging is performed in the subclass with the static logger of the base class. Thus the name
-              of the base class Logger is printed.</li>
+<li>Logging is performed in Child using the static logger in the parent, so the name of the
+              parent is printed as the logger name.</li>
             
-<li>Logging is performed in the subclass with the static logger of the base class. The name
-              of the subclass is printed since that is where the method performing the logging exists.</li>
+<li>Logging is performed in Child using the static logger in the parent. Since the method calling the logging
+              method is in Child that is the class name that appears.</li>
 
             
-<li>Logging is performed in the base class using the logger of the subclass. The
-              logger name matches the name of the subclass and so is printed.</li>
+<li>Logging is performed in the parent class using the logger of Child. The
+              logger name matches the name of the child and so it is printed.</li>
             
-<li>Logging is performed in the base class using the logger of the subclass. Although
-              the method was called against the MyClass instance it is implemented in MySuperClass so that is what
+<li>Logging is performed in the parent class using the logger of the Child. Although
+              the method was called against the Child instance it is implemented in PArent so that is what
               appears as the class name.</li>
             
-<li>Logging is performed in the subclass using the logger in the subclass, so the name of the
-              subclass is printed as the logger name.</li>
-            
-<li>Logging is performed in the subclass using the logger in the subclass, so the name of the subclass
-              is printed since that is where the method exists.</li>
-            
-<li>Logging is performed in the subclass with the logger of the base class. Thus the name
-              of the base class Logger is printed.</li>
+<li>Logging is performed in Child using the logger in the parent which is set to the child logger,
+              so the name of the child is printed as the logger name.</li>
             
-<li>Logging is performed in the subclass with the static logger of the base class, so the name
-              of the subclass is printed since that is where the method performing the logging exists.</li>
+<li>Logging is performed in Child using the logger in the parent, which is set to the child logger. Since
+              the method calling the logging method is in Child that is the class name that appears.</li>
           </ol>
         
 
 <div>
 <pre class="prettyprint">
-  ------- MySuperClass Logger ----------
-  1. Logger name org.apache.logging.MySuperClass MySuperClass log message
-  2. Class name org.apache.logging.MySuperClass MySuperClass log message
-  3. Logger name org.apache.logging.MyClass MyClass logger message
-  4. Class name org.apache.logging.MyClass MyClass logger message
-  5. Logger name org.apache.logging.MySuperClass MySuperClass logger message from MyClass
-  6. Class name org.apache.logging.MyClass MySuperClass logger message from MyClass
-  ------- MySuperClass Logger set to MyClass Logger ----------
-  7. Logger name org.apache.logging.MyClass MySuperClass log message
-  8. Class name org.apache.logging.MySuperClass MySuperClass log message
-  9. Logger name org.apache.logging.MyClass MyClass logger message
-  10. Class name org.apache.logging.MyClass MyClass logger message
-  11. Logger name org.apache.logging.MySuperClass MySuperClass logger message from MyClass
-  12. Class name org.apache.logging.MyClass MySuperClass logger message from MyClass
+  ------- Parent Logger ----------
+  1. Parent log message: Logger=org.apache.logging.Parent
+  2. Parent log message: Class=org.apache.logging.Parent
+  3. Log message from Child: Logger=org.apache.logging.Parent
+  4. Log message from Child: Class=org.apache.logging.Child
+  5. Parent logger, message from Child: Logger=org.apache.logging.Parent
+  6. Parent logger, message from Child: Class=org.apache.logging.Child
+  ------- Parent Logger set to Child Logger ----------
+  7. Parent log message: Logger=org.apache.logging.Child
+  8. Parent log message: Class=org.apache.logging.Parent
+  9. Log message from Child: Logger=org.apache.logging.Child
+  10. Log message from Child: Class=org.apache.logging.Child
 </pre></div>