Return-Path: X-Original-To: apmail-logging-log4j-dev-archive@www.apache.org Delivered-To: apmail-logging-log4j-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 57D47183FC for ; Mon, 24 Aug 2015 06:40:46 +0000 (UTC) Received: (qmail 88766 invoked by uid 500); 24 Aug 2015 06:40:46 -0000 Delivered-To: apmail-logging-log4j-dev-archive@logging.apache.org Received: (qmail 88712 invoked by uid 500); 24 Aug 2015 06:40:46 -0000 Mailing-List: contact log4j-dev-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Developers List" Reply-To: "Log4J Developers List" Delivered-To: mailing list log4j-dev@logging.apache.org Received: (qmail 88702 invoked by uid 99); 24 Aug 2015 06:40:46 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Aug 2015 06:40:46 +0000 Date: Mon, 24 Aug 2015 06:40:46 +0000 (UTC) From: "Ralph Goers (JIRA)" To: log4j-dev@logging.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (LOG4J2-952) FAQ: How do I configure log4j2 programmatically in code without a configuration file? MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/LOG4J2-952?page=3Dcom.atlassian= .jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D1470= 8864#comment-14708864 ]=20 Ralph Goers commented on LOG4J2-952: ------------------------------------ No, it is not in a branch. You should be able to apply the patch to master.= Note though that one of the unit test that was recently added is failing e= ven before applying the patch. > FAQ: How do I configure log4j2 programmatically in code without a configu= ration file? > -------------------------------------------------------------------------= ------------ > > Key: LOG4J2-952 > URL: https://issues.apache.org/jira/browse/LOG4J2-952 > Project: Log4j 2 > Issue Type: Bug > Components: API, Configurators, Documentation > Affects Versions: 2.1 > Reporter: Joe Merten > Attachments: LOG4J2-952.patch > > > I found [this link|http://logging.apache.org/log4j/2.x/faq.html#config_fr= om_code] which said: > {quote} > You could use the static method #initialize(String contextName, ClassLoad= er loader, String configLocation) in org.apache.logging.log4j.core.config.C= onfigurator. (You can pass null for the class loader.) Be aware that this c= lass is not part of the public API so your code may break with any minor re= lease. > {quote} > This documentation is unclear because it points to a member function whic= h needs a filename {{configLocation}} where as the topic is =C2=BBwithout a= configuration file=C2=AB. > It shoud rather point to the member function {{org.apache.logging.log4j.c= ore.config.Configurator.initialize(ClassLoader loader, ConfigurationSource = source)}}. > Example: > {code:java} > import org.apache.logging.log4j.core.config.ConfigurationSource; > import org.apache.logging.log4j.core.config.Configurator; > final String hardCodedXmlConfig =3D > "\n" + > "\n" + > " \n" + > " \n" + > " \n" + > " \n" + > " \n" + > " \n" + > " \n" + > " \n" + > " \n" + > " \n" + > "\n"; > try { > Configurator.initialize(null, new ConfigurationSource(new ByteArrayIn= putStream(hardCodedXmlConfig.getBytes()))); > } catch (IOException e) { > e.printStackTrace(); > } > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org For additional commands, e-mail: log4j-dev-help@logging.apache.org