😊

2012-07-27 Thread GALLAGHER, RON


Sent from my iPhone


RE: Could not instantiate appender named "console"

2010-10-18 Thread GALLAGHER, RON (ATTSI)
Hamed,

I believe this is the key message for you:

Could not find value for key log4j.appender.console

You've configured an appender named "CONSOLE", but you haven't
configured one named "console".  Case matters.

Change these three lines:

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%t:%p] %c: %m%n

to this:

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%t:%p] %c: %m%n

and you should see better results.

Ron Gallagher

-Original Message-
From: HJD [mailto:hamed_...@yahoo.com] 
Sent: Monday, October 18, 2010 2:56 AM
To: log4j-user@logging.apache.org
Subject: Could not instantiate appender named "console"


Hi all,
I'm running my program and I want to log program activities using log4j.
First, I set the log4j to DEBUG level and to write in the file, but what
is
written in the file is just at INFO level.
Second, I set it to write on the console and I get these errors:

log4j:ERROR Could not find value for key log4j.appender.console
log4j:ERROR Could not instantiate appender named "console".

and this is my log4j.properties file content:

# Root logger option
log4j.rootLogger=debug, console, file

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.Threshold=DEBUG
log4j.appender.file.File=C:\\logfile.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L -
%m%n

# Direct log messages to stdout
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.console.Threshold=DEBUG
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%t:%p] %c: %m%n
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L
-
%m%n


Does anyone have any idea?
Regards,
Hamed
-- 
View this message in context:
http://old.nabble.com/Could-not-instantiate-appender-named-%22console%22
-tp29987859p29987859.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org


-
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org



RE: Log4j Configuration

2007-06-28 Thread Gallagher, Ron
Ed --

Here's my recommendation:

1) Create a class that extends java.io.PrintStream.
2) In this class, override the public void println(String) method.  In
the overridden method, evaluate the string that's being written.  If the
string that's being written begins with "log4j:ERROR ", then record the
fact that log4j has encountered an error.
3) Before log4j loads it's configuration, replace System.err with your
extension of java.io.PrintStream.
4) Let log4j configure itself.
5) After the configuration is complete, restore System.err to the
original PrintStream and check your extension of java.io.PrintStream to
see if log4j wrote any error messages to System.err.

Here's some code:

// This is my extension of java.io.PrintStream
public class MyPrintStream extends PrintStream {
private List log4jErrors = new ArrayList();
public MyPrintStream(OutputStream out) throws FileNotFoundException
{
super(out);
}
public void println(String x) {
// Record any errors that originate from log4j.
if ((x != null) && (x.startsWith("log4j:ERROR "))) {
log4jErrors.add(x);
}
super.println(x);
}
public String[] getLog4jErrors() {
String[] result = new String[log4jErrors.size()];
result = (String[])log4jErrors.toArray(result);
return result;
}
}

// This class demonstrates how this would work.
private void runTest() {
try {
// Setup a new error stream.
MyPrintStream myPs = new MyPrintStream(System.err);
PrintStream oldErr = System.err;
System.setErr(myPs);

// Configure log4j.
DOMConfigurator.configureAndWatch("log4j.xml");

// Since my configuration has no errors in it, log4j didn't
write
// anything out to it's 'raw' logger. So, just for testing
purposes,
// I am going to write some messages out to log4j's 'raw' logger
in
// order to illustrate how you can respond to any errors that
occur
// during configuration. In a 'normal' situation, you would not
do
// this.
LogLog.error("Something bad has happened!!");
LogLog.error("This is an exception", new Exception(
"This is the exception"));

// Restore the old error stream.
System.setErr(oldErr);

// Check to see if log4j wrote anything out to System.err
String[] errors = myPs.getLog4jErrors();
if ((errors != null) && (errors.length != 0)) {
System.out.println("log4j recorded " + errors.length
+ (errors.length == 1 ? " error." : " errors."));
for (int i = 0; i < errors.length; i++) {
System.out.println("log4jErrors[" + i + "]="
+ errors[i]);
}
System.exit(1);
}

} catch (FileNotFoundException e) {
e.printStackTrace();
}
}

Ron Gallagher, AT&T Mobility

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 28, 2007 5:38 AM
To: Log4J Users List
Subject: Re: Log4j Configuration

Hi

Anybody got any ideas on this one?
Am i in correct mail list?
Rgds

Ed Howard
GSK House D3-133 ext 4996
external 00 44 020 8047 4996

[EMAIL PROTECTED] wrote on 25/06/2007 16:26:32:

> Hi
> Hopefully someone can help me. 
> I want to configure log4j from a properties file.
> I am writing a little java application. I have several log4j 
> appenders and everything works well. However I want the option to 
> exit application if ANY of log4j configuration fails.
> By default I am seeing a warning message from Log4j but application 
> continues to run...
> Do you know of a property to set for log4j that application exits if
> log4j properties are not correct?
> OR should I attempt this programmicatally.
> 
> Rgds
> 
> Ed Howard
> 
> ---
> This e-mail was sent by GlaxoSmithKline Services Unlimited 
> (registered in England and Wales No. 1047315), which is a 
> member of the GlaxoSmithKline group of companies. The 
> registered address of GlaxoSmithKline Services Unlimited 
> is 980 Great West Road, Brentford, Middlesex TW8 9GS.
> ---

---
This e-mail was sent by GlaxoSmithKline Services Unlimited 
(registered in England and Wales No. 1047315), which is a 
member of the GlaxoSmithKline group of companies. The 
registered address of GlaxoSmithKline Services Unlimited 
is 980 Great West Road, Brentford, Middlesex TW8 9GS.
---

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: JUnit testing of output logged with log4j?

2007-06-25 Thread Gallagher, Ron
Bob --

Have you considered using an appender that doesn't write to any files
but simply collects all messages for later analysis?

Here's how:

1) Create an appender that simply stores all logging messages in a
static array.  This appender should also provide static methods to (a)
retrieve all messages that were logged and (b) clear out the static
message array.  Something like this:

package com.fwl;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;
public class AppenderForTesting extends AppenderSkeleton {
private static List messages = new ArrayList();
protected void append(LoggingEvent event) {
messages.add(event.getRenderedMessage());
}
public void close() {}
public boolean requiresLayout() {return false;}
public static String[] getMessages() {
return (String[]) messages.toArray(new String[messages.size()]);
}
public static void clear() {
messages.clear();
}
}

BTW, "fwl" is my TLA for "fun with logging".

2) Configure log4j so that this appender is attached to all loggers are
used by the target of your test.  I'm taking a very simplistic approach
here and just attaching this appender to the root logger:













3) In the setUp method in your test harness, clear out the message list
that's used by the appender:

protected void setUp() throws Exception {
super.setUp();
AppenderForTesting.clear();
}

You also may want to include this logic in the tearDown method as well,
just to ensure that the message list is kept to a minimum.

4) In your test, after you invoke the method that should generate
logging messages, validate the actual output.  Here is the code for a
simple class I wrote that just divides two numbers and a test harness
for that class.

package com.fwl;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
public class MyMath {
private static final Logger LOG =
LogManager.getLogger(MyMath.class);
public static double divide(int numerator, int denominator) {
LOG.debug("dividing "  + numerator + " by " + denominator);
try {
return (numerator / denominator);
} catch (Exception e) {
LOG.error("Unable to divide " + numerator + " by "
+ denominator, e);
if (denominator==0){
LOG.error("You should never attempt to divide by 0");
}
return 0;
}
}
}


package com.fwl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import junit.framework.TestCase;
public class MyMathTest extends TestCase {

public void testDivideDenominatorIsZero() {
MyMath.divide(2, 0);
String[] expectedMessage = new String[]{"dividing 2 by 0"};
validateMessages(expectedMessage);
}

private void validateMessages(String expectedMessages[]) {
// Build a list of expected messages.
List expected = new ArrayList();
for (int i = 0; i < expectedMessages.length; i++) {
if (expectedMessages[i] != null) {
expected.add(expectedMessages[i]);
}
}

// Evaluate the actual messages that were recorded.
List unexpected = new ArrayList();
String actual[] = AppenderForTesting.getMessages();
for (int i = 0; i < actual.length; i++) {
if (actual[i] != null) {
if (expected.contains(actual[i])) {
expected.remove(actual[i]);
} else {
unexpected.add(actual[i]);
}
}
}

// Fail if any expected messages were not found.
if (!expected.isEmpty()) {
StringBuffer sb = new StringBuffer();
for (Iterator iter = expected.iterator(); iter.hasNext();) {
sb.append("\n").append((String) iter.next());
}
fail("did not receive the following message(s):" + sb);
}
// Fail if any unexpected messages were found.
if (!unexpected.isEmpty()) {
StringBuffer sb = new StringBuffer();
for (Iterator iter = unexpected.iterator(); iter.hasNext();)
{
sb.append("\n").append((String) iter.next());
}
fail("received the following unexpected message(s):" + sb);
}
}
}

In the testDivideDenominatorIsZero method, we are only expecting the
message "dividing 2 by 0".  However, the actual test writes out two
extra messages when the denominator is 0:

  * "Unable to divide 2 by 0"
  * "You should never attempt to divide by 0"

The validateMessages method retrieves the actual messages that were
written out to the logger and will record a test failure since the
messages above were not included in the expected messages list.

Ron Gallagher, AT&T Mobility

-Original M

RE: Configuring a file appender using environment variable

2007-06-01 Thread Gallagher, Ron
Quinn --

Use the syntax ${xxx} in your configuration file, replacing xxx with the
name of the system property that you want to use.

Ron Gallagher, AT&T Mobility

-Original Message-
From: Cheung, Quinn [mailto:[EMAIL PROTECTED] 
Sent: Friday, June 01, 2007 10:06 AM
To: Log4J Users List
Subject: Configuring a file appender using environment variable

Is it possible to configure the output file of a file appender using the
environment variable APPDATA (Windows XP)? What is the syntax in the
log4j.properties file and do I have to send an argument to the JVM?

Thanks,


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Unable to call doRender. Am I missing anything?

2007-06-01 Thread Gallagher, Ron
Naider --

The purpose of Renderers is to generate a String representation of an
Object. Since a String is already a String, there's no need to do any
additional rendering.

The getRenderedMessage method in the LoggingEvent is what is responsible
for calling any defined renderers.  This method has an explicit check
for situations where the object that's about be rendered is an instance
of String.  In that case, the Object to render is simply cast into a
String and used as-is.


Ron Gallagher, AT&T Mobility


-Original Message-
From: Naider Chen [mailto:[EMAIL PROTECTED] 
Sent: Thursday, May 31, 2007 5:26 PM
To: Log4J Users List
Subject: Unable to call doRender. Am I missing anything?

I'm trying to intercept the logging message to filter
some keyword before forwarding to the destination.  I
tested it in a windows environment using RAD6 

I add the new  tag entry to log4j.xml and
put both log4j.dtd and log4j.xml in the
WEB-INF/classes folder but after I re-compile and
bounce the server the doRender method was never get
called.  

Am I missing snything?  Please help.  Thanks.



I create a new class test.log4j.LogCatcher as follows:

package test.log4j;
import org.apache.log4j.*;
import org.apache.log4j.spi.*;
import org.apache.log4j.or.ObjectRenderer;

public class LogCatcher implements ObjectRenderer {

public String doRender(Object arg0) {
String st = arg0.toString();
System.out.println("LogCatcher doRender **
log string catched = *" + st + "*");
return st;
}
}

ALWAYS THERE FOR YOU!!!
Naider Chen
EMAIL ME ANYTIME




   


Choose the right car based on your needs.  Check out Yahoo! Autos new
Car Finder tool.
http://autos.yahoo.com/carfinder/

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Third Party Appenders

2007-05-23 Thread Gallagher, Ron
Roger --

I'm not aware of an existing appender that does what you're asking, but
it wouldn't be difficult to create one.  Just create a class that
extends org.apache.log4j.AppenderSkeleton and override the
append(LoggingEvent) method.  In append(LoggingEvent), you'd run
whatever program you wanted via the java.lang.Runtime class. 

Ron Gallagher, AT&T Mobility

-Original Message-
From: Roger Varley [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, May 23, 2007 1:00 PM
To: Log4J Users List
Subject: Re: Third Party Appenders

>
> You can accomplish what you want using the components that come
packaged
> w/ log4j.  Here's a log4j configuration that should accomplish your
> goals.  Explanations follow:
>

Ron, thank you very much for that very full and very clear
explanation. I can see how this will get me most of the way to what I
want by applying filters to the email appender. One last question if I
may, is there an appender available that will trigger the execution of
another java class when a message arrives. There is one message that
requires a re-start of the application and I would like to script the
restart based on the arrival of that message in the log (rather than
being woken in the middle of the night when a user can't log in).

I appreciate that this is not really what log4j was designed for, but
when I have no control over the application itself, this seems a
reasonably elegant way.

Regards
Gilbert

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Third Party Appenders

2007-05-23 Thread Gallagher, Ron
Gilbert --

You can accomplish what you want using the components that come packaged
w/ log4j.  Here's a log4j configuration that should accomplish your
goals.  Explanations follow:








































1) The root logger is setup w/ 2 appenders: AllOutput and SpecialOutput.

2) The AllOutput appender is a simple file appender that accepts every
logging request and writes the rendered output for each message out to
the file ${user.dir}/AllOutput.log.

3) The SpecialOutput appender is also a simple file appender.  However,
this appender only writes logging message if the attached filters accept
it. There are three filters attached to the SpecialOutput appender:

The first filter will accept any logging requests where the rendered
message contains the string "ERR-10234".  If the rendered message
doesn't contain the string "ERR-10234", then the logging request will be
evaluated by the remaining filters.

The second is basically the same as the first except that it accepts
logging requests only if the rendered message contains "ERR-30857".

The third filter is the 'catch all' filter that will reject any logging
request that wasn't accepted by any of the previous filters. 

Assume that the SpecialOutput appender in place as outlined above and
that the following code is run: 

Logger logger = LogManager.getLogger(MyClass.class);
logger.debug("Greetings from Initech"); // msg11
logger.debug("ERR-10234: TPS report is invalid!"); // msg2
logger.debug("ERR-30857: TPS report has incorrect cover page!"); // msg3
logger.debug("ERR-43821: Bill Lumbergh needs a new tie"); // msg4

The ${user.dir}/AllOutput.log file would contain the following since
there are no filters on the AllOutput appender

Greetings from Initech
ERR-10234: TPS report is invalid!
ERR-30857: TPS report has incorrect cover page!
ERR-43821: Bill Lumbergh needs a new tie

The ${user.dir}/SpecialOutput.log file would only contain the following
two lines since these messages are the only ones that were accepted by
the filters that are attached to the SpecialOutput appender:

ERR-10234: TPS report is invalid!
ERR-30857: TPS report has incorrect cover page!

My example above used the FileAppender that come packaged w/ log4j, but
the same concepts could be applied to any log4j appender.


Ron Gallagher, AT&T Mobility

-Original Message-
From: Roger Varley [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, May 23, 2007 7:37 AM
To: log4j-user@logging.apache.org
Subject: Third Party Appenders

Hi

Is there an appender that will allow me to monitor for a specific
message or list of specific messages and allow me to trigger an action
against those messages. I may need a different action for each
message.

Background.

I'm supporting a third party java web application. I don't have access
to the source code nor am I allowed to de-compile and modify the
source code. However, the application is using log4j for it's logging.
At the moment I'm manually monitoring the logfiles for the appearance
of specific messages and manually taking action based on those
messages.

I've tried writing a unix like "tail" program to monitor the logfile
directly but this fails overnight when the logfile rolls over to a new
logfile. So I thought that adding my own appender might be a more
elegant solution. I'm quite prepared to have a go at doing this myself
but I thought that I would check first in case this has already been
done. I'd also be grateful for alternate suggestions if it is
generally felt that this is not a good idea.

Regards
Gilbert

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Logger level being ignored

2007-05-23 Thread Gallagher, Ron
Ben --

Here's your problem:

log4j: Setting [org.apache.commons.httpclient] additivity to [true].

With the additivity of the org.apache.commons.httpclient logger set to
true, any logging output that is processed by the
org.apache.commons.httpclient will also be processed by any explicitly
configured loggers in it's ancestry, including the 'root' logger.

To change this behavior, just set the additivity on the
org.apache.commons.httpclient to false.  



Ron Gallagher, AT&T Mobility

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of
ben short
Sent: Wednesday, May 23, 2007 10:54 AM
To: Log4J Users List
Subject: Re: Logger level being ignored

Heres my output with -Dlog4j.debug. Seems to show the correct setup of
the logger.

log4j: Trying to find [log4j.properties] using
ClassLoader.getSystemResource().
log4j: Could not find resource: [null].
log4j:WARN No appenders could be found for logger
(org.apache.commons.digester.Digester.sax).
log4j:WARN Please initialize the log4j system properly.
log4j: System property is :null
log4j: Standard DocumentBuilderFactory search succeded.
log4j: DocumentBuilderFactory is:
org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
log4j: debug attribute= "null".
log4j: Ignoring debug attribute.
log4j: Threshold ="null".
log4j: Retreiving an instance of org.apache.log4j.Logger.
log4j: Setting [org.springframework] additivity to [true].
log4j: Level value for org.springframework is  [WARN].
log4j: org.springframework level set to WARN
log4j: Retreiving an instance of org.apache.log4j.Logger.
log4j: Setting [org.apache.commons.httpclient] additivity to [true].
log4j: Level value for org.apache.commons.httpclient is  [WARN].
log4j: org.apache.commons.httpclient level set to WARN
log4j: Level value for root is  [all].
log4j: root level set to ALL
log4j: Class name: [org.apache.log4j.RollingFileAppender]
log4j: Setting property [maxFileSize] to [128MB].
log4j: Setting property [maxBackupIndex] to [5].
log4j: Setting property [file] to
[/opt/apache-tomcat-5.5.23/logs/jc_core.log].
log4j: Setting property [threshold] to [DEBUG].
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d{ABSOLUTE} %5p %C:%L -
%m%n].
log4j: setFile called: /opt/apache-tomcat-5.5.23/logs/jc_core.log, true
log4j: setFile ended
log4j: Adding appender named [FILE] to category [root].

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Configuring Log4J with Maven Testing and Production

2007-04-05 Thread Gallagher, Ron
I've added an entry to the wiki page you referenced.

Ron Gallagher 

-Original Message-
From: Jacob Kjome [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, April 03, 2007 10:16 PM
To: Log4J Users List
Subject: RE: Configuring Log4J with Maven Testing and Production


This might make a good wiki entry.  I encourage you to enter it if 
you get a chance...

http://wiki.apache.org/logging-log4j/UsefulCode


Jake

At 02:53 PM 4/3/2007, you wrote:
 >Mark --
 >
 >Try this:
 >
 >1) Rename the log4j.xml file that you use for testing to something
else,
 >perhaps test-log4j.xml.  Keep it in the src/test/resources directory.
 >
 >2) Make sure that you've included a testResource entry in your pom
that
 >includes the test-log4j.xml file.  Something like this:
 >
 >
 >  
 >
 >  src/test/resources
 >  
 >test-log4j.xml
 >  
 >
 >  
 >
 >
 >This entry will force Maven to copy the test-log4j.xml file from the
 >src/test/resources directory to the target/test-classes whenever it
 >compiles the test classes.
 >
 >3) Tell log4j to use your test configuration file during the unit
tests.
 >This is done by configuring the surefire plugin.  More specifically,
 >you'll set the "log4j.configuration" system property to
 >"test-log4j.xml".  Details on configuring the surefire plugin can be
 >found at
 
>http://maven.apache.org/plugins/maven-surefire-plugin/examples/system-p
r
 >operties.html.  Here's what I believe you'll need to configure the
 >surefire plugin:
 >
 >
 >  
 >
 >  org.apache.maven.plugins
 >  maven-surefire-plugin
 >  
 >
 >  
 >log4j.configuration
 >test-log4j.xml
 >  
 >
 >  
 >
 >  
 >
 >
 >Ron Gallagher
 >
 >-Original Message-
 >From: Mark Hansen [mailto:[EMAIL PROTECTED]
 >Sent: Tuesday, April 03, 2007 1:14 PM
 >To: log4j-user@logging.apache.org
 >Subject: Configuring Log4J with Maven Testing and Production
 >
 >I use Log4J and build my applications with Maven2.  I have a log4j.xml
 >config file in the src/main/resources directory so that Maven2 builds
it
 >
 >into the JAR with my application.
 >
 >However, I have a different log4j.xml that I want to use with the
JUnit
 >test that run as part of my Maven build process.  I'd like to put that
 >log4j.xml (testing) in the src/test/resources directory and have it
 >overide the production version in src/main/resources.  However, Maven
 >doesn't seem to work that way.  Instead, the production version of
 >log4j.xml seems to come first on the testing classpath and therefore
 >gets loaded instead of the testing version of log4j.xml.
 >
 >I'm sure others must have faced this issue.  Are there any recommended
 >solutions to the problem?
 >
 >Thanks,
 >
 >Mark
 >
 >-
 >To unsubscribe, e-mail: [EMAIL PROTECTED]
 >For additional commands, e-mail: [EMAIL PROTECTED]
 >
 >
 >-
 >To unsubscribe, e-mail: [EMAIL PROTECTED]
 >For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Configuring Log4J with Maven Testing and Production

2007-04-03 Thread Gallagher, Ron
Mark --

Try this:

1) Rename the log4j.xml file that you use for testing to something else,
perhaps test-log4j.xml.  Keep it in the src/test/resources directory.

2) Make sure that you've included a testResource entry in your pom that
includes the test-log4j.xml file.  Something like this:


  

  src/test/resources
  
test-log4j.xml
  

  


This entry will force Maven to copy the test-log4j.xml file from the
src/test/resources directory to the target/test-classes whenever it
compiles the test classes.

3) Tell log4j to use your test configuration file during the unit tests.
This is done by configuring the surefire plugin.  More specifically,
you'll set the "log4j.configuration" system property to
"test-log4j.xml".  Details on configuring the surefire plugin can be
found at
http://maven.apache.org/plugins/maven-surefire-plugin/examples/system-pr
operties.html.  Here's what I believe you'll need to configure the
surefire plugin:


  

  org.apache.maven.plugins
  maven-surefire-plugin
  

  
log4j.configuration
test-log4j.xml
  

  

  


Ron Gallagher 

-Original Message-
From: Mark Hansen [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, April 03, 2007 1:14 PM
To: log4j-user@logging.apache.org
Subject: Configuring Log4J with Maven Testing and Production

I use Log4J and build my applications with Maven2.  I have a log4j.xml 
config file in the src/main/resources directory so that Maven2 builds it

into the JAR with my application.

However, I have a different log4j.xml that I want to use with the JUnit 
test that run as part of my Maven build process.  I'd like to put that 
log4j.xml (testing) in the src/test/resources directory and have it 
overide the production version in src/main/resources.  However, Maven 
doesn't seem to work that way.  Instead, the production version of 
log4j.xml seems to come first on the testing classpath and therefore 
gets loaded instead of the testing version of log4j.xml.

I'm sure others must have faced this issue.  Are there any recommended 
solutions to the problem?

Thanks,

Mark

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Logger (not Appender) Filter

2007-01-24 Thread Gallagher, Ron
Brett --

I can't address the reasons for why filters aren't allowed at the logger
level, but I can offer you a solution to your problem.

Appenders can be nested.  Simply attach an appender "A" to the logger
for "com.xyz.dostuff".  The configure appender "A" with the filter
you've described and three nested appenders, one each for the file,
console and email.

Here's a basic configuration.

  




  
  

  
  

  
  

  
  


  

The key is the configuration of the appender "Main.CustomApp.Appender".
This appender does nothing more than delegate to any appenders that are
attached to it.  In the configuration above, the
"Main.CustomApp.Appender" has three attached appenders.  However, before
any logging events are delegated to the attached appenders, the filters
are all interrogated to determine whether the delegation should occur.
With this approach, you configure your filter once, and the filter's
decision is applied to 3 separate filters.

The configuration above utilizes the AsyncAppender class which is the
only class I found in the core log4j libraries that implements both the
Appender and AppenderAttachable interfaces.  If you don't want to
utilize the asynchronous aspects of this appender, you'll either have to
roll your own non-asynchronous appender or search the various
contributions to see if someone has already developed one.

Ron Gallagher 
Cingular Wireless


-Original Message-
From: Brett Birschbach [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 23, 2007 5:07 PM
To: log4j-user@logging.apache.org
Subject: Logger (not Appender) Filter


Is there a good reason why the default log4j implementation does not
allow
for a filter at the Logger level? I know we can add filters to
Appenders,
but there are certain scenarios where this can be quite wasteful on
resources. Perhaps I am attacking this situation all wrong? 

Scenario:
-Using code developed by a different company. 
-The code from package com.xyz.dostuff generates a log.error, including
the
stack trace, whenever an exception occurs. 
-If the Exception descends from a certain type of exception, I do not
want
the exception to clutter up the log with the stack trace, nor be logged
at
the error level.
-The root logger has 3 appenders (file, console, and email) 

Possible Solution: 
-Add a filter to all 3 appenders to filter out the undesired log.error's
Cons: 
-Repeatitive declarations (adding filter to all 3 appenders) 
-Every single log statement that goes through the root logger must go
through the filter
-For every single log statment, the filter is executed 3 times, once for
each filter

Proposed Solution: 
-Add a filter (not possible using default log4j) to the specific logger
com.xyz.dostuff
Pros: 
-Only need to add the filter to one logger vs. three appenders 
-Only log messages from the specific package com.xyz.dostuff must pass
through the filter
-The filter is executed only once for each log statement.

1) Am I overlooking this functionality, and is it already built into
log4j?
2) Am I looking at this problem completely wrong, and is there a better
approach?
3) If 1) and 2) are no, are there any drawbacks to me wrapping the
org.apache.log4j.Logger class and adding the functionality for filters?
I
assume I would need to override the default configuration classes as
well?

-- 
View this message in context:
http://www.nabble.com/Logger-%28not-Appender%29-Filter-tf3077715.html#a8
550568
Sent from the Log4j - Users mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: How to use log4j (log4j.xml) and Maven and Junit??

2007-01-24 Thread Gallagher, Ron
Lisa --

You don't need to make any modifications to the mvn script to accomplish
what you're trying to do.  Here's what we do...

1) Set up a directory that will contain resource/configuration files
that you want available when you run your tests.  For us, we use
${basedir}/src/test/config

2) Put any resource/configiguration files you want available during
tests in that directory.  For your situation, you'd put the log4j.xml
file in the ${basedir}/src/test/config directory.

3) Add an entry to the build/testResources element in your pom.xml.
Here's an example:
  

  
src/test/config

  log4j.xml

  

  
You need to add an 'include' entry for each resource.  Check out
http://maven.apache.org/ref/current/maven-model/maven.html#class_testRes
ource for more details on what you can do with the testResources
element.

With these changes in place, Maven will copy to the test/classes folder
all of the test resources you've listed.  The test/classes folder is
included in the class path when Maven runs your tests, so log4j will
utilize the log4j.xml file that was originally located in
src/test/config.

As far as turning on log4j's debugging, just set the  debug attribute in
the root element to "true". 

Ron Gallagher 
Cingular Wireless

-Original Message-
From: news [mailto:[EMAIL PROTECTED] On Behalf Of Lisa
Sent: Tuesday, January 23, 2007 5:17 PM
To: log4j-user@logging.apache.org
Subject: How to use log4j (log4j.xml) and Maven and Junit??

I have written some JUnit tests and put them in the standard layout for
test
cases under Maven.  The tests use log.debug(msg), log.info(msg) etc.

The tests run OK.

So now I created a simple log4j.xml file with an appender and a logger
that
filters only the logging messages in my test case (by package).

When I run maven (mvn test), how do I tell it where my log4j.xml is and
how to
use log4j logging?

I have tried everything.  I edited the "mvn" script under the install
directory
to include the following:

 exec "$JAVACMD" \
   $MAVEN_OPTS \
   -classpath "${M2_HOME}"/core/boot/classworlds-*.jar \
   "-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \
   "-Dmaven.home=${M2_HOME}"  \
   "-Dmaven.junit.sysproperties=log4j.configuration" \
   "-Dlog4j.configuration=file:C:\tmp\log4j.xml" \
   ${CLASSWORLDS_LAUNCHER} $QUOTED_ARGS


this does not work (have tried with and without file:.

---
I have included a something similiar on the mvn command line:
   mvn -Dlog4j.configuration=c:\tmp\log4j.xml  test

this does not work (have included =file:c:\tmp... as well

---
I have also tried setting properties in the pom.xml like so:


org.apache.maven.plugins
maven-surefire-plugin

false
false



maven.junit.sysproperties
log4j.configuration


log4j.configuration
file=:c:\tmp\log4j.xml





---
and 


org.apache.maven.plugins
maven-surefire-plugin

false
false



maven.junit.sysproperties
log4j.configuration


log4j.configuration
c:\tmp\log4j.xml





--- and  (log4j.xml is in same directory as pom.xml) this does not work
either.



org.apache.maven.plugins
maven-surefire-plugin

false
false



maven.junit.sysproperties
log4j.configuration


log4j.configuration
log4j.xml






---
none of these work.  Any ideas on how to integrate Maven2, Log4J and
Junit would
be greatly appreciated.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Deployment of 1.2.14 to Maven repository at ibiblio.org

2006-11-28 Thread Gallagher, Ron
All --

Are there any plans to deploy version 1.2.14 to a the Maven repository
that's hosted at ibilio.org?

Ron Gallagher 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]