logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Lussmyer <John.Lussm...@efi.com>
Subject RE: Configuring Log4J without a file - FAQ needs update
Date Tue, 03 Feb 2015 18:51:47 GMT
I can have a log "file" in my resources, but I can't write it to disk anywhere for Log4J to
then read.
So this solution does work for this case.
(and even if I couldn't have a resource file, I could just build a String and use a StringInputStream.)

-----Original Message-----
From: Blaine Bergeson (bbergeson) [mailto:bbergeson@micron.com] 
Sent: Tuesday, February 03, 2015 10:47 AM
To: Log4J Users List
Subject: RE: Configuring Log4J without a file - FAQ needs update

John,

This was the solution that I came up with to be able to load a configuration file that was
not on the class path.  I have since had to update the code to work correctly with a NetBeans
RCP application.  If I understand you correctly this solution will not work for you because
you don't want a configuration file at all while I did want a configuration file but I wanted
the file hidden within the project and not modified afterwards.

Blaine

-----Original Message-----
From: John Lussmyer [mailto:John.Lussmyer@efi.com] 
Sent: Tuesday, February 03, 2015 10:47 AM
To: log4j-user@logging.apache.org
Subject: Configuring Log4J without a file - FAQ needs update

I have a situation where I can't have a configuration file, so I want to configure Log4J programmatically.
The FAQ on this "How do I configure log4j2 in code without a configuration file?<http://logging.apache.org/log4j/2.x/faq.html#config_from_code>"
is rather unclear, as it suggests using a method that takes a file name.
Shouldn't it suggest the one that takes a ConfigurationSource?

I recently found this:
        InputStream is = MyLogFactory.class.getResourceAsStream("log4j2.xml");
        ConfigurationSource source = new ConfigurationSource(is);
        Configurator.initialize(MyLogFactory.class.getClassLoader(), source);

Is this the proper technique to use in this case?


________________________________
Confidentiality notice: This message may contain confidential information. It is intended
only for the person to whom it is addressed. If you are not that person, you should not use
this message. We request that you notify us by replying to this message, and then delete all
copies including any contained in your reply. Thank you.

---------------------------------------------------------------------
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


Mime
View raw message