apache-log4j1.2-1.2.17.orig/ 0000755 0001750 0001750 00000000000 12126647423 013773 5 ustar tony tony apache-log4j1.2-1.2.17.orig/build.xml 0000644 0001750 0001750 00000077671 11751454714 015640 0 ustar tony tony
Example usage of log4j including source code.
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
/dir-where-you-unpacked-log4j/classes
to your classpath
before trying out the examples.
This package's shows how log4j can be used to output log statements.
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).
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.
0 INFO [main] () - NumberCruncherServer bound and ready to serve. 276493 INFO [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Beginning to factor. 276495 DEBUG [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Trying to see if 2 is a factor. 276699 DEBUG [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Trying to see if 3 is a factor. 276908 DEBUG [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Trying to see if 4 is a factor. 276983 INFO [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Beginning to factor. 276984 DEBUG [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Trying to see if 2 is a factor. 277115 DEBUG [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Trying to see if 5 is a factor. 277188 DEBUG [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Trying to see if 3 is a factor. 277318 DEBUG [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Trying to see if 6 is a factor. 277398 DEBUG [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Trying to see if 4 is a factor. 277520 DEBUG [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Trying to see if 7 is a factor. 277605 DEBUG [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Trying to see if 5 is a factor. 277728 DEBUG [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Trying to see if 8 is a factor. 277808 DEBUG [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Trying to see if 6 is a factor. 277931 DEBUG [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Trying to see if 9 is a factor. 278019 DEBUG [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Trying to see if 7 is a factor. 278138 DEBUG [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Trying to see if 10 is a factor. 278228 DEBUG [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Trying to see if 8 is a factor. 278348 DEBUG [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Trying to see if 11 is a factor. 278438 DEBUG [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Trying to see if 9 is a factor. 278559 DEBUG [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Trying to see if 12 is a factor. 278648 DEBUG [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Trying to see if 10 is a factor. 278768 DEBUG [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Trying to see if 13 is a factor. 278858 DEBUG [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Trying to see if 11 is a factor. 278970 DEBUG [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Trying to see if 14 is a factor. 279068 DEBUG [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Trying to see if 12 is a factor. 279178 DEBUG [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Trying to see if 15 is a factor. 279270 DEBUG [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Trying to see if 13 is a factor. 279387 DEBUG [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Trying to see if 16 is a factor. 279478 DEBUG [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Trying to see if 14 is a factor. 279598 DEBUG [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Trying to see if 17 is a factor. 279688 DEBUG [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Trying to see if 15 is a factor. 279808 DEBUG [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Trying to see if 18 is a factor. 279898 DEBUG [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Trying to see if 16 is a factor. 280018 INFO [RMI TCP Connection(7)-128.178.50.84] (128.178.50.84 359) - Found factor 359 280108 DEBUG [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Trying to see if 17 is a factor. 280318 DEBUG [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Trying to see if 18 is a factor. 280520 INFO [RMI TCP Connection(8)-9.4.2.196] (9.4.2.196 347) - Found factor 347
SortAlgo uses the bubble sort algorithm to sort an integer array. See also its source code. @author Ceki Gülcü */ public class SortAlgo { final static String className = SortAlgo.class.getName(); final static Logger LOG = Logger.getLogger(className); final static Logger OUTER = Logger.getLogger(className + ".OUTER"); final static Logger INNER = Logger.getLogger(className + ".INNER"); final static Logger DUMP = Logger.getLogger(className + ".DUMP"); final static Logger SWAP = Logger.getLogger(className + ".SWAP"); int[] intArray; SortAlgo(int[] intArray) { this.intArray = intArray; } void bubbleSort() { LOG.info( "Entered the sort method."); for(int i = intArray.length -1; i >= 0 ; i--) { NDC.push("i=" + i); OUTER.debug("in outer loop."); for(int j = 0; j < i; j++) { NDC.push("j=" + j); // It is poor practice to ship code with log staments in tight loops. // We do it anyway in this example. INNER.debug( "in inner loop."); if(intArray[j] > intArray[j+1]) swap(j, j+1); NDC.pop(); } NDC.pop(); } } void dump() { if(! (this.intArray instanceof int[])) { DUMP.error("Tried to dump an uninitialized array."); return; } DUMP.info("Dump of integer array:"); for(int i = 0; i < this.intArray.length; i++) { DUMP.info("Element [" + i + "]=" + this.intArray[i]); } } void swap(int l, int r) { // It is poor practice to ship code with log staments in tight // loops or code called potentially millions of times. SWAP.debug( "Swapping intArray["+l+"]=" + intArray[l] + " and intArray["+r+"]=" + intArray[r]); int temp = this.intArray[l]; this.intArray[l] = this.intArray[r]; this.intArray[r] = temp; } } apache-log4j1.2-1.2.17.orig/examples/sort4.properties 0000644 0001750 0001750 00000003662 11751454714 021013 0 ustar tony tony # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Attach appender A1 to root. Set root level to Level.DEBUG. log4j.rootLogger=DEBUG, A1 # A1 is set to be a FileAppender sending its output to # System.out. However, only error messages and above will be printed # in A1 because A1's threshold is set to Level.ERROR. # The fact that the root level is set to Prority.DEBUG only influences # log requests made to the root logger. It has no influence on the # *appenders* attached to root. log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.Threshold=ERROR log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%p [%t] %c{2} (%M:%L) - %m%n # Set the level of the logger named "org.apache.log4j.examples" to # Level.INFO, attach appender A2. log4j.logger.org.apache.log4j.examples=INFO, A2 # Appender A2 writes to the file "test" in user's home. log4j.appender.A2=org.apache.log4j.FileAppender log4j.appender.A2.File=${user.home}/test # Truncate 'test' if it aleady exists. log4j.appender.A2.Append=false # Appender A2 uses the PatternLayout. log4j.appender.A2.layout=org.apache.log4j.PatternLayout log4j.appender.A2.layout.ConversionPattern=%5r %-5p [%t] %c{2} - %m%n apache-log4j1.2-1.2.17.orig/examples/Sort.java 0000644 0001750 0001750 00000006237 11751454714 017415 0 ustar tony tony /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package examples; import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.Logger; /** Example code for log4j to viewed in conjunction with the {@link examples.SortAlgo SortAlgo} class.
This program expects a configuration file name as its first argument, and the size of the array to sort as the second and last argument. See its source code for more details.
Play around with different values in the configuration file and watch the changing behavior.
Example configuration files can be found in sort1.properties, sort2.properties, sort3.properties and sort4.properties are supplied with the package.
If you are also interested in logging performance, then have look at the {@link org.apache.log4j.performance.Logging} class. @author Ceki Gülcü */ public class Sort { static Logger logger = Logger.getLogger(Sort.class.getName()); public static void main(String[] args) { if(args.length != 2) { usage("Incorrect number of parameters."); } int arraySize = -1; try { arraySize = Integer.valueOf(args[1]).intValue(); if(arraySize <= 0) usage("Negative array size."); } catch(java.lang.NumberFormatException e) { usage("Could not number format ["+args[1]+"]."); } PropertyConfigurator.configure(args[0]); int[] intArray = new int[arraySize]; logger.info("Populating an array of " + arraySize + " elements in" + " reverse order."); for(int i = arraySize -1 ; i >= 0; i--) { intArray[i] = arraySize - i - 1; } SortAlgo sa1 = new SortAlgo(intArray); sa1.bubbleSort(); sa1.dump(); // We intentionally initilize sa2 with null. SortAlgo sa2 = new SortAlgo(null); logger.info("The next log statement should be an error message."); sa2.dump(); logger.info("Exiting main method."); } static void usage(String errMsg) { System.err.println(errMsg); System.err.println("\nUsage: java org.apache.examples.Sort " + "configFile ARRAY_SIZE\n"+ "where configFile is a configuration file\n"+ " ARRAY_SIZE is a positive integer.\n"); System.exit(1); } } apache-log4j1.2-1.2.17.orig/examples/MyPatternLayout.java 0000644 0001750 0001750 00000003761 11751454714 021606 0 ustar tony tony /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package examples; import org.apache.log4j.*; import org.apache.log4j.helpers.PatternParser; /** Example showing how to extend PatternLayout to recognize additional conversion characters.
In this case MyPatternLayout recognizes %# conversion pattern. It outputs the value of an internal counter which is also incremented at each call.
See source code
for more details.
@see MyPatternParser
@see org.apache.log4j.PatternLayout
@author Anders Kristensen
*/
public class MyPatternLayout extends PatternLayout {
public
MyPatternLayout() {
this(DEFAULT_CONVERSION_PATTERN);
}
public
MyPatternLayout(String pattern) {
super(pattern);
}
public
PatternParser createPatternParser(String pattern) {
return new MyPatternParser(
pattern == null ? DEFAULT_CONVERSION_PATTERN : pattern);
}
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...");
}
}
apache-log4j1.2-1.2.17.orig/examples/sort1.properties 0000644 0001750 0001750 00000003465 11751454714 021011 0 ustar tony tony # Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# An example log4j configuration file that outputs to System.out. The
# output information consists of relative time, log level, thread
# name, logger name, nested diagnostic context and the message in that
# order.
# For the general syntax of property based configuration files see the
# documenation of org.apache.log4j.PropertyConfigurator.
log4j.rootLogger=DEBUG, A1
# A1 is set to be a ConsoleAppender which outputs to System.out.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
# The conversion pattern uses format specifiers. You might want to
# change the pattern an watch the output format change.
log4j.appender.A1.layout.ConversionPattern=%-4r %-5p [%t] %37c %3x - %m%n
# In this example, we are not really interested in INNER loop or SWAP
# messages. See the effects of uncommenting and changing the levels of
# the following loggers.
# log4j.logger.org.apache.log4j.examples.SortAlgo.INNER=WARN
# log4j.logger.org.apache.log4j.examples.SortAlgo.SWAP=WARN
apache-log4j1.2-1.2.17.orig/examples/mycat.bad 0000644 0001750 0001750 00000002561 11751454714 017404 0 ustar tony tony # Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 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
apache-log4j1.2-1.2.17.orig/examples/Trivial.java 0000644 0001750 0001750 00000005124 11751454714 020072 0 ustar tony tony /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package examples;
import org.apache.log4j.Logger;
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 Logger logger = Logger.getLogger(Trivial.class);
public static void main(String[] args) {
BasicConfigurator.configure();
NDC.push("Client #45890");
logger.info("Awake awake. Put on thy strength.");
Trivial.foo();
InnerTrivial.foo();
logger.info("Exiting Trivial.");
}
static
void foo() {
NDC.push("DB");
logger.debug("Now king David was old.");
NDC.pop();
}
static class InnerTrivial {
static Logger logger = Logger.getLogger(InnerTrivial.class);
static
void foo() {
logger.info("Entered foo.");
}
}
}
apache-log4j1.2-1.2.17.orig/examples/NumberCruncherServer.java 0000644 0001750 0001750 00000013073 11751454714 022573 0 ustar tony tony /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package examples;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
import java.rmi.Naming;
import java.util.Vector;
import org.apache.log4j.Logger;
import org.apache.log4j.NDC;
import org.apache.log4j.PropertyConfigurator;
/**
A simple {@link 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.
Usage: java org.apache.log4j.examples.NumberCruncherServer configFile where configFile is a log4j configuration file.We supply a simple config file factor.lcf for directing log output to the file
factor.log
.
Try it yourself by starting a NumberCruncherServer
and make queries from multiple {@link NumberCruncherClient
NumberCruncherClients} to factor numbers.
Sample output shows the log output when two clients connect to the server near simultaneously.
See source code
of NumberCruncherServer
for more details.
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 /dir-where-you-unpacked-log4j/classes
to
your classpath before trying out the examples.
*/
public class NumberCruncherServer extends UnicastRemoteObject
implements NumberCruncher {
private static final long serialVersionUID = 2626753561969426769L;
static Logger logger = Logger.getLogger(NumberCruncherServer.class);
public
NumberCruncherServer() throws RemoteException {
}
public
int[] factor(int number) throws RemoteException {
// The client's host is an important source of information.
try {
NDC.push(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));
logger.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.
logger.debug("Trying to see if " + i + " is a factor.");
if((n % i) == 0) {
logger.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) {
logger.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);
logger.info("NumberCruncherServer bound and ready to serve.");
}
catch(Exception e) {
logger.error("Could not bind NumberCruncherServer.", e);
return;
}
NumberCruncherClient.loop(ncs);
}
}
apache-log4j1.2-1.2.17.orig/examples/subclass/ 0000755 0001750 0001750 00000000000 12126647422 017427 5 ustar tony tony apache-log4j1.2-1.2.17.orig/examples/subclass/MyLoggerTest.java 0000644 0001750 0001750 00000005530 11751454714 022665 0 ustar tony tony /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package examples.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.
The example should make it clear that subclasses follow the hierarchy. You should also try running this example with a bad and good configuration file samples.
See source code for more details. */ public class MyLoggerTest { /** When called wihtout arguments, this program will just print
DEBUG [main] some.cat - Hello world.and exit. 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.getLogger("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); } } apache-log4j1.2-1.2.17.orig/examples/subclass/MyLogger.java 0000644 0001750 0001750 00000004256 11751454714 022031 0 ustar tony tony /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package examples.subclass; import org.apache.log4j.*; import examples.customLevel.XLevel; /** A simple example showing logger subclassing.
See source code for more details.
See {@link 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 {@link 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); } } apache-log4j1.2-1.2.17.orig/examples/subclass/MyLoggerFactory.java 0000644 0001750 0001750 00000002564 11751454714 023361 0 ustar tony tony /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package examples.subclass; import org.apache.log4j.Logger; import org.apache.log4j.spi.LoggerFactory; /** A factory that makes new {@link MyLogger} objects. See source code 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); } } apache-log4j1.2-1.2.17.orig/examples/customLevel/ 0000755 0001750 0001750 00000000000 12126647422 020112 5 ustar tony tony apache-log4j1.2-1.2.17.orig/examples/customLevel/XLevel.java 0000644 0001750 0001750 00000004602 11751454714 022161 0 ustar tony tony /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package examples.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 { private static final long serialVersionUID = 2626753561969426769L; static public final int TRACE_INT = Level.DEBUG_INT - 1; static public 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 {@link #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); } } apache-log4j1.2-1.2.17.orig/examples/lf5/ 0000755 0001750 0001750 00000000000 12126647422 016276 5 ustar tony tony apache-log4j1.2-1.2.17.orig/examples/lf5/InitUsingMultipleAppenders/ 0000755 0001750 0001750 00000000000 12126647422 023565 5 ustar tony tony apache-log4j1.2-1.2.17.orig/examples/lf5/InitUsingMultipleAppenders/example.properties 0000644 0001750 0001750 00000004204 11751454714 027341 0 ustar tony tony # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # For the general syntax of property based configuration files see the # documenation of org.apache.log4j.PropertyConfigurator. # The root category uses two appenders called A1 and R. 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, R # A1 is set to be a LF5Appender which outputs to a swing # logging console. log4j.appender.A1=org.apache.log4j.lf5.LF5Appender # R is the RollingFileAppender that outputs to a rolling log # file called rolling_log_file.log. log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=rolling_log_file.log # Define a pattern layout for the file. # For more information on conversion characters (i.e. d,p,t,c,l,m,n) # please see the PatternLayout class of the Log4j API. log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=[slf5s.start]%d{DATE}[slf5s.DATE]%n%p[slf5s.PRIORITY]%n%x[slf5s.NDC]%n%t[slf5s.THREAD]%n%c[slf5s.CATEGORY]%n%l[slf5s.LOCATION]%n%m[slf5s.MESSAGE]%n%n # Set the max size of the file and the number of backup files log4j.appender.R.MaxFileSize=100KB log4j.appender.R.MaxBackupIndex=1 apache-log4j1.2-1.2.17.orig/examples/lf5/InitUsingMultipleAppenders/InitUsingMultipleAppenders.java 0000644 0001750 0001750 00000013723 11751454714 031730 0 ustar tony tony /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package examples.lf5.InitUsingMultipleAppenders; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import java.io.IOException; import java.net.URL; /** * This example shows how to use LogFactor5 with other Log4J appenders * (In this case the RollingFileAppender). * * The following lines can be added to the log4j.properties file or a * standard Java properties file. * * # Two appenders are registered with the root of the Category tree. * * log4j.rootCategory=, A1, R * * # A1 is set to be a LF5Appender which outputs to a swing * # logging console. * * log4j.appender.A1=org.apache.log4j.lf5.LF5Appender * * # R is the RollingFileAppender that outputs to a rolling log * # file called rolling_log_file.log. * * log4j.appender.R=org.apache.log4j.RollingFileAppender * log4j.appender.R.File=rolling_log_file.log * * log4j.appender.R.layout=org.apache.log4j.PatternLayout * log4j.appender.R.layout.ConversionPattern=Date - %d{DATE}%nPriority * - %p%nThread - %t%nCategory - %c%nLocation - %l%nMessage - %m%n%n * log4j.appender.R.MaxFileSize=100KB * log4j.appender.R.MaxBackupIndex=1 * * To make this example work, either run the InitUsingMultipleAppenders.bat * file located in the examples folder or run it at the command line. If you * are running the example at the command line, you must ensure that the * example.properties file is in your classpath. * * @author Brent Sprecher * @author Brad Marlborough */ // Contributed by ThoughtWorks Inc. public class InitUsingMultipleAppenders { //-------------------------------------------------------------------------- // Constants: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Protected Variables: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Private Variables: //-------------------------------------------------------------------------- private static Logger logger = Logger.getLogger(InitUsingMultipleAppenders.class); //-------------------------------------------------------------------------- // Constructors: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Public Methods: //-------------------------------------------------------------------------- public static void main(String argv[]) { // Use a PropertyConfigurator to initialize from a property file. String resource = "/examples/lf5/InitUsingMultipleAppenders/example.properties"; URL configFileResource = InitUsingMultipleAppenders.class.getResource(resource); PropertyConfigurator.configure(configFileResource); // Add a bunch of logging statements ... logger.debug("Hello, my name is Homer Simpson."); logger.debug("Hello, my name is Lisa Simpson."); logger.debug("Hello, my name is Marge Simpson."); logger.debug("Hello, my name is Bart Simpson."); logger.debug("Hello, my name is Maggie Simpson."); logger.info("We are the Simpsons!"); logger.info("Mmmmmm .... Chocolate."); logger.info("Homer likes chocolate"); logger.info("Doh!"); logger.info("We are the Simpsons!"); logger.warn("Bart: I am through with working! Working is for chumps!" + "Homer: Son, I'm proud of you. I was twice your age before " + "I figured that out."); logger.warn("Mmm...forbidden donut."); logger.warn("D'oh! A deer! A female deer!"); logger.warn("Truly, yours is a butt that won't quit." + "- Bart, writing as Woodrow to Ms. Krabappel."); logger.error("Dear Baby, Welcome to Dumpsville. Population: you."); logger.error("Dear Baby, Welcome to Dumpsville. Population: you.", new IOException("Dumpsville, USA")); logger.error("Mr. Hutz, are you aware you're not wearing pants?"); logger.error("Mr. Hutz, are you aware you're not wearing pants?", new IllegalStateException("Error !!")); logger.fatal("Eep."); logger.fatal("Mmm...forbidden donut.", new SecurityException("Fatal Exception")); logger.fatal("D'oh! A deer! A female deer!"); logger.fatal("Mmmmmm .... Chocolate.", new SecurityException("Fatal Exception")); } //-------------------------------------------------------------------------- // Protected Methods: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Private Methods: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Nested Top-Level Classes or Interfaces: //-------------------------------------------------------------------------- } apache-log4j1.2-1.2.17.orig/examples/lf5/InitUsingDefaultConfigurator/ 0000755 0001750 0001750 00000000000 12126647422 024077 5 ustar tony tony ././@LongLink 0000000 0000000 0000000 00000000150 00000000000 011561 L ustar root root apache-log4j1.2-1.2.17.orig/examples/lf5/InitUsingDefaultConfigurator/InitUsingDefaultConfigurator.java apache-log4j1.2-1.2.17.orig/examples/lf5/InitUsingDefaultConfigurator/InitUsingDefaultConfigurator.j0000644 0001750 0001750 00000011640 11751454714 032060 0 ustar tony tony /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package examples.lf5.InitUsingDefaultConfigurator; import org.apache.log4j.Logger; import org.apache.log4j.NDC; import org.apache.log4j.lf5.DefaultLF5Configurator; import java.io.IOException; /** * This class is a simple example of how to configure the LogFactor5 * logging window using the DefaultLF5Configurator. * * The DefaultLF5Configurator uses a default configuration file stored * in the log4j.jar in order to provide a default configuration for * the LF5Appender. * * @author Brent Sprecher */ // Contributed by ThoughtWorks Inc. public class InitUsingDefaultConfigurator { //-------------------------------------------------------------------------- // Constants: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Protected Variables: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Private Variables: //-------------------------------------------------------------------------- private static Logger logger = Logger.getLogger(InitUsingDefaultConfigurator.class); //-------------------------------------------------------------------------- // Constructors: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Public Methods: //-------------------------------------------------------------------------- public static void main(String[] args) throws IOException { // Configure the LF5Appender using the DefaultLF5Configurator. This // will add the LF5Appender to the root of the Category tree. DefaultLF5Configurator.configure(); // Add an NDC to demonstrate how NDC information is output. NDC.push("#23856"); // Log some information. for (int i = 0; i < 10; i++) { logger.debug("Hello, my name is Homer Simpson."); logger.info("Mmmmmm .... Chocolate."); logger.warn("Mmm...forbidden donut."); } // Clean up NDC NDC.pop(); NDC.remove(); NDC.push("Another NDC"); // Log some information. logger.fatal("Hello, my name is Bart Simpson."); logger.error("Hi diddly ho good neighbour."); // Clean up NDC NDC.pop(); NDC.remove(); // Call methods on both classes. InitUsingDefaultConfigurator.foo(); InnerInitUsingDefaultConfigurator.foo(); logger.info("Exiting InitUsingDefaultConfigurator."); } public static void foo() { logger.debug("Entered foo in InitUsingDefaultConfigurator class"); NDC.push("#123456"); logger.debug("Hello, my name is Marge Simpson."); logger.info("D'oh!! A deer! A female deer."); // Clean up NDC NDC.pop(); NDC.remove(); } //-------------------------------------------------------------------------- // Protected Methods: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Private Methods: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Nested Top-Level Classes or Interfaces: //-------------------------------------------------------------------------- public static class InnerInitUsingDefaultConfigurator { static Logger logger = Logger.getLogger(InnerInitUsingDefaultConfigurator.class.getName()); static void foo() throws IOException { // Configure the LF5Appender again. You can call // DefaultLF5Configurator.configure() as often as you want // without unexpected behavior. DefaultLF5Configurator.configure(); logger.info("Entered foo in InnerInitUsingDefaultConfigurator class."); } } } apache-log4j1.2-1.2.17.orig/examples/lf5/InitUsingLog4JProperties/ 0000755 0001750 0001750 00000000000 12126647422 023124 5 ustar tony tony apache-log4j1.2-1.2.17.orig/examples/lf5/InitUsingLog4JProperties/log4j.properties 0000644 0001750 0001750 00000002673 11751454714 026274 0 ustar tony tony # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # 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 LF5Appender which outputs to a swing # logging console. log4j.appender.A1=org.apache.log4j.lf5.LF5Appender log4j.appender.A1.MaxNumberOfRecords=1000 apache-log4j1.2-1.2.17.orig/examples/lf5/InitUsingLog4JProperties/InitUsingLog4JProperties.java 0000644 0001750 0001750 00000012142 11751454714 030620 0 ustar tony tony /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package examples.lf5.InitUsingLog4JProperties; import org.apache.log4j.Logger; import java.io.IOException; /** * This class is a simple example of how to use the LogFactor5 logging * window. * * The LF5Appender is the primary class that enables logging to the * LogFactor5 logging window. The simplest method of using this Appender * is to add the following line to your log4j.properties file: * * log4j.appender.A1=org.apache.log4j.lf5.LF5Appender * * The log4j.properties file MUST be in you system classpath. If this file * is in your system classpath, a static initializer in the Category class * will load the file during class initialization. The LF5Appender will be * added to the root category of the Category tree. * * Create a log4j.properties file and add this line to it, or add this line * to your existing log4j.properties file. Run the example at the command line * and explore the results! * * @author Brent Sprecher */ // Contributed by ThoughtWorks Inc. public class InitUsingLog4JProperties { //-------------------------------------------------------------------------- // Constants: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Protected Variables: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Private Variables: //-------------------------------------------------------------------------- private static Logger logger = Logger.getLogger(InitUsingLog4JProperties.class); //-------------------------------------------------------------------------- // Constructors: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Public Methods: //-------------------------------------------------------------------------- public static void main(String argv[]) { // Add a bunch of logging statements ... logger.debug("Hello, my name is Homer Simpson."); logger.debug("Hello, my name is Lisa Simpson."); logger.debug("Hello, my name is Marge Simpson."); logger.debug("Hello, my name is Bart Simpson."); logger.debug("Hello, my name is Maggie Simpson."); logger.info("We are the Simpsons!"); logger.info("Mmmmmm .... Chocolate."); logger.info("Homer likes chocolate"); logger.info("Doh!"); logger.info("We are the Simpsons!"); logger.warn("Bart: I am through with working! Working is for chumps!" + "Homer: Son, I'm proud of you. I was twice your age before " + "I figured that out."); logger.warn("Mmm...forbidden donut."); logger.warn("D'oh! A deer! A female deer!"); logger.warn("Truly, yours is a butt that won't quit." + "- Bart, writing as Woodrow to Ms. Krabappel."); logger.error("Dear Baby, Welcome to Dumpsville. Population: you."); logger.error("Dear Baby, Welcome to Dumpsville. Population: you.", new IOException("Dumpsville, USA")); logger.error("Mr. Hutz, are you aware you're not wearing pants?"); logger.error("Mr. Hutz, are you aware you're not wearing pants?", new IllegalStateException("Error !!")); logger.fatal("Eep."); logger.fatal("Mmm...forbidden donut.", new SecurityException("Fatal Exception")); logger.fatal("D'oh! A deer! A female deer!"); logger.fatal("Mmmmmm .... Chocolate.", new SecurityException("Fatal Exception")); } //-------------------------------------------------------------------------- // Protected Methods: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Private Methods: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Nested Top-Level Classes or Interfaces: //-------------------------------------------------------------------------- } apache-log4j1.2-1.2.17.orig/examples/lf5/UsingSocketAppenders/ 0000755 0001750 0001750 00000000000 12126647422 022376 5 ustar tony tony apache-log4j1.2-1.2.17.orig/examples/lf5/UsingSocketAppenders/socketclient.properties 0000644 0001750 0001750 00000002726 11751454714 027215 0 ustar tony tony # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # 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 LF5Appender which outputs to a swing # logging console. log4j.appender.A1=org.apache.log4j.net.SocketAppender log4j.appender.A1.RemoteHost=localhost log4j.appender.A1.Port=8887 apache-log4j1.2-1.2.17.orig/examples/lf5/UsingSocketAppenders/UsingSocketAppenders.java 0000644 0001750 0001750 00000013515 11751454714 027351 0 ustar tony tony /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package examples.lf5.UsingSocketAppenders; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import java.io.IOException; import java.net.URL; /** * This is another simple example of how to use the LogFactor5 * logging console. * * The LF5Appender is the primary class that enables logging to the * LogFactor5 logging window. If the following line is added to a properties * file, the LF5Appender will be appended to the root category when * the properties file is loaded: * * log4j.appender.A1=org.apache.log4j.lf5.LF5Appender * * To make this example work, you must ensure that the example.properties file * is in your classpath.You can then run the example at the command line. * * @author Brent Sprecher */ // Contributed by ThoughtWorks Inc. public class UsingSocketAppenders { //-------------------------------------------------------------------------- // Constants: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Protected Variables: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Private Variables: //-------------------------------------------------------------------------- private static Logger logger1 = Logger.getLogger(UsingSocketAppenders.class); private static Logger logger2 = Logger.getLogger("TestClass.Subclass"); private static Logger logger3 = Logger.getLogger("TestClass.Subclass.Subclass"); //-------------------------------------------------------------------------- // Constructors: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Public Methods: //-------------------------------------------------------------------------- public static void main(String argv[]) { // Use a PropertyConfigurator to initialize from a property file. String resource = "/examples/lf5/UsingSocketAppenders/socketclient.properties"; URL configFileResource = UsingSocketAppenders.class.getResource(resource); PropertyConfigurator.configure(configFileResource); // Add a bunch of logging statements ... logger1.debug("Hello, my name is Homer Simpson."); logger1.debug("Hello, my name is Lisa Simpson."); logger2.debug("Hello, my name is Marge Simpson."); logger2.debug("Hello, my name is Bart Simpson."); logger3.debug("Hello, my name is Maggie Simpson."); logger2.info("We are the Simpsons!"); logger2.info("Mmmmmm .... Chocolate."); logger3.info("Homer likes chocolate"); logger3.info("Doh!"); logger3.info("We are the Simpsons!"); logger1.warn("Bart: I am through with working! Working is for chumps!" + "Homer: Son, I'm proud of you. I was twice your age before " + "I figured that out."); logger1.warn("Mmm...forbidden donut."); logger1.warn("D'oh! A deer! A female deer!"); logger1.warn("Truly, yours is a butt that won't quit." + "- Bart, writing as Woodrow to Ms. Krabappel."); logger2.error("Dear Baby, Welcome to Dumpsville. Population: you."); logger2.error("Dear Baby, Welcome to Dumpsville. Population: you.", new IOException("Dumpsville, USA")); logger3.error("Mr. Hutz, are you aware you're not wearing pants?"); logger3.error("Mr. Hutz, are you aware you're not wearing pants?", new IllegalStateException("Error !!")); logger3.fatal("Eep."); logger3.fatal("Mmm...forbidden donut.", new SecurityException("Fatal Exception ... ")); logger3.fatal("D'oh! A deer! A female deer!"); logger2.fatal("Mmmmmm .... Chocolate.", new SecurityException("Fatal Exception")); // Put the main thread is put to sleep for 5 seconds to allow the // SocketServer to process all incoming messages before the Socket is // closed. This is done to overcome some basic limitations with the // way the SocketServer and SocketAppender classes manage sockets. try { Thread.sleep(5000); } catch (InterruptedException ie) { } } //-------------------------------------------------------------------------- // Protected Methods: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Private Methods: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Nested Top-Level Classes or Interfaces: //-------------------------------------------------------------------------- } apache-log4j1.2-1.2.17.orig/examples/lf5/UsingSocketAppenders/socketserver.properties 0000644 0001750 0001750 00000003013 11751454714 027233 0 ustar tony tony # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # 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=DEBUG, A1 log4j.rootCategory=, A1 # A1 is set to be a LF5Appender which outputs to a swing # logging console. #log4j.category.org.apache.log4j.net.SocketNode=DEBUG log4j.appender.A1=org.apache.log4j.lf5.LF5Appender log4j.appender.A1.MaxNumberOfRecords=700 apache-log4j1.2-1.2.17.orig/examples/lf5/UsingLogMonitorAdapter/ 0000755 0001750 0001750 00000000000 12126647422 022676 5 ustar tony tony apache-log4j1.2-1.2.17.orig/examples/lf5/UsingLogMonitorAdapter/CustomizedLogLevels.java 0000644 0001750 0001750 00000011106 11751454714 027506 0 ustar tony tony /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package examples.lf5.UsingLogMonitorAdapter; import org.apache.log4j.lf5.LogLevel; import org.apache.log4j.lf5.util.LogMonitorAdapter; /** * This class is a simple example of how use the LogMonitorAdapter to * bypass the Log4JAppender and post LogRecords directly to the LogMonitor * using customized LogLevels * * To make this example work, ensure that the lf5.jar and lf5-license.jar * files are in your classpath, and then run the example at the command line. * * @author Richard Hurst */ // Contributed by ThoughtWorks Inc. public class CustomizedLogLevels { //-------------------------------------------------------------------------- // Constants: //-------------------------------------------------------------------------- public final static LogLevel LEVEL_ONE = new LogLevel("LEVEL 1", 1); public final static LogLevel LEVEL_TWO = new LogLevel("LEVEL 2", 2); public final static LogLevel LEVEL_THREE = new LogLevel("LEVEL 3", 3); public final static LogLevel LEVEL_FOUR = new LogLevel("LEVEL 4", 4); public final static LogLevel DEFAULT = new LogLevel("DEFAULT", 0); //-------------------------------------------------------------------------- // Protected Variables: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Private Variables: //-------------------------------------------------------------------------- private static LogMonitorAdapter _adapter; static { // The first LogLevel in the Array will be used as the default LogLevel. _adapter = LogMonitorAdapter.newInstance(new LogLevel[]{DEFAULT, LEVEL_ONE, LEVEL_TWO, LEVEL_THREE, LEVEL_FOUR, LogLevel.FATAL}); // if a different log level is to be used it can be specified as such // _adapter.setDefaultLevel(LEVEL_THREE); } //-------------------------------------------------------------------------- // Constructors: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Public Methods: //-------------------------------------------------------------------------- public static void main(String[] args) { CustomizedLogLevels test = new CustomizedLogLevels(); test.doMyBidding(); } public void doMyBidding() { // tell the LogMonitorAdapter which LogLevel is the severe Level if necessary _adapter.setSevereLevel(LEVEL_ONE); String levels = this.getClass().getName(); // will used the default Level _adapter.log(levels, "Using the customized LogLevels"); _adapter.log(levels, LEVEL_FOUR, "This is a test"); _adapter.log(levels, LEVEL_THREE, "Hmmm fobidden doughnut"); _adapter.log(levels, LEVEL_ONE, "Danger Danger Will Robinson", new RuntimeException("DANGER"), "32"); _adapter.log(levels, LEVEL_TWO, "Exit stage right->"); _adapter.log(levels, LEVEL_FOUR, "What's up Doc?", new NullPointerException("Unfortunate exception")); } //-------------------------------------------------------------------------- // Protected Methods: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Private Methods: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Nested Top-Level Classes or Interfaces: //-------------------------------------------------------------------------- } apache-log4j1.2-1.2.17.orig/examples/lf5/UsingLogMonitorAdapter/UsingLogMonitorAdapter.java 0000644 0001750 0001750 00000007123 11751454714 030147 0 ustar tony tony /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package examples.lf5.UsingLogMonitorAdapter; import org.apache.log4j.lf5.LogLevel; import org.apache.log4j.lf5.util.LogMonitorAdapter; /** * This class is a simple example of how use the LogMonitorAdapter to * bypass the Log4JAppender and post LogRecords directly to the LogMonitor * * To make this example work, ensure that the lf5.jar and lf5-license.jar * files are in your classpath, and then run the example at the command line. * * @author Richard Hurst */ // Contributed by ThoughtWorks Inc. public class UsingLogMonitorAdapter { //-------------------------------------------------------------------------- // Constants: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Protected Variables: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Private Variables: //-------------------------------------------------------------------------- private static LogMonitorAdapter _adapter; static { _adapter = LogMonitorAdapter.newInstance(LogMonitorAdapter.LOG4J_LOG_LEVELS); } //-------------------------------------------------------------------------- // Constructors: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Public Methods: //-------------------------------------------------------------------------- public static void main(String[] args) { UsingLogMonitorAdapter test = new UsingLogMonitorAdapter(); test.doMyBidding(); } public void doMyBidding() { String logger = this.getClass().getName(); // will default to debug log level _adapter.log(logger, "Doh this is a debugging"); _adapter.log(logger, LogLevel.INFO, "Hmmm fobidden doughnut"); _adapter.log(logger, LogLevel.WARN, "Danger Danger Will Robinson", new RuntimeException("DANGER"), "32"); _adapter.log(logger, LogLevel.ERROR, "Exit stage right->"); _adapter.log(logger, LogLevel.FATAL, "What's up Doc?", new NullPointerException("Unfortunate exception")); } //-------------------------------------------------------------------------- // Protected Methods: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Private Methods: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Nested Top-Level Classes or Interfaces: //-------------------------------------------------------------------------- } apache-log4j1.2-1.2.17.orig/examples/lf5/index.html 0000644 0001750 0001750 00000002024 11751454714 020274 0 ustar tony tony
See Examples section in the LogFactor5 user guide.
apache-log4j1.2-1.2.17.orig/examples/lf5/OpeningLogFiles/ 0000755 0001750 0001750 00000000000 11751454714 021325 5 ustar tony tony apache-log4j1.2-1.2.17.orig/examples/lf5/InitUsingPropertiesFile/ 0000755 0001750 0001750 00000000000 12126647422 023064 5 ustar tony tony apache-log4j1.2-1.2.17.orig/examples/lf5/InitUsingPropertiesFile/InitUsingPropertiesFile.java 0000644 0001750 0001750 00000012353 11751454714 030524 0 ustar tony tony /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package examples.lf5.InitUsingPropertiesFile; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import java.io.IOException; import java.net.URL; /** * This is another simple example of how to use the LogFactor5 * logging console. * * The LF5Appender is the primary class that enables logging to the * LogFactor5 logging window. If the following line is added to a properties * file, the LF5Appender will be appended to the root category when * the properties file is loaded: * * log4j.appender.A1=org.apache.log4j.lf5.LF5Appender * * To make this example work, you must ensure that the example.properties file * is in your classpath.You can then run the example at the command line. * * @author Brent Sprecher */ // Contributed by ThoughtWorks Inc. public class InitUsingPropertiesFile { //-------------------------------------------------------------------------- // Constants: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Protected Variables: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Private Variables: //-------------------------------------------------------------------------- private static Logger logger = Logger.getLogger(InitUsingPropertiesFile.class); //-------------------------------------------------------------------------- // Constructors: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Public Methods: //-------------------------------------------------------------------------- public static void main(String argv[]) { // Use a PropertyConfigurator to initialize from a property file. String resource = "/examples/lf5/InitUsingPropertiesFile/example.properties"; URL configFileResource = InitUsingPropertiesFile.class.getResource(resource); PropertyConfigurator.configure(configFileResource); // Add a bunch of logging statements ... logger.debug("Hello, my name is Homer Simpson."); logger.debug("Hello, my name is Lisa Simpson."); logger.debug("Hello, my name is Marge Simpson."); logger.debug("Hello, my name is Bart Simpson."); logger.debug("Hello, my name is Maggie Simpson."); logger.info("We are the Simpsons!"); logger.info("Mmmmmm .... Chocolate."); logger.info("Homer likes chocolate"); logger.info("Doh!"); logger.info("We are the Simpsons!"); logger.warn("Bart: I am through with working! Working is for chumps!" + "Homer: Son, I'm proud of you. I was twice your age before " + "I figured that out."); logger.warn("Mmm...forbidden donut."); logger.warn("D'oh! A deer! A female deer!"); logger.warn("Truly, yours is a butt that won't quit." + "- Bart, writing as Woodrow to Ms. Krabappel."); logger.error("Dear Baby, Welcome to Dumpsville. Population: you."); logger.error("Dear Baby, Welcome to Dumpsville. Population: you.", new IOException("Dumpsville, USA")); logger.error("Mr. Hutz, are you aware you're not wearing pants?"); logger.error("Mr. Hutz, are you aware you're not wearing pants?", new IllegalStateException("Error !!")); logger.fatal("Eep."); logger.fatal("Mmm...forbidden donut.", new SecurityException("Fatal Exception")); logger.fatal("D'oh! A deer! A female deer!"); logger.fatal("Mmmmmm .... Chocolate.", new SecurityException("Fatal Exception")); } //-------------------------------------------------------------------------- // Protected Methods: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Private Methods: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Nested Top-Level Classes or Interfaces: //-------------------------------------------------------------------------- } apache-log4j1.2-1.2.17.orig/examples/lf5/InitUsingPropertiesFile/example.properties 0000644 0001750 0001750 00000002672 11751454714 026647 0 ustar tony tony # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # 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 LF5Appender which outputs to a swing # logging console. log4j.appender.A1=org.apache.log4j.lf5.LF5Appender log4j.appender.A1.MaxNumberOfRecords=700 apache-log4j1.2-1.2.17.orig/examples/lf5/InitUsingXMLPropertiesFile/ 0000755 0001750 0001750 00000000000 12126647422 023445 5 ustar tony tony apache-log4j1.2-1.2.17.orig/examples/lf5/InitUsingXMLPropertiesFile/example.xml 0000644 0001750 0001750 00000002241 11751454714 025624 0 ustar tony tony