RE: [SCL-3] using of system properties in subject of SMTPAppender
Usually a customer is served within one separate thread, isn't it? If yes, you can use the MDC (mapped diagnostic context). You put a value into it: MDC.put(CUSTOMER, SOME NAME) at the begin of the session (probably in a servlet listener) and reference this value with the layout pattern %X{CUSTOMER}. Do not forget to remove the value when session terminates! Heri -Original Message- From: Zbynek Vavros [mailto:zbynek_vav...@cz.ibm.com] Sent: Monday, May 23, 2011 4:18 PM To: log4j-user@logging.apache.org Subject: [SCL-3] using of system properties in subject of SMTPAppender Hi, I have a 1 server app and many clients app on different servers. Obviously I wanted to know from which server the email comes, so I used this: log4j.xml appender name=email class=org.apache.log4j.net.SMTPAppender param name=BufferSize value=512 / param name=SMTPHost value=my_smtp_host / param name=From value=AutoBot / param name=To value=my_em...@someserver.com / param name=Subject value=Agent on [${HOSTNAME}] has encountered error / layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{HH:mm:ss} [%t] %p %C (%L) %x - %m%n / /layout filter class=org.apache.log4j.varia.LevelRangeFilter param name=LevelMin value=error / param name=LevelMax value=fatal / /filter /appender and since system property has to be setup before configuring log4j, I use this in my code. Main class //create system property to hold server name System.setProperty(HOSTNAME, InetAddress.getLocalHost ().getCanonicalHostName()); //reconfigure log4j so it picks up HOSTNAME property DOMConfigurator.configure(getClass().getClassLoader().getResource( log4j.xml)); Then Im receiving emails with subject like this: Agent on [127.0.0.1] has encountered error. So far so good. And now I have request to include customer name in subject. I have no problem to include it in stack trace, but since I cannot set customer name the same way as I did with IP (there are multiple customers handled by my app so I cannot just use System.setProperty(CUSTOMER, SOME NAME)). I though of solution to set this property when exception is catched and reconfigure log4j after setting proper customer name into system property. But I think it is politelly said ugly. Can some1 suggest a better way maybe? Thanks, Zbynek Kind Regards / Mit freundlichen Grüßen / Üdvözlettel / S pozdravem: Zbynek VAVROS (Embedded Development image moved to file: pic20342.gif) Delivery Centre 616 00, Brno Central Europe Technicka 21 Brno SITE Czech Republic (Embedded image moved to file: pic17964.gif)Phone: 420-53341- x6283 Mobile: E-mail: zbynek_vav...@cz.ibm.com IBM Global Services Delivery Center Czech Republic, s.r.o. Registered address: Brno, Technicka 2995/21, Zip code: 61600, Company ID: 26244535 Entered in the Commercial Register
Appender-Webservice
hello sir: My Web service is here:http://www.smster.in/testwebservice/service.asmx now i want to cal the web service using Appender..How can i cal ? Thanks K.Elakkiya Gloria Tech http://gloriatech.com - In Christ, We Trust - This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to which they are addressed. If you have received this email in error please notify the system manager at postmas...@gloriatech.com. Please note that any ideas, views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of the company. Even though the company has put in place an effective security system to protect against viruses, the recipient should check this email and any attachments for the presence of viruses. The company will not accept any liability for damages caused by the contents of this email due to virus or any other means.
Re: Set Root Log Level on command line
You can specify a system property on the command line and expand it in the configuration. java -DrootLevel=INFO ... and in your configuration file do: log4j.rootLogger=${rootLevel} On May 23, 2011, at 2:58 PM, Andy Flury wrote: Hi All Is there a way to set the root log level on the command line? We have an application that runs either in Simulation mode or in Live mode. Depending on the mode, the log level needs to be debug or error. It would be very inconvenient to have two different log4j config files, because all other settings will be constant. thanks for your help andy flury - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
Re: log4j
There is an intro on the website, http://logging.apache.org/log4j/1.2/manual.html. Maybe that will not answer your question, but it will provide some background that may help you formulate your question. As it is written, it is unclear whether your situation is: a) There is an existing appender that I want to use and I do not know how to configure it and attach it to the hierarchy so it can process events. b) I need to implement a custom appender that process events by doing something not supported by the available appenders and I do not know how to implement it. For situation a, read the short guide previously mentioned. For situation b, identify the appender that is closest to your desired functionality and what you need it to do differently. On May 21, 2011, at 12:15 AM, niras iva wrote: Hai Am new in log4j..i dunno how to create a new Appender ..please explain me clearly -- View this message in context: http://old.nabble.com/log4j-tp31669215p31669215.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: using of system properties in subject of SMTPAppender
If it can be in the body of the email, then there are many ways that you could customize the rendering of the message. Since it appears to be a very low frequency occurrence, you could do something like: if(logger.isErrorEnabled()) { string msg = Client + clienName + encountered unexpected exception;. logger.error(msg, e); } If you really want it in the subject, you will likely need to extend SMTPAppender. You could create an object that represents the combination of the server context and the message (or just the context if you don't need the message parameter) logger.error(context, e); or if(logger.isErrorEnabled()) { logger.error(new MyCustomObject(context, msg), e); } The toString method of the first parameter will be used for the message. Your customized SMTPAppender can recognize the message parameter object and extract whatever information you need for the subject line. On May 23, 2011, at 9:18 AM, Zbynek Vavros wrote: Hi, I have a 1 server app and many clients app on different servers. Obviously I wanted to know from which server the email comes, so I used this: log4j.xml appender name=email class=org.apache.log4j.net.SMTPAppender param name=BufferSize value=512 / param name=SMTPHost value=my_smtp_host / param name=From value=AutoBot / param name=To value=my_em...@someserver.com / param name=Subject value=Agent on [${HOSTNAME}] has encountered error / layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d{HH:mm:ss} [%t] %p %C (%L) %x - %m%n / /layout filter class=org.apache.log4j.varia.LevelRangeFilter param name=LevelMin value=error / param name=LevelMax value=fatal / /filter /appender and since system property has to be setup before configuring log4j, I use this in my code. Main class //create system property to hold server name System.setProperty(HOSTNAME, InetAddress.getLocalHost ().getCanonicalHostName()); //reconfigure log4j so it picks up HOSTNAME property DOMConfigurator.configure(getClass().getClassLoader().getResource( log4j.xml)); Then Im receiving emails with subject like this: Agent on [127.0.0.1] has encountered error. So far so good. And now I have request to include customer name in subject. I have no problem to include it in stack trace, but since I cannot set customer name the same way as I did with IP (there are multiple customers handled by my app so I cannot just use System.setProperty(CUSTOMER, SOME NAME)). I though of solution to set this property when exception is catched and reconfigure log4j after setting proper customer name into system property. But I think it is politelly said ugly. Can some1 suggest a better way maybe? Thanks, Zbynek Kind Regards / Mit freundlichen Grüßen / Üdvözlettel / S pozdravem: Zbynek VAVROS (Embedded Development image moved to file: pic20342.gif) Delivery Centre 616 00, Brno Central Europe Technicka 21 Brno SITE Czech Republic (Embedded image moved to file: pic17964.gif)Phone: 420-53341- x6283 Mobile: E-mail: zbynek_vav...@cz.ibm.com IBM Global Services Delivery Center Czech Republic, s.r.o. Registered address: Brno, Technicka 2995/21, Zip code: 61600, Company ID: 26244535 Entered in the Commercial Register maintained by the Regional Court in Brno (Part C, Entry 39922) IBM Global Services Delivery Center Czech Republic, s.r.o.
Re: is it possible to have different log level for same package
Set the logger's level to the lower level and one of the appenders to a higher level. The event will get pass the check on the logger and will pass the check on one of the appenders and not the other. log4j.logger.com.foo.hello=DEBUG,FOO_1,FOO_2 log4j.appender.FOO_1.threshold=ERROR On May 17, 2011, at 10:33 AM, Nitin Kumar Gupta wrote: suppose I have a package com.foo.hello , can I define log level and appender such that error logs goes to one file and all other (even including error, if possible) goes to another file. I tried as follows, but last one is always overwriting first one log4j.logger.com.foo.hello=ERROR, FOO_1 log4j.logger.com.foo.hello=DEBUG, FOO_2 and appender as log4j.appender.FOO_1=org.apache.log4j.RollingFileAppender log4j.appender.FOO_1.File=../log/foo_error.log log4j.appender.FOO_2=org.apache.log4j.RollingFileAppender log4j.appender.FOO_2.File=../log/foo_all.log Can someone please help me on that? Thanks a ton Nitin -- View this message in context: http://old.nabble.com/is-it-possible-to-have-different-log-level-for-same-package-tp31638492p31638492.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