You say that you have sys outs in the code, but in the code you supplied there aren't any. I assume that you haven't posted the whole code due to IP concerns, or because most of is not related to the problem. Either way, try to cut down the code to as small a block as possible which still has the problem. I often find when doing this, that removing chunks of code hilights where the problem is.
If you still can't find the problem, then post the small piece of code along with the similarly small property files, and maybe someone will be able to see where the problem is Chris On 9/22/06, Donna Johnson <[EMAIL PROTECTED]> wrote:
Yes, I have sys outs in the code that are being printed out, so I do know the code is being hit. Thanks for your response, though. :) -----Original Message----- From: Blok, Eelke [mailto:[EMAIL PROTECTED] Sent: Friday, September 22, 2006 2:41 AM To: Log4J Users List Subject: RE: Add appender programmatically after logger configured initially with PropertyConfigurator Hi, Are you sure your code to add the appenders is actually called (it's dependant on the presence and validity of some properties)? I don't see any obvious problems with the code itself. Best regards, Eelke Blok -----Original Message----- From: Donna Johnson [mailto:[EMAIL PROTECTED] Sent: vrijdag 22 september 2006 0:01 To: Log4J Users List Subject: RE: Add appender programmatically after logger configured initially with PropertyConfigurator Is there anyone who can please help me with this? I am writing a logging utility to be used by our services and, needless to say, I have several people waiting on me. Thank you! Donna ________________________________ From: Donna Johnson Sent: Wednesday, September 20, 2006 4:40 PM To: 'Log4J Users List' Subject: RE: Add appender programmatically after logger configured initially with PropertyConfigurator Thank you for your response, Kamal. I added a call to activateOptions() on each appender, but that still does not work. I set log4j.debug to true, and I see debug trace for setting the configuration through the logger_config.properties file, but there is no trace for the appenders added in the code other than setting the file for the FileAppender - which I see twice and I've included below: log4j: setFile called: /home/djohnson/test.txt, true log4j: setFile ended log4j: setFile called: /home/djohnson/test.txt, true log4j: setFile ended Thank you so much for your help! Here's the code after I added the call to activateOptions(): try { PatternLayout layout; String loggerPropFile = properties.getProperty("ngl.config",null); String loggerName = properties.getProperty("ngl.logger.name", null); if (loggerPropFile != null) { PropertyConfigurator.configure(loggerPropFile); } logger = Logger.getLogger(loggerName); Enumeration en = logger.getAllAppenders(); int nbrOfAppenders = 0; while (en.hasMoreElements()) { nbrOfAppenders++; Object ap = en.nextElement(); } if (nbrOfAppenders > 1) { return; } try { if ("true".equals(properties .getProperty("ngl.console", "false"))) { layout = new PatternLayout("%d [%t] %-5p %m%n"); ConsoleAppender cnslAppndr = new ConsoleAppender(layout); logger.addAppender(cnslAppndr); cnslAppndr.activateOptions(); } } catch (RuntimeException e) { handleException(e); } try { String logfile = properties.getProperty("ngl.logfile", null); if (logfile != null) { layout = new PatternLayout("%d [%t] %-5p %m%n"); FileAppender fileAppender = new FileAppender(layout, logfile); logger.addAppender(fileAppender); fileAppender.activateOptions(); } } catch (RuntimeException e) { handleException(e); } } catch (Exception ex) { handleException(ex); } ________________________________ From: Kamal Ahmed [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 19, 2006 3:57 PM To: Log4J Users List Subject: RE: Add appender programmatically after logger configured initially with PropertyConfigurator Donna, I think you have to call activateOptions() method on your Appenders. Also what error message / debug trace are you getting? Hope this helps. -Kamal. ________________________________ From: Donna Johnson [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 19, 2006 4:48 PM To: [email protected] Subject: Add appender programmatically after logger configured initially with PropertyConfigurator I am trying to add a couple of appenders to my logger in the code based on flags in the application's properties file. I configure the logger with an appender in the logger.properties file initially and I want to add appenders to that programmatically. I add a console appender as well as a file appender (based on the flags). Nothing is being logged to either the console or the file, even though the file is being created. Any help is very much appreciated! Here is the logger.properties file: # Logger for Errors/Debugging (Syslog) log4j.logger.error=DEBUG, A1 log4j.appender.A1=org.apache.log4j.net.SyslogAppender log4j.appender.A1.syslogHost=localhost log4j.appender.A1.facility=LOCAL5 log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %m%n # Logger for stats log4j.logger.stats=INFO,A2 log4j.appender.A2=org.apache.log4j.RollingFileAppender log4j.appender.A2.File=./cust/properties/stats log4j.appender.A2.MaxFileSize=10MB log4j.appender.A2.MaxBackupIndex=1 log4j.appender.A2.layout=org.apache.log4j.PatternLayout log4j.appender.A2.layout.ConversionPattern=%d %m%n Here is the application properties file: # Log to console ngl.console=true # Log to local5 (Unix only) ngl.syslog=localhost:local5 # Log to a disk file ngl.logfile=./cust/properties/test.txt # Logging level (can be DEBUG, INFO, WARN, ERROR, or CRITICAL|FATAL) ngl.level=DEBUG # Host name that will print out on each log line ngl.hostname=localhost # If true, writes abbreviated log header with only level and message ngl.brief=false ngl.config=./cust/properties/logger_config.properties ngl.logger.name=error Here is the actual code to initialize the logger: try { PatternLayout layout; String loggerPropFile = properties.getProperty("ngl.config",null); String loggerName = properties.getProperty("ngl.logger.name", null); if (loggerPropFile != null) { PropertyConfigurator.configure(loggerPropFile); } logger = Logger.getLogger(loggerName); Enumeration en = logger.getAllAppenders(); int nbrOfAppenders = 0; while (en.hasMoreElements()) { nbrOfAppenders++; Object ap = en.nextElement(); } if (nbrOfAppenders > 1) { return; } try { if ("true".equals(properties .getProperty("ngl.console", "false"))) { layout = new PatternLayout("%d [%t] %-5p %m%n"); logger.addAppender(new ConsoleAppender(layout)); } } catch (RuntimeException e) { handleException(e); } try { String logfile = properties.getProperty("ngl.logfile", null); if (logfile != null) { layout = new PatternLayout("%d [%t] %-5p %m%n"); logger.addAppender(new FileAppender(layout, logfile)); } } catch (RuntimeException e) { handleException(e); } } catch (Exception ex) { handleException(ex); } Donna Johnson Sr. Programmer Analyst FedEx 10 Fedex Pkwy 2nd Floor Horizontal Collierville, TN 38017 <http://maps.yahoo.com/py/maps.py?Pyt=Tmap&addr=10+Fedex+Pkwy&csz=Collie rville%2C+TN++38017&country=us> [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> tel: 901-263-9914 Add me to your address book... <https://www.plaxo.com/add_me?u=51540020625&v0=826157&k0=553936137> Want a signature like this? <http://www.plaxo.com/signature> PRIVACY: The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or priviliged material. Any review, retransmission, dissemination or other use of this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. Thank you. --------------------------------------------------------------------- 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]
