You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by zafer aydin <za...@hotmail.com> on 2014/05/13 07:20:34 UTC

how to set log4j2 xml config location

Hello,
In my Java application, I created an xml configuration file named "log4j2.xml" and put it under "Default Package". It works as expected.Now I want to change this location but I can't not do it. It seems that in previous version (log4j) it was possible to set xml config file location by "DOMConfigurator.configure" but with "log4j2" I cannot find similar function.How can I set the xml config file location in log4j2?
Thanks.

Zafer AYDIN 		 	   		  

Re: how to set log4j2 xml config location

Posted by Remko Popma <re...@gmail.com>.
Take a look here:
http://logging.apache.org/log4j/2.x/faq.html#config_location


On Tue, May 13, 2014 at 2:20 PM, zafer aydin <za...@hotmail.com> wrote:

> Hello,
> In my Java application, I created an xml configuration file named
> "log4j2.xml" and put it under "Default Package". It works as expected.Now I
> want to change this location but I can't not do it. It seems that in
> previous version (log4j) it was possible to set xml config file location by
> "DOMConfigurator.configure" but with "log4j2" I cannot find similar
> function.How can I set the xml config file location in log4j2?
> Thanks.
>
> Zafer AYDIN

Re: how to set log4j2 xml config location

Posted by Ralph Goers <ra...@dslextreme.com>.
While this works it would be better to use the Configurator class such as

Configurator.intitalize(“MyContextName”, “myLog4j2.xml”);

or 

final ConfigurationFactory.ConfigurationSource source = new ConfigurationFactory.ConfigurationSource(new ByteArrayInputStream(config.getBytes("UTF-8")));
Configurator.initalize(null, source);

Ralph


On May 13, 2014, at 1:15 AM, Luigi Alice <Lu...@persis.de> wrote:

> Load the file via InputStream:
> 
>                    final ConfigurationFactory.ConfigurationSource source = new ConfigurationFactory.ConfigurationSource(new ByteArrayInputStream(config.getBytes("UTF-8")));
>                    XMLConfiguration cfg = new XMLConfiguration(source);
>                    Logger l = (Logger) LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);
>                    l.getContext().start(cfg);  
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: zafer aydin [mailto:zaferaydn@hotmail.com] 
> Gesendet: Dienstag, 13. Mai 2014 07:21
> An: log4j-user@logging.apache.org
> Betreff: how to set log4j2 xml config location
> 
> Hello,
> In my Java application, I created an xml configuration file named "log4j2.xml" and put it under "Default Package". It works as expected.Now I want to change this location but I can't not do it. It seems that in previous version (log4j) it was possible to set xml config file location by "DOMConfigurator.configure" but with "log4j2" I cannot find similar function.How can I set the xml config file location in log4j2?
> Thanks.
> 
> Zafer AYDIN 		 	   		  
> 
> ---------------------------------------------------------------------
> 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


RE: AW: AW: how to set log4j2 xml config location

Posted by zafer aydin <za...@hotmail.com>.
It works,Thank you.

Zafer AYDIN

> From: Luigi.Alice@persis.de
> To: log4j-user@logging.apache.org
> Subject: AW: AW: how to set log4j2 xml config location
> Date: Tue, 13 May 2014 11:47:31 +0000
> 
> Yes, it has.
> 
> Class: 
> org.apache.logging.log4j.core.Logger
> 
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: zafer aydin [mailto:zaferaydn@hotmail.com] 
> Gesendet: Dienstag, 13. Mai 2014 13:36
> An: Log4J Users List
> Betreff: RE: AW: how to set log4j2 xml config location
> 
> Hello Luigi,
> There is a problem at this line: l.getContext().start(cfg);Logger cannot contain any method named getContext.  What can we use insead?
> 
> Zafer AYDIN
> 
> > From: Luigi.Alice@persis.de
> > To: log4j-user@logging.apache.org
> > Subject: AW: how to set log4j2 xml config location
> > Date: Tue, 13 May 2014 08:15:20 +0000
> > 
> > Load the file via InputStream:
> > 
> >                     final ConfigurationFactory.ConfigurationSource source = new ConfigurationFactory.ConfigurationSource(new ByteArrayInputStream(config.getBytes("UTF-8")));
> >                     XMLConfiguration cfg = new XMLConfiguration(source);
> >                     Logger l = (Logger) LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);
> >                     l.getContext().start(cfg);  
> > 
> > 
> > -----Ursprüngliche Nachricht-----
> > Von: zafer aydin [mailto:zaferaydn@hotmail.com] 
> > Gesendet: Dienstag, 13. Mai 2014 07:21
> > An: log4j-user@logging.apache.org
> > Betreff: how to set log4j2 xml config location
> > 
> > Hello,
> > In my Java application, I created an xml configuration file named "log4j2.xml" and put it under "Default Package". It works as expected.Now I want to change this location but I can't not do it. It seems that in previous version (log4j) it was possible to set xml config file location by "DOMConfigurator.configure" but with "log4j2" I cannot find similar function.How can I set the xml config file location in log4j2?
> > Thanks.
> > 
> > Zafer AYDIN 		 	   		  
> > 
> > ---------------------------------------------------------------------
> > 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
> 
 		 	   		  

AW: AW: how to set log4j2 xml config location

Posted by Luigi Alice <Lu...@persis.de>.
Yes, it has.

Class: 
org.apache.logging.log4j.core.Logger



-----Ursprüngliche Nachricht-----
Von: zafer aydin [mailto:zaferaydn@hotmail.com] 
Gesendet: Dienstag, 13. Mai 2014 13:36
An: Log4J Users List
Betreff: RE: AW: how to set log4j2 xml config location

Hello Luigi,
There is a problem at this line: l.getContext().start(cfg);Logger cannot contain any method named getContext.  What can we use insead?

Zafer AYDIN

> From: Luigi.Alice@persis.de
> To: log4j-user@logging.apache.org
> Subject: AW: how to set log4j2 xml config location
> Date: Tue, 13 May 2014 08:15:20 +0000
> 
> Load the file via InputStream:
> 
>                     final ConfigurationFactory.ConfigurationSource source = new ConfigurationFactory.ConfigurationSource(new ByteArrayInputStream(config.getBytes("UTF-8")));
>                     XMLConfiguration cfg = new XMLConfiguration(source);
>                     Logger l = (Logger) LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);
>                     l.getContext().start(cfg);  
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: zafer aydin [mailto:zaferaydn@hotmail.com] 
> Gesendet: Dienstag, 13. Mai 2014 07:21
> An: log4j-user@logging.apache.org
> Betreff: how to set log4j2 xml config location
> 
> Hello,
> In my Java application, I created an xml configuration file named "log4j2.xml" and put it under "Default Package". It works as expected.Now I want to change this location but I can't not do it. It seems that in previous version (log4j) it was possible to set xml config file location by "DOMConfigurator.configure" but with "log4j2" I cannot find similar function.How can I set the xml config file location in log4j2?
> Thanks.
> 
> Zafer AYDIN 		 	   		  
> 
> ---------------------------------------------------------------------
> 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


RE: AW: how to set log4j2 xml config location

Posted by zafer aydin <za...@hotmail.com>.
Hello Luigi,
There is a problem at this line: l.getContext().start(cfg);Logger cannot contain any method named getContext.  What can we use insead?

Zafer AYDIN

> From: Luigi.Alice@persis.de
> To: log4j-user@logging.apache.org
> Subject: AW: how to set log4j2 xml config location
> Date: Tue, 13 May 2014 08:15:20 +0000
> 
> Load the file via InputStream:
> 
>                     final ConfigurationFactory.ConfigurationSource source = new ConfigurationFactory.ConfigurationSource(new ByteArrayInputStream(config.getBytes("UTF-8")));
>                     XMLConfiguration cfg = new XMLConfiguration(source);
>                     Logger l = (Logger) LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);
>                     l.getContext().start(cfg);  
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: zafer aydin [mailto:zaferaydn@hotmail.com] 
> Gesendet: Dienstag, 13. Mai 2014 07:21
> An: log4j-user@logging.apache.org
> Betreff: how to set log4j2 xml config location
> 
> Hello,
> In my Java application, I created an xml configuration file named "log4j2.xml" and put it under "Default Package". It works as expected.Now I want to change this location but I can't not do it. It seems that in previous version (log4j) it was possible to set xml config file location by "DOMConfigurator.configure" but with "log4j2" I cannot find similar function.How can I set the xml config file location in log4j2?
> Thanks.
> 
> Zafer AYDIN 		 	   		  
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
 		 	   		  

Re: how to set log4j2 xml config location

Posted by Gary Gregory <ga...@gmail.com>.
Minor improvement: you can replace:

LogManager.getLogger(LogManager.ROOT_LOGGER_NAME)

with:

LogManager.getRootLogger()

Gary



On Tue, May 13, 2014 at 4:15 AM, Luigi Alice <Lu...@persis.de> wrote:

> Load the file via InputStream:
>
>                     final ConfigurationFactory.ConfigurationSource source
> = new ConfigurationFactory.ConfigurationSource(new
> ByteArrayInputStream(config.getBytes("UTF-8")));
>                     XMLConfiguration cfg = new XMLConfiguration(source);
>                     Logger l = (Logger)
> LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);
>                     l.getContext().start(cfg);
>
>
> -----Ursprüngliche Nachricht-----
> Von: zafer aydin [mailto:zaferaydn@hotmail.com]
> Gesendet: Dienstag, 13. Mai 2014 07:21
> An: log4j-user@logging.apache.org
> Betreff: how to set log4j2 xml config location
>
> Hello,
> In my Java application, I created an xml configuration file named
> "log4j2.xml" and put it under "Default Package". It works as expected.Now I
> want to change this location but I can't not do it. It seems that in
> previous version (log4j) it was possible to set xml config file location by
> "DOMConfigurator.configure" but with "log4j2" I cannot find similar
> function.How can I set the xml config file location in log4j2?
> Thanks.
>
> Zafer AYDIN
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

AW: how to set log4j2 xml config location

Posted by Luigi Alice <Lu...@persis.de>.
Load the file via InputStream:

                    final ConfigurationFactory.ConfigurationSource source = new ConfigurationFactory.ConfigurationSource(new ByteArrayInputStream(config.getBytes("UTF-8")));
                    XMLConfiguration cfg = new XMLConfiguration(source);
                    Logger l = (Logger) LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);
                    l.getContext().start(cfg);  


-----Ursprüngliche Nachricht-----
Von: zafer aydin [mailto:zaferaydn@hotmail.com] 
Gesendet: Dienstag, 13. Mai 2014 07:21
An: log4j-user@logging.apache.org
Betreff: how to set log4j2 xml config location

Hello,
In my Java application, I created an xml configuration file named "log4j2.xml" and put it under "Default Package". It works as expected.Now I want to change this location but I can't not do it. It seems that in previous version (log4j) it was possible to set xml config file location by "DOMConfigurator.configure" but with "log4j2" I cannot find similar function.How can I set the xml config file location in log4j2?
Thanks.

Zafer AYDIN 		 	   		  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org