ceki 2003/12/15 13:49:02
Added: examples/src/factor factor.lcf NumberCruncher.java
NumberCruncherServer.java factor.html
NumberCruncherClient.java
examples/src/subclass MyLogger.java MyLoggerFactory.java
mycat.good MyLoggerTest.java mycat.bad
examples/src/jmx T.java
examples/src/objectBased Base.java ChildTwo.java Test.java
ChildOne.java
examples/src/trivial Trivial.java
examples/src/pattern MyPatternLayout.java
CountingPatternConverter.java
examples/src/customLevel XLevel.java
examples/src package.html
Removed: examples/sort sort2.properties sort4.properties
sort1.properties Sort.java sort3.properties
SortAlgo.java
examples/objectBased ChildTwo.java Base.java Test.java
ChildOne.java
examples/subclass MyLogger.java mycat.good mycat.bad
MyLoggerFactory.java MyLoggerTest.java
examples/customLevel XLevel.java
examples/trivial Trivial.java
examples/factor NumberCruncher.java
NumberCruncherClient.java NumberCruncherServer.java
factor.html factor.lcf
examples/pattern CountingPatternConverter.java
MyPatternLayout.java
examples package.html
examples/jmx T.java
Log:
Moved examples/ files to examples/src
Revision Changes Path
1.1 jakarta-log4j/examples/src/factor/factor.lcf
Index: factor.lcf
===================================================================
# For the general syntax of property based configuration files see the
# documenation of org.apache.log4j.PropertyConfigurator.
# The root category uses the appender called A1. Since no priority is
# specified, the root category assumes the default priority for root
# which is DEBUG in log4j. The root category is the only category that
# has a default priority. All other categories need not be assigned a
# priority in which case they inherit their priority from the
# hierarchy.
log4j.rootCategory=, A1
# A1 is set to be a FileAppender which outputs to the file
# "factor.log". Start the server NumberCruncherServer and two
# NumberCruncherClients, and ask to factor two numbers
# near-simultaneously. Notice that the log output from these two
# requests are logged in the file factor.log. Nevertheless, the logs
# of these requests can still be distinguished given their distinct
# nested diagnostic contexts.
log4j.appender.A1=org.apache.log4j.FileAppender
log4j.appender.A1.File=factor.log
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
# Note the %x conversion specifier for NDC printing.
log4j.appender.A1.layout.ConversionPattern=%-4r %-5p [%t] (%x) - %m\n
1.1 jakarta-log4j/examples/src/factor/NumberCruncher.java
Index: NumberCruncher.java
===================================================================
package factor;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
NumberCruncher's factor positive integers. See <a
href=doc-files/NumberCruncher.java>source</a> code for more details.
@author Ceki Gülcü
*/
public interface NumberCruncher extends Remote {
/**
Factor a positive integer <code>number</code> and return its
<em>distinct</em> factor's as an integer array.
*/
int[] factor(int number) throws RemoteException;
}
1.1 jakarta-log4j/examples/src/factor/NumberCruncherServer.java
Index: NumberCruncherServer.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software
* License version 1.1, a copy of which has been included with this
* distribution in the LICENSE.APL file. */
package factor;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
import java.rmi.Naming;
import java.util.Vector;
import org.apache.log4j.Category;
import org.apache.log4j.NDC;
import org.apache.log4j.PropertyConfigurator;
/**
A simple [EMAIL PROTECTED] NumberCruncher} implementation that logs its
progress when factoring numbers. The purpose of the whole exercise
is to show the use of nested diagnostic contexts in order to
distinguish the log output from different client requests.
<pre>
<b>Usage:</b> java org.apache.log4j.examples.NumberCruncherServer
<em>configFile</em>
where <em>configFile</em> is a log4j
configuration file.
</pre>
We supply a simple config file <a href=doc-files/factor.lcf>factor.lcf</a>
for directing log output to the file <code>factor.log</code>.
<p>Try it yourself by starting a <code>NumberCruncherServer</code>
and make queries from multiple [EMAIL PROTECTED] NumberCruncherClient
NumberCruncherClients} to factor numbers.
<p><b><a href="doc-files/factor.html">Sample output</a></b> shows the log
output when two clients connect to the server near simultaneously.
<p>See <a href=doc-files/NumberCruncherServer.java>source</a> code
of <code>NumberCruncherServer</code> for more details.
<p>Note that class files for the example code is not included in
any of the distributed log4j jar files. You will have to add the
directory <code>/dir-where-you-unpacked-log4j/classes</code> to
your classpath before trying out the examples.
*/
public class NumberCruncherServer extends UnicastRemoteObject
implements NumberCruncher {
static Category cat = Category.getInstance(
NumberCruncherServer.class.getName());
public
NumberCruncherServer() throws RemoteException {
}
public
int[] factor(int number) throws RemoteException {
// The client's host is an important source of information.
try {
NDC.push(this.getClientHost());
}
catch(java.rmi.server.ServerNotActiveException e) {
// we are being called from same VM
NDC.push("localhost");
}
// The information contained within the request is another source of
// distinctive information. It might reveal the users name, date of request,
// request ID etc. In servlet type environments, much information is
// contained in cookies.
NDC.push(String.valueOf(number));
cat.info("Beginning to factor.");
if(number <= 0) {
throw new IllegalArgumentException(number+" is not a positive integer.");
}
else if(number == 1)
return new int[] {1};
Vector factors = new Vector();
int n = number;
for(int i = 2; (i <= n) && (i*i <= number); i++) {
// It is bad practice to place log requests within tight loops.
// It is done here to show interleaved log output from
// different requests.
cat.debug("Trying to see if " + i + " is a factor.");
if((n % i) == 0) {
cat.info("Found factor "+i);
factors.addElement(new Integer(i));
do {
n /= i;
} while((n % i) == 0);
}
// Placing artificial delays in tight-loops will also lead to sub-optimal
// resuts. :-)
delay(100);
}
if(n != 1) {
cat.info("Found factor "+n);
factors.addElement(new Integer(n));
}
int len = factors.size();
int[] result = new int[len];
for(int i = 0; i < len; i++) {
result[i] = ((Integer) factors.elementAt(i)).intValue();
}
// Before leaving a thread we call NDC.remove. This deletes the reference
// to the thread in the internal hash table. Version 0.8.5 introduces a
// a lazy removal mechanism in case you forget to call remove when
// exiting a thread. See the java documentation in NDC.remove for further
// details.
NDC.remove();
return result;
}
static
void usage(String msg) {
System.err.println(msg);
System.err.println(
"Usage: java org.apache.log4j.examples.NumberCruncherServer configFile\n" +
" where configFile is a log4j configuration file.");
System.exit(1);
}
public static
void delay(int millis) {
try{Thread.sleep(millis);}
catch(InterruptedException e) {}
}
public static void main(String[] args) {
if(args.length != 1)
usage("Wrong number of arguments.");
NumberCruncherServer ncs;
PropertyConfigurator.configure(args[0]);
try {
ncs = new NumberCruncherServer();
Naming.rebind("Factor", ncs);
cat.info("NumberCruncherServer bound and ready to serve.");
}
catch(Exception e) {
cat.error("Could not bind NumberCruncherServer.", e);
return;
}
NumberCruncherClient.loop(ncs);
}
}
1.1 jakarta-log4j/examples/src/factor/factor.html
Index: factor.html
===================================================================
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title></title>
</head>
<body bgcolor=white>
<center><h2>Log4j output of two near-simultaneous requests</h2></center>
<p>Here is the logged output when two clients ask to factor two
integers near-simultanesouly. The client on the host 128.178.50.84
asks to factor the prime number 359. The client on the host 9.4.2.196
asks to factor the number 347 (also a prime).
<p>The NDC is placed between parantheses in bold. The NDC information
consists of the client's host and the number to factor. Since the two
requests have distinct NDCs, their output can be easily separated.
<pre>
0 INFO [main] <b>()</b> - NumberCruncherServer bound and ready to serve.
276493 INFO [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Beginning to factor.
276495 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Trying to see if 2 is a factor.
276699 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Trying to see if 3 is a factor.
276908 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Trying to see if 4 is a factor.
276983 INFO [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Beginning to
factor.
276984 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to
see if 2 is a factor.
277115 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Trying to see if 5 is a factor.
277188 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to
see if 3 is a factor.
277318 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Trying to see if 6 is a factor.
277398 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to
see if 4 is a factor.
277520 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Trying to see if 7 is a factor.
277605 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347) </b>- Trying to
see if 5 is a factor.
277728 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Trying to see if 8 is a factor.
277808 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to
see if 6 is a factor.
277931 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Trying to see if 9 is a factor.
278019 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to
see if 7 is a factor.
278138 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Trying to see if 10 is a factor.
278228 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to
see if 8 is a factor.
278348 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Trying to see if 11 is a factor.
278438 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to
see if 9 is a factor.
278559 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Trying to see if 12 is a factor.
278648 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to
see if 10 is a factor.
278768 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Trying to see if 13 is a factor.
278858 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to
see if 11 is a factor.
278970 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Trying to see if 14 is a factor.
279068 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to
see if 12 is a factor.
279178 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Trying to see if 15 is a factor.
279270 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to
see if 13 is a factor.
279387 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Trying to see if 16 is a factor.
279478 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to
see if 14 is a factor.
279598 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Trying to see if 17 is a factor.
279688 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to
see if 15 is a factor.
279808 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Trying to see if 18 is a factor.
279898 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to
see if 16 is a factor.
280018 INFO [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> -
Found factor 359
280108 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to
see if 17 is a factor.
280318 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to
see if 18 is a factor.
280520 INFO [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Found factor
347
</pre>
<hr>
<address></address>
<!-- hhmts start -->
Last modified: Fri May 5 10:36:05 MDT 2000
<!-- hhmts end -->
</body> </html>
1.1 jakarta-log4j/examples/src/factor/NumberCruncherClient.java
Index: NumberCruncherClient.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software
* License version 1.1, a copy of which has been included with this
* distribution in the LICENSE.APL file. */
package factor;
import java.rmi.RemoteException;
import java.rmi.Naming;
import java.io.*;
/**
NumberCruncherClient is a simple client for factoring integers. A
remote NumberCruncher is contacted and asked to factor an
integer. The factors returned by the [EMAIL PROTECTED] NumberCruncherServer}
are displayed on the screen.
<p>See <a href=doc-files/NumberCruncherClient.java>source</a> code of
<code>NumberCruncherClient</code> for more details.
<pre>
<b>Usage:</b> java org.apache.log4j.examples.NumberCruncherClient HOST
where HOST is the machine where the NumberCruncherServer
is running
</pre>
<p>Note that class files for the example code is not included in
any of the distributed log4j jar files. You will have to add the
directory <code>/dir-where-you-unpacked-log4j/classes</code> to
your classpath before trying out the examples.
@author Ceki Gülcü
*/
public class NumberCruncherClient {
public static void main(String[] args) {
if(args.length == 1) {
try {
String url = "rmi://"+args[0]+ "/Factor";
NumberCruncher nc = (NumberCruncher) Naming.lookup(url);
loop(nc);
}
catch(Exception e) {
e.printStackTrace();
}
}
else
usage("Wrong number of arguments.");
}
static
void usage(String msg) {
System.err.println(msg);
System.err.println(
"Usage: java org.apache.log4j.examples.NumberCruncherClient HOST\n" +
" where HOST is the machine where the NumberCruncherServer is running.");
System.exit(1);
}
static
void loop(NumberCruncher nc) {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int i = 0;
while (true) {
System.out.print("Enter a number to factor, '-1' to quit: ");
try {
i = Integer.parseInt(in.readLine());
}
catch(Exception e) {
e.printStackTrace();
}
if(i == -1) {
System.out.print("Exiting loop.");
return;
}
else {
try {
System.out.println("Will attempt to factor "+i);
int[] factors = nc.factor(i);
System.out.print("The factors of "+i+" are");
for(int k=0; k < factors.length; k++) {
System.out.print(" " + factors[k]);
}
System.out.println(".");
}
catch(RemoteException e) {
System.err.println("Could not factor "+i);
e.printStackTrace();
}
}
}
}
}
1.1 jakarta-log4j/examples/src/subclass/MyLogger.java
Index: MyLogger.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software
* License version 1.1, a copy of which has been included with this
* distribution in the LICENSE.txt file. */
package subclass;
import org.apache.log4j.*;
import customLevel.XLevel;
/**
A simple example showing logger subclassing.
<p>See <b><a href="doc-files/MyLogger.java">source code</a></b>
for more details.
<p>See [EMAIL PROTECTED] MyLoggerTest} for a usage example.
*/
public class MyLogger extends Logger {
// It's usually a good idea to add a dot suffix to the fully
// qualified class name. This makes caller localization to work
// properly even from classes that have almost the same fully
// qualified class name as MyLogger, e.g. MyLoggerTest.
static String FQCN = MyLogger.class.getName() + ".";
// It's enough to instantiate a factory once and for all.
private static MyLoggerFactory myFactory = new MyLoggerFactory();
/**
Just calls the parent constuctor.
*/
public MyLogger(String name) {
super(name);
}
/**
Overrides the standard debug method by appending " world" at the
end of each message. */
public
void debug(Object message) {
super.log(FQCN, Level.DEBUG, message + " world.", null);
}
/**
This method overrides [EMAIL PROTECTED] Logger#getInstance} by supplying
its own factory type as a parameter.
*/
public
static
Category getInstance(String name) {
return Logger.getLogger(name, myFactory);
}
/**
This method overrides [EMAIL PROTECTED] Logger#getLogger} by supplying
its own factory type as a parameter.
*/
public
static
Logger getLogger(String name) {
return Logger.getLogger(name, myFactory);
}
public
void trace(Object message) {
super.log(FQCN, XLevel.TRACE, message, null);
}
}
1.1 jakarta-log4j/examples/src/subclass/MyLoggerFactory.java
Index: MyLoggerFactory.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software
* License version 1.1, a copy of which has been included with this
* distribution in the LICENSE.txt file. */
package subclass;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggerFactory;
/**
A factory that makes new [EMAIL PROTECTED] MyLogger} objects.
See <b><a href="doc-files/MyLoggerFactory.java">source
code</a></b> for more details.
@author Ceki Gülcü */
public class MyLoggerFactory implements LoggerFactory {
/**
The constructor should be public as it will be called by
configurators in different packages. */
public
MyLoggerFactory() {
}
public
Logger makeNewLoggerInstance(String name) {
return new MyLogger(name);
}
}
1.1 jakarta-log4j/examples/src/subclass/mycat.good
Index: mycat.good
===================================================================
# Setting the logger factory to MyLoggerFactory solves the
# ClassCastException problem encountered with the "mycat.bad"
# configuration file.
log4j.loggerFactory=examples.subclass.MyLoggerFactory
# The usual stuff. Note that A1 is configured in root not in "some.cat"
log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%5p [%t] %c - %m%n
# Set the priority of "some.cat" to TRACE (defined in
# examples.customLevel.XLevel). Since we specified MyLoggerFactory as
# the logger factory, the following line willl also have the side
# effect of instanciating a MyLogger object having the name
# "some.cat".
log4j.logger.some.cat=TRACE#examples.customLevel.XLevel
1.1 jakarta-log4j/examples/src/subclass/MyLoggerTest.java
Index: MyLoggerTest.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software
* License version 1.1, a copy of which has been included with this
* distribution in the LICENSE.txt file. */
package subclass;
import org.apache.log4j.*;
import org.apache.log4j.xml.DOMConfigurator;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.helpers.LogLog;
/**
A simple example showing logger subclassing.
<p>The example should make it clear that subclasses follow the
hierarchy. You should also try running this example with a <a
href="doc-files/mycat.bad">bad</a> and <a
href="doc-files/mycat.good">good</a> configuration file samples.
<p>See <b><a
href="doc-files/MyLogger.java">source code</a></b> for more details.
*/
public class MyLoggerTest {
/**
When called wihtout arguments, this program will just print
<pre>
DEBUG [main] some.cat - Hello world.
</pre>
and exit.
<b>However, it can be called with a configuration file in XML or
properties format.
*/
static public void main(String[] args) {
if(args.length == 0) {
// Note that the appender is added to root but that the log
// request is made to an instance of MyLogger. The output still
// goes to System.out.
Logger root = Logger.getRootLogger();
Layout layout = new PatternLayout("%p [%t] %c (%F:%L) - %m%n");
root.addAppender(new ConsoleAppender(layout, ConsoleAppender.SYSTEM_OUT));
}
else if(args.length == 1) {
if(args[0].endsWith("xml")) {
DOMConfigurator.configure(args[0]);
} else {
PropertyConfigurator.configure(args[0]);
}
} else {
usage("Incorrect number of parameters.");
}
try {
MyLogger c = (MyLogger) MyLogger.getInstance("some.cat");
c.trace("Hello");
c.debug("Hello");
} catch(ClassCastException e) {
LogLog.error("Did you forget to set the factory in the config file?", e);
}
}
static
void usage(String errMsg) {
System.err.println(errMsg);
System.err.println("\nUsage: "+MyLogger.class.getName() + "[configFile]\n"
+ " where *configFile* is an optional configuration file, "+
"either in properties or XML format.");
System.exit(1);
}
}
1.1 jakarta-log4j/examples/src/subclass/mycat.bad
Index: mycat.bad
===================================================================
# The usual stuff. Note that A1 is configured in root not in "some.cat"
log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%5p [%t] %c - %m%n
# Set the priority of "some.cat" to TRACE (defined in
# examples.customLevel.XLevel). This will actually have the side
# effect of instanciating a logger object having the name "some.cat"
# this will cause a ClassCastException if the logger object is cast
# as a MyLogger object.
log4j.logger.some.cat=TRACE#examples.customLevel.XLevel
1.1 jakarta-log4j/examples/src/jmx/T.java
Index: T.java
===================================================================
package jmx;
import org.apache.log4j.jmx.Agent;
import org.apache.log4j.Category;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.*;
public class T {
public static void main(String[] args) {
Category cat = Category.getInstance(T.class);
Layout layout = new PatternLayout("%r %p [%t] %c - %m%n");
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
consoleAppender.setName("console");
BasicConfigurator.configure(consoleAppender);
Agent agent = new Agent();
agent.start();
}
}
1.1 jakarta-log4j/examples/src/objectBased/Base.java
Index: Base.java
===================================================================
/*
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "log4j" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/
package objectBased;
import org.apache.log4j.Logger;
/**
*
* An almost trivially simple Base class.
*
* It uses the [EMAIL PROTECTED] #getLogger} method to retreive the logger to use.
This
* method can be overrriden by derived clases to acheive "object" based logging.
*
* @author Scott Melcher
* @author Gülcü
*/
public class Base {
static Logger logger = Logger.getLogger(Base.class);
public void myMethod() {
getLogger().debug("logging message");
}
public Logger getLogger() {
System.out.println("Base.getLogger called");
return Base.logger;
}
}
1.1 jakarta-log4j/examples/src/objectBased/ChildTwo.java
Index: ChildTwo.java
===================================================================
/*
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "log4j" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/
package objectBased;
import org.apache.log4j.Logger;
public class ChildTwo extends Base {
static Logger logger = Logger.getLogger(ChildTwo.class);
public void execute() {
myMethod();
}
public Logger getLogger() {
System.out.println("ChildTwo.getLogger called");
return ChildTwo.logger;
}
}
1.1 jakarta-log4j/examples/src/objectBased/Test.java
Index: Test.java
===================================================================
/*
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "log4j" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/
package objectBased;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
public class Test {
public static void main(String[] args) {
BasicConfigurator.configure();
Logger logger_c2 = Logger.getLogger(ChildTwo.class);
logger_c2.setLevel(Level.INFO);
ChildOne c1 = new ChildOne();
c1.execute();
ChildTwo c2 = new ChildTwo();
c2.execute();
}
}
1.1 jakarta-log4j/examples/src/objectBased/ChildOne.java
Index: ChildOne.java
===================================================================
/*
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "log4j" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/
package objectBased;
import org.apache.log4j.Logger;
public class ChildOne extends Base {
static Logger logger = Logger.getLogger(ChildOne.class);
public void execute() {
myMethod();
}
public Logger getLogger() {
System.out.println("ChildOne.getLogger called");
return ChildOne.logger;
}
}
1.1 jakarta-log4j/examples/src/trivial/Trivial.java
Index: Trivial.java
===================================================================
/*
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "log4j" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/
package trivial;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Category;
import org.apache.log4j.NDC;
/**
View the <a href="doc-files/Trivial.java">source code</a> of this a
trivial usage example. Running <code>java examples.Trivial</code>
should output something similar to:
<pre>
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.
</pre>
<p> 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.
<p>See [EMAIL PROTECTED] Sort} and [EMAIL PROTECTED] SortAlgo} for sligtly more
elaborate
examples.
<p>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 <code>/dir-where-you-unpacked-log4j/classes</code> 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.");
}
}
}
1.1 jakarta-log4j/examples/src/pattern/MyPatternLayout.java
Index: MyPatternLayout.java
===================================================================
/*
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "log4j" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/
package pattern;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.Logger;
import org.apache.log4j.Layout;
/**
*
* Example showing how to extend PatternLayout to recognize additional
* conversion words without adding.
*
* <p>In this case MyPatternLayout recognizes %counter conversion word.
* It outputs the value of an internal counter which is also incremented at
* each call.
*
* @see org.apache.log4j.PatternLayout
* @author Anders Kristensen
* @author Ceki Gülcü
*/
public class MyPatternLayout extends PatternLayout {
public MyPatternLayout() {
super();
}
public MyPatternLayout(String pattern) {
super(pattern);
}
/**
Activates the conversion pattern. Do not forget to call this method after
you change the parameters of the PatternLayout instance.
*/
public void activateOptions() {
this.addConversionRule("counter", CountingPatternConverter.class.getName());
super.activateOptions();
}
public static void main(String[] args) {
Layout layout = new MyPatternLayout("[counter=%.10#] - %m%n");
Logger logger = Logger.getLogger("some.cat");
logger.addAppender(new ConsoleAppender(layout, ConsoleAppender.SYSTEM_OUT));
logger.debug("Hello, log");
logger.info("Hello again...");
}
}
1.1 jakarta-log4j/examples/src/pattern/CountingPatternConverter.java
Index: CountingPatternConverter.java
===================================================================
/*
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "log4j" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/
package pattern;
import org.apache.log4j.pattern.PatternConverter;
import org.apache.log4j.spi.LoggingEvent;
public class CountingPatternConverter extends PatternConverter {
StringBuffer buf;
int counter = 0;
public CountingPatternConverter() {
super();
this.buf = new StringBuffer(5);
}
public StringBuffer convert(LoggingEvent event) {
if(buf.capacity() > 64) {
buf = new StringBuffer(5);
} else {
buf.setLength(0);
}
return buf.append(String.valueOf(++counter));
}
}
1.1 jakarta-log4j/examples/src/customLevel/XLevel.java
Index: XLevel.java
===================================================================
/*
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "log4j" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/
package customLevel;
import org.apache.log4j.Level;
/**
This class introduces a new level level called TRACE. TRACE has
lower level than DEBUG.
*/
public class XLevel extends Level {
public static final int TRACE_INT = Level.DEBUG_INT - 1;
public static final int LETHAL_INT = Level.FATAL_INT + 1;
private static String TRACE_STR = "TRACE";
private static String LETHAL_STR = "LETHAL";
public static final XLevel TRACE = new XLevel(TRACE_INT, TRACE_STR, 7);
public static final XLevel LETHAL = new XLevel(LETHAL_INT, LETHAL_STR, 0);
protected XLevel(int level, String strLevel, int syslogEquiv) {
super(level, strLevel, syslogEquiv);
}
/**
Convert the string passed as argument to a level. If the
conversion fails, then this method returns [EMAIL PROTECTED] #TRACE}.
*/
public static Level toLevel(String sArg) {
return (Level) toLevel(sArg, XLevel.TRACE);
}
public static Level toLevel(String sArg, Level defaultValue) {
if (sArg == null) {
return defaultValue;
}
String stringVal = sArg.toUpperCase();
if (stringVal.equals(TRACE_STR)) {
return XLevel.TRACE;
} else if (stringVal.equals(LETHAL_STR)) {
return XLevel.LETHAL;
}
return Level.toLevel(sArg, (Level) defaultValue);
}
public static Level toLevel(int i) throws IllegalArgumentException {
switch (i) {
case TRACE_INT:
return XLevel.TRACE;
case LETHAL_INT:
return XLevel.LETHAL;
}
return Level.toLevel(i);
}
}
1.1 jakarta-log4j/examples/src/package.html
Index: package.html
===================================================================
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title></title>
</head>
<body>
<p>Example usage of log4j including source code.
<p>Note that class files for the example code is not included in any
of the distributed log4j jar files. You will have to add the directory
<code>/dir-where-you-unpacked-log4j/classes</code> to your classpath
before trying out the examples.
<p>This package's shows how log4j can be used to output log
statements.
<ul>
<p><li>See source code of <a
href="doc-files/Trivial.java">Trivial.java</a> for a trivial usage
example.
<p><li>See source code of <a href="doc-files/Sort.java">Sort.java</a> and
<a href="doc-files/SortAlgo.java">SortAlgo.java</a> to for a slightly
more advanced example.
<p><li>See [EMAIL PROTECTED] org.apache.log4j.examples.NumberCruncherServer} for a
[EMAIL PROTECTED]
org.apache.log4j.NDC} based technique to distinguish the log output from
requests from multiple clients.
</ul>
<hr>
<address></address>
<!-- hhmts start -->
Last modified: Fri May 5 10:20:04 MDT 2000
<!-- hhmts end -->
</body> </html>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]