User: starksm Date: 01/05/03 23:08:08 Modified: src/main/org/jboss/logging Log4jService.java Added: src/main/org/jboss/logging ConsoleAppender.java Log: Add a log4j ConsoleAppender to handle the console output that captures msgs written directly to System.out and System.err Revision Changes Path 1.6 +2 -2 jboss/src/main/org/jboss/logging/Log4jService.java Index: Log4jService.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/logging/Log4jService.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Log4jService.java 2001/04/27 15:56:50 1.5 +++ Log4jService.java 2001/05/04 06:08:08 1.6 @@ -38,7 +38,7 @@ @author <a href="mailto:[EMAIL PROTECTED]">Fulco Muriglio</a> @author [EMAIL PROTECTED] @author <a href="mailto:[EMAIL PROTECTED]">David Jencks</a> -@version $Revision: 1.5 $ +@version $Revision: 1.6 $ */ public class Log4jService implements Log4jServiceMBean, NotificationListener, MBeanRegistration @@ -109,7 +109,6 @@ URL url = loader.getResource(configurationPath); if( url == null ) throw new FileNotFoundException("Failed to find logj4 props: "+configurationPath); - this.category = Category.getRoot(); if( refreshFlag ) { // configurationPath is a file path @@ -120,6 +119,7 @@ { PropertyConfigurator.configure(url); } + this.category = Category.getRoot(); category.info("Started Log4jService, config="+url); } /** Stops the log4j framework by calling the Category.shutdown() method. 1.1 jboss/src/main/org/jboss/logging/ConsoleAppender.java Index: ConsoleAppender.java =================================================================== package org.jboss.logging; import java.io.PrintStream; import org.apache.log4j.AppenderSkeleton; import org.apache.log4j.Category; import org.apache.log4j.Priority; import org.apache.log4j.spi.LoggingEvent; /** A log4j Appender implementation that writes to the System.out and System.err console streams. It also installs PrintStreams for System.out and System.err to route logging through those objects to the log4j system via a category named Default. @author [EMAIL PROTECTED] @version $Revision: 1.1 $ */ public class ConsoleAppender extends AppenderSkeleton { private Category category; private PrintStream out; private PrintStream err; /** Creates new ConsoleAppender */ public ConsoleAppender() { out = System.out; err = System.err; System.setOut(new Log4jStream(Priority.INFO, out)); System.setErr(new Log4jStream(Priority.ERROR, err)); } public void activateOptions() { super.activateOptions(); category = Category.getInstance("Default"); } public boolean requiresLayout() { return true; } public void close() { if( out != null ) System.setOut(out); out = null; if( err != null ) System.setErr(err); err = null; } protected void append(LoggingEvent event) { String msg = this.layout.format(event); if( event.priority == Priority.ERROR ) out.print(msg); else err.print(msg); } class Log4jStream extends PrintStream { Priority priority; Log4jStream(Priority priority, PrintStream ps) { super(ps); this.priority = priority; } public void println(String msg) { category.log(priority, msg); } public void println(Object msg) { category.log(priority, msg); } } } _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-development
