[logback-user] Project Can't Find logback.xml file

Roger Spears rspears at northweststate.edu
Fri Jan 20 18:42:59 CET 2012


Hello,

Thank you for your suggestion of add the ClassLoader.  I don't know why 
I didn't think of that.  Maybe it's because I'm fairly new to Java.

I added the following two lines to my HelloWorld.java class:

     String URL = "logback.xml";
     System.out.println(ClassLoader.getSystemResource(URL));

The output I receive on the console looks like this:

file:/Users/roger/NetBeansProjects/HelloWorld/build/classes/logback.xml
12:30:01.762 [main] DEBUG helloworld - Hello world.

When I open the logback.xml file that is listed in the console output, 
it looks exactly like the custom logback.xml file I created.

The problem still exists that it's not picking up on the custom pattern 
I have in logback.xml.  That pattern looks like this:

<pattern>%date %n [%thread] %level %logger{35} - %n %msg</pattern>


I would have expected to see the date followed by a jump down to a new 
line followed by [main] followed by a jump down to a new line and etc. 
etc etc.

Am I wrong to think logback uses %n as new line characters?

My experience has been with log4j and %n generates the newline in its 
pattern.

Thanks again,
Rogert

> Adam Gordon <mailto:adam.n.gordon at gmail.com>
> January 20, 2012 12:13 PM
> The XML file needs to be in your class path. The first thing I would 
> check is to see if you can load the file as a resource with 
> ClassLoader.getResourceAsStream(String) or similar. If this is able to 
> load the file, then it's on your class path and I'm not sure what the 
> problem is but it's something to eliminate as an issue first.
>
> In my maven project, I have it in src/main/resources and everything is 
> happy.
>
>
>
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user
> Roger Spears <mailto:rspears at northweststate.edu>
> January 20, 2012 12:07 PM
> Hello,
>
> I'm running Netbeans 7.0.1 on a Mac Book Pro with OS Lion.  I'm 
> currently using log4j without any problems.  I wanted to try out logback.
>
> Yesterday I downloaded logback and placed the 4 jar files in the 
> proper location.  I'm able to run the basic logback HelloWorld 
> example.  Here's the code for the HelloWorld example I'm working with:
>
> package helloworld;
>
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> public class HelloWorld {
>
>   public static void main(String[] args) {
>
>     Logger logger = LoggerFactory.getLogger("helloworld");
>     logger.debug("Hello world.");
>
>   }
>
> }
>
> Here's my customized logback.xml file:
>
> <configuration>
> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
> <encoder>
> <pattern>%date %n [%thread] %level %logger{35} - %n %msg</pattern>
> </encoder>
> </appender>
> <root level="DEBUG">
> <appender-ref ref="STDOUT" />
> </root>
> </configuration>
>
> The problem is...Netbeans (or java) never picks up on my customized 
> logback.xml file.  I'm starting out easy by just changing the pattern 
> to see if I can get it to work.  When I run the project, I see the 
> following on the console:
>
> 11:56:33.569 [main] DEBUG helloworld - Hello world.
>
> That's not the pattern I specified in logback.xml.
>
> I'm assuming I just don't have it in the proper location.  I have a 
> copy of logback.xml in the following locations just to see if I had it 
> in the wrong place:
>
> NetBeansProjects -> HelloWorld -> src -> logback.xml
>
> NetBeansProjects -> HelloWorld -> logback.xml
>
> NetBeansProjects -> HelloWorld -> nbproject -> private -> logback.xml
>
> NetBeansProjects -> HelloWorld -> build -> classes -> logback.xml
>
> System -> Libraries -> Java -> Extensions -> logback.xml
>
>
> I am still unable to get the pattern I'm looking for.
>
> Does anyone know why this would be happening?
>
> Thanks,
> Roger
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20120120/959d0772/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: postbox-contact.jpg
Type: image/jpeg
Size: 1251 bytes
Desc: not available
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20120120/959d0772/attachment-0002.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: compose-unknown-contact.jpg
Type: image/jpeg
Size: 770 bytes
Desc: not available
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20120120/959d0772/attachment-0003.jpg>


More information about the Logback-user mailing list