alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code


package examples;


import org.apache.log4j.Category;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.NDC;

/**
   View the source code of this a
   trivial usage example. Running java examples.Trivial
   should output something similar to:

   
      0    INFO  [main] examples.Trivial (Client #45890) - Awake awake. Put on thy strength.
      15   DEBUG [main] examples.Trivial (Client #45890 DB) - Now king David was old.
      278  INFO  [main] examples.Trivial$InnerTrivial (Client #45890) - Entered foo.
      293  INFO  [main] examples.Trivial (Client #45890) - Exiting Trivial.   
   

The increasing numbers at the beginning of each line are the times elapsed since the start of the program. The string between the parentheses is the nested diagnostic context.

See {@link Sort} and {@link SortAlgo} for sligtly more elaborate examples.

Note thent class files for the example code is not included in any of the distributed log4j jar files. You will have to add the directory /dir-where-you-unpacked-log4j/classes to your classpath before trying out the examples. */ public class Trivial { static Category cat = Category.getInstance(Trivial.class.getName()); public static void main(String[] args) { BasicConfigurator.configure(); NDC.push("Client #45890"); cat.info("Awake awake. Put on thy strength."); Trivial.foo(); InnerTrivial.foo(); cat.info("Exiting Trivial."); } static void foo() { NDC.push("DB"); cat.debug("Now king David was old."); NDC.pop(); } static class InnerTrivial { static Category cat = Category.getInstance(InnerTrivial.class.getName()); static void foo() { cat.info("Entered foo."); } } }

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.