Return-Path: X-Original-To: apmail-logging-log4j-user-archive@www.apache.org Delivered-To: apmail-logging-log4j-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A369911DF6 for ; Mon, 11 Aug 2014 08:11:36 +0000 (UTC) Received: (qmail 28457 invoked by uid 500); 11 Aug 2014 08:11:36 -0000 Delivered-To: apmail-logging-log4j-user-archive@logging.apache.org Received: (qmail 28416 invoked by uid 500); 11 Aug 2014 08:11:35 -0000 Mailing-List: contact log4j-user-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Users List" Reply-To: "Log4J Users List" Delivered-To: mailing list log4j-user@logging.apache.org Received: (qmail 28405 invoked by uid 99); 11 Aug 2014 08:11:35 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Aug 2014 08:11:35 +0000 X-ASF-Spam-Status: No, hits=-2.8 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_HI,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [160.83.44.129] (HELO loninmrp13.uk.db.com) (160.83.44.129) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Aug 2014 08:11:31 +0000 Received: from sdbo1103.uk.db.com (LONINMTP1103.uk.db.com [10.240.132.12]) by loninmrp13.uk.db.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.2.2) with ESMTP id s7B8B8m9008963 for ; Mon, 11 Aug 2014 08:11:08 GMT In-Reply-To: References: <4F7213B6-973F-42C3-BE7B-77E63C7FB08C@dslextreme.com> <2FE0E8D8-FF45-4D00-9CF7-C4CFB5686D2A@apache.org> <9AAD09D1-10A3-46F6-AC93-EEA6FD91CF45@dslextreme.com> To: "Log4J Users List" MIME-Version: 1.0 Subject: Re: how to change logging level for a class at runtime [I] X-KeepSent: 1D4D3D8C:64173004-80257D31:002648D5; type=4; name=$KeepSent X-Mailer: Lotus Notes Release 8.5.3 September 15, 2011 From: Phil Wray Message-ID: Date: Mon, 11 Aug 2014 09:11:04 +0100 X-MIMETrack: Serialize by Router on sdbo1103/DMGUK/DeuBaInt/DeuBa(Release 8.0.2 FP2 HF135|October 22, 2009) at 11/08/2014 09:11:08, Serialize complete at 11/08/2014 09:11:08 Content-Type: multipart/alternative; boundary="=_alternative 002CF5C880257D31_=" X-Virus-Checked: Checked by ClamAV on apache.org --=_alternative 002CF5C880257D31_= Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable Classification: For internal use only LoggerConfigAdmin mbean instances only exist for explicitly configured=20 loggers - so you can only change the level for loggers originally defined=20 in your config file - not for an arbitrary class or package - which I've=20 found a useful feature. I've updated the jira with a patch file and 2 new classes -=20 LoggerLevelAdmin and LoggerLevelAdminMBean. Server changed to register a single LoggerLevelAdmin mbean that allows you= =20 to dynamically change level for any logger - creating a new loggerConfig=20 item if necessary. If someone could take a look at them would be great. thanks, Phil Phil Wray Developer Deutsche Bank AG, Filiale London Global Technology 20 Finsbury Circus, EC2M 1NB London, United Kingdom Tel. +44(20)7547 4918 Mobile +44 (0)7815 780246 Email phil.wray@db.com From: Matt Sicker To: Log4J Users List ,=20 Date: 09/08/2014 02:35 Subject: Re: how to change logging level for a class at runtime [I] Is this not what you're looking for? http://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/l= og4j/core/jmx/LoggerConfigAdminMBean.html On 6 August 2014 22:44, Matt Sicker wrote: > I may take a look at this soon as I've been getting into JMX lately at > work in order to automate some build/deployment infrastructure. It's=20 still > fresh ;) > > > On 6 August 2014 17:42, Ralph Goers wrote: > >> I wouldn?t have asked for a patch submission if I didn?t plan to=20 consider >> it. That said, we are all volunteers here and sometimes don?t get to=20 things >> as quickly as we would like. >> >> Ralph >> >> On Aug 6, 2014, at 1:24 PM, Ang Xu wrote: >> >> > Hi, >> > >> > Is there any plan to merge this patch to the main branch? This >> > functionality seems extremely useful when modifying config file is=20 not >> an >> > option. >> > >> > Thanks, >> > Ang >> > >> > On 6/25/14, 12:19 AM, "Phil Wray" wrote: >> > >> >> Classification: For internal use only >> >> >> >> Hey Ralph. >> >> Sure - have created: >> >> LOG4J2-681 Add ability to change log level for any class/package >> >> dynamically via jmx >> >> >> >> cheers, >> >> Phil >> >> >> >> >> >> >> >> >> >> >> >> From: >> >> Ralph Goers >> >> To: >> >> Log4J Users List , >> >> Date: >> >> 24/06/2014 15:34 >> >> Subject: >> >> Re: how to change logging level for a class at runtime >> >> >> >> >> >> >> >> Phil, >> >> >> >> That looks pretty good. It would be great if you could create a=20 Jira >> >> issue and add that as a patch >> >> >> >> Sent from my iPad >> >> >> >>> On Jun 24, 2014, at 7:01 AM, Phil Wray wrote: >> >>> >> >>> Classification: Public >> >>> >> >>> Hi Ralph, >> >>> Just to confirm running latest trunk version its possible to change >> >> levels >> >>> at runtime using code as per your docs. >> >>> Thanks for the help. >> >>> I see a tag for 2.0-rc2 was taken a couple of days ago - I'm=20 guessing >> >> this >> >>> is being released imminently? >> >>> >> >>> In case it helps others I ended up with the following util to let=20 us >> >>> change levels via jmx, just using whatever existing appender the >> logger >> >>> would have had. >> >>> >> >>> @ManagedOperation >> >>> public String changeLogLevel(String loggerName, String=20 level){ >> >>> Level newLevel =3D Level.toLevel(level); >> >>> LoggerContext ctx =3D (LoggerContext) >> >> LogManager.getContext( >> >>> false); >> >>> Configuration config =3D ctx.getConfiguration(); >> >>> LoggerConfig loggerConfig =3D >> >>> config.getLoggerConfig(loggerName); >> >>> String msg; >> >>> >> >>> if (loggerName.equals(loggerConfig.getName())){ >> >>> Level oldLevel =3D loggerConfig.getLevel(); >> >>> loggerConfig.setLevel(newLevel); >> >>> msg =3D String.format("Modified existing logge= r=20 %s >> >>> level from %s to %s", loggerName, oldLevel, newLevel); >> >>> } else { >> >>> createCopyFrom(loggerConfig, loggerName, >> >> newLevel, >> >>> config); >> >>> msg =3D String.format("Added new logger %s with >> >>> level %s previously used logger %s with level %s", loggerName, >> >>> newLevel, >> >> >> >>> loggerConfig.getName(), loggerConfig.getLevel()); >> >>> } >> >>> ctx.updateLoggers(); >> >>> LOG.info(msg); >> >>> return msg; >> >>> } >> >>> >> >>> private void createCopyFrom(LoggerConfig original, String=20 name, >> >>> Level level, Configuration config){ >> >>> AppenderRef[] refs =3D=20 original.getAppenderRefs().toArray( >> >>> new AppenderRef[]{}); >> >>> Filter filter =3D original.getFilter(); >> >>> LoggerConfig copy =3D LoggerConfig.createLogger( >> >>> "false", >> >>> level, >> >>> name, >> >>> Boolean.toString >> >>> (original.isIncludeLocation()), >> >>> refs, null, config, filter); >> >>> >> >>> for (Appender appender : >> >>> original.getAppenders().values()){ >> >>> copy.addAppender(appender, null, null); >> >>> } >> >>> config.addLogger(name, copy); >> >>> } >> >>> >> >>> cheers, >> >>> Phil >> >>> >> >>> >> >>> >> >>> >> >>> From: >> >>> Phil Wray/ext/dbcom >> >>> To: >> >>> "Log4J Users List" , >> >>> Date: >> >>> 24/06/2014 11:16 >> >>> Subject: >> >>> Re: how to change logging level for a class at runtime >> >>> >> >>> >> >>> Classification: Public >> >>> >> >>> Hi Ralph, >> >>> Sorry hadn't looked at the latest source - see you've made changes= =20 to >> >>> Configuration to allow adding of LoggerConfig via the interface=20 that >> >>> are >> >> >> >>> not yet in the release candidate jar. >> >>> I'll take the latest source and build from that. >> >>> >> >>> >> >>> thanks, >> >>> Phil >> >>> >> >>> >> >>> >> >>> >> >>> >> >>> >> >>> From: >> >>> Phil Wray/ext/dbcom >> >>> To: >> >>> "Log4J Users List" , >> >>> Date: >> >>> 24/06/2014 09:07 >> >>> Subject: >> >>> Re: how to change logging level for a class at runtime >> >>> >> >>> >> >>> Classification: Public >> >>> >> >>> Hi Ralph, >> >>> Thanks for getting back, but the examples do not show how to change >> >> levels >> >>> at runtime, >> >>> >> >>> There is no method addLogger(String, LoggerConfig) method on the >> >>> Configuration interface. >> >>> The addLogger method exists on BaseConfiguration, however it throws= =20 an >> >>> IllegalStateException as its already started, and says you have to >> >> create >> >>> a new configuration. >> >>> >> >>> Is it actually possible to change the logging level for a >> class/package >> >> at >> >>> runtime after startup? >> >>> I think this is a common use case for troubleshooting critical long >> >>> running processes. >> >>> >> >>> >> >>> thanks, >> >>> Phil >> >>> >> >>> >> >>> >> >>> >> >>> >> >>> >> >>> >> >>> From: >> >>> Ralph Goers >> >>> To: >> >>> Log4J Users List , >> >>> Date: >> >>> 23/06/2014 15:57 >> >>> Subject: >> >>> Re: how to change logging level for a class at runtime >> >>> >> >>> >> >>> >> >>> Please see >> >>> http://people.apache.org/~rgoers/log4j2/manual/customconfig.html >> >>> >> >>> Ralph >> >>> >> >>>> On Jun 23, 2014, at 3:44 AM, Phil Wray wrote: >> >>>> >> >>>> Classification: Public >> >>>> >> >>>> Hi, >> >>>> Would like to turn on debug for a particular class or package at >> >>> runtime, >> >>>> either via jmx or programmatically, where this class or package is >> >>>> arbitrary and not known at start up time please. >> >>>> I can't see a way to do this? >> >>>> Previous posts titled "Programmatic configuration of loggers" show >> how >> >>> to >> >>>> do this for an existing named logger but not for an arbitrary=20 class >> or >> >>>> package which is a typical use case. >> >>>> LoggerConfig loggerConfig =3D config.getLoggerConfig(loggerName); >> >>>> >> >>>> But this returns the root logger if no existing logger for that=20 name >> >>>> exists - and we can't just enable debug on everything. >> >>>> Is there a way of adding a new LoggerConfig into the=20 configuration? >> >>>> >> >>>> thanks, >> >>>> Phil Wray >> >>>> >> >>>> >> >>>> >> >>>> >> >>>> --- >> >>>> >> >>>> This e-mail may contain confidential and/or privileged=20 information. >> If >> >>> you are not the intended recipient (or have received this e-mail in >> >> error) >> >>> please notify the sender immediately and delete this e-mail. Any >> >>> unauthorized copying, disclosure or distribution of the material in >> >>> this >> >> >> >>> e-mail is strictly forbidden. >> >>>> >> >>>> Please refer to http://www.db.com/en/content/eu_disclosures.htm=20 for >> >>> additional EU corporate and regulatory disclosures and to >> >>> http://www.db.com/unitedkingdom/content/privacy.htm for information >> >> about >> >>> privacy. >> >>> >> >>> >> >>> >> >>> >> >>> >> >>> >> >>> >> >>> >> >>> >> >>> --- >> >>> >> >>> This e-mail may contain confidential and/or privileged information.= =20 If >> >> you are not the intended recipient (or have received this e-mail in >> >> error) >> >> please notify the sender immediately and delete this e-mail. Any >> >> unauthorized copying, disclosure or distribution of the material in >> this >> >> e-mail is strictly forbidden. >> >>> >> >>> Please refer to http://www.db.com/en/content/eu_disclosures.htm for >> >> additional EU corporate and regulatory disclosures and to >> >> http://www.db.com/unitedkingdom/content/privacy.htm for information >> about >> >> privacy. >> >> >> >>=20 --------------------------------------------------------------------- >> >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org >> >> For additional commands, e-mail: log4j-user-help@logging.apache.org >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> --- >> >> >> >> This e-mail may contain confidential and/or privileged information.=20 If >> >> you are not the intended recipient (or have received this e-mail in >> >> error) please notify the sender immediately and delete this e-mail.=20 Any >> >> unauthorized copying, disclosure or distribution of the material in >> this >> >> e-mail is strictly forbidden. >> >> >> >> Please refer to http://www.db.com/en/content/eu_disclosures.htm for >> >> additional EU corporate and regulatory disclosures and to >> >> http://www.db.com/unitedkingdom/content/privacy.htm for information >> about >> >> privacy. >> > >> > >> > --------------------------------------------------------------------- >> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org >> > For additional commands, e-mail: log4j-user-help@logging.apache.org >> > >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org >> For additional commands, e-mail: log4j-user-help@logging.apache.org >> >> > > > -- > Matt Sicker > --=20 Matt Sicker --- This e-mail may contain confidential and/or privileged information. If you = are not the intended recipient (or have received this e-mail in error) plea= se notify the sender immediately and delete this e-mail. Any unauthorized c= opying, disclosure or distribution of the material in this e-mail is strict= ly forbidden. Please refer to http://www.db.com/en/content/eu_disclosures.htm for additio= nal EU corporate and regulatory disclosures and to http://www.db.com/united= kingdom/content/privacy.htm for information about privacy. --=_alternative 002CF5C880257D31_=--