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 Alex Colic <ac...@yahoo.com> on 2000/12/29 15:48:36 UTC

Trying to figure out how to get Log4J to work with Properties

Hi,

I am trying to figure out how to get Log4J to work with a properties file which I have created and
I am having a bit of a problem. I think I have done everything correctly but Log4J can't find my
properties file. I have created a class called Test with the following code in the Main:

  PropertyConfigurator.configure("LogSetting");
  Category cat=Category.getInstance("test");
  cat.info("Info Entry");
  cat.warn("Warn entry");
  cat.error("Error entry");
  cat.debug("Debug entry");

I have also created a properties file called "LogSetting.properties" and placed it with the test
class file. I have checked and this is on my class path. The properties file consists of:

log4j.configDebug=true
log4j.appender.A1=org.log4j.FileAppender
log4j.appender.A1.File=System.out

log4j.rootCategory=DEBUG, A1

log4j.appender.A1.layout=org.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x-%m%n


When I run my test program I get the following error:


log4j: Could not read configuration file [LogSetting].
java.io.FileNotFoundException: LogSetting (The system cannot find the file specified)

Any ideas or help in getting this to work will be greatly appreciated.

Alex



__________________________________________________
Do You Yahoo!?
Yahoo! Photos - Share your holiday photos online!
http://photos.yahoo.com/

RE: Trying to figure out how to get Log4J to work with Properties

Posted by Ceki Gulcu <cg...@urbanet.ch>.
Keith,

You might want to try Class.getResource instead of ResourceBundle. Regards, 
Ceki

At 10:43 29.12.2000 -0500, Keith R. Bennett wrote:
>Alex -
>
>I don't know if this will address your problem, but...
>
>I have a method that takes a ResourceBundle and returns a Properties object:
>
>     static public Properties getPropertiesFromResourceBundle(
>             ResourceBundle bundle)
>     {
>         Properties props = new Properties();
>
>         Enumeration keys = bundle.getKeys();
>
>         while( keys.hasMoreElements()) {
>             String key = (String) keys.nextElement();
>             String val = bundle.getString( key);
>             props.setProperty( key, val);
>         }
>
>         return props;
>     }
>
>
>Then I call it something like this:
>
>ResourceBundle logProps = ResourceBundle.getBundle( "com.fgm.TrackerRes");
>Properties props = AggregationUtils.getPropertiesFromResourceBundle(
>logProps);
>PropertyConfigurator.configure( props);
>
>I think I went to that trouble because I wanted to take advantage of
>ResourceBundle.getBundle()'s automatic scanning of the classpath for the
>file, and its locale functionality.
>
>I may be exposing a major misunderstanding on my part of how log4j works.  I
>welcome any comments on the above.
>
>- Keith Bennett
>
>
>
> > -----Original Message-----
> > From: Alex Colic [mailto:acolic@yahoo.com]
> > Sent: Friday, December 29, 2000 9:49 AM
> > To: log4j-user@jakarta.apache.org
> > Subject: Trying to figure out how to get Log4J to work with Properties
> >
> >
> > Hi,
> >
> > I am trying to figure out how to get Log4J to work with a
> > properties file which I have created and
> > I am having a bit of a problem. I think I have done everything
> > correctly but Log4J can't find my
> > properties file. I have created a class called Test with the
> > following code in the Main:
> >
> >   PropertyConfigurator.configure("LogSetting");
> >   Category cat=Category.getInstance("test");
> >   cat.info("Info Entry");
> >   cat.warn("Warn entry");
> >   cat.error("Error entry");
> >   cat.debug("Debug entry");
> >
> > I have also created a properties file called
> > "LogSetting.properties" and placed it with the test
> > class file. I have checked and this is on my class path. The
> > properties file consists of:
> >
> > log4j.configDebug=true
> > log4j.appender.A1=org.log4j.FileAppender
> > log4j.appender.A1.File=System.out
> >
> > log4j.rootCategory=DEBUG, A1
> >
> > log4j.appender.A1.layout=org.log4j.PatternLayout
> > log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x-%m%n
> >
> >
> > When I run my test program I get the following error:
> >
> >
> > log4j: Could not read configuration file [LogSetting].
> > java.io.FileNotFoundException: LogSetting (The system cannot find
> > the file specified)
> >
> > Any ideas or help in getting this to work will be greatly appreciated.
> >
> > Alex
> >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Yahoo! Photos - Share your holiday photos online!
> > http://photos.yahoo.com/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: log4j-user-help@jakarta.apache.org
> >
> >
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-user-help@jakarta.apache.org


RE: Trying to figure out how to get Log4J to work with Properties

Posted by "Keith R. Bennett" <ke...@fgm.com>.
Alex -

I don't know if this will address your problem, but...

I have a method that takes a ResourceBundle and returns a Properties object:

    static public Properties getPropertiesFromResourceBundle(
            ResourceBundle bundle)
    {
        Properties props = new Properties();

        Enumeration keys = bundle.getKeys();

        while( keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            String val = bundle.getString( key);
            props.setProperty( key, val);
        }

        return props;
    }


Then I call it something like this:

ResourceBundle logProps = ResourceBundle.getBundle( "com.fgm.TrackerRes");
Properties props = AggregationUtils.getPropertiesFromResourceBundle(
logProps);
PropertyConfigurator.configure( props);

I think I went to that trouble because I wanted to take advantage of
ResourceBundle.getBundle()'s automatic scanning of the classpath for the
file, and its locale functionality.

I may be exposing a major misunderstanding on my part of how log4j works.  I
welcome any comments on the above.

- Keith Bennett



> -----Original Message-----
> From: Alex Colic [mailto:acolic@yahoo.com]
> Sent: Friday, December 29, 2000 9:49 AM
> To: log4j-user@jakarta.apache.org
> Subject: Trying to figure out how to get Log4J to work with Properties
>
>
> Hi,
>
> I am trying to figure out how to get Log4J to work with a
> properties file which I have created and
> I am having a bit of a problem. I think I have done everything
> correctly but Log4J can't find my
> properties file. I have created a class called Test with the
> following code in the Main:
>
>   PropertyConfigurator.configure("LogSetting");
>   Category cat=Category.getInstance("test");
>   cat.info("Info Entry");
>   cat.warn("Warn entry");
>   cat.error("Error entry");
>   cat.debug("Debug entry");
>
> I have also created a properties file called
> "LogSetting.properties" and placed it with the test
> class file. I have checked and this is on my class path. The
> properties file consists of:
>
> log4j.configDebug=true
> log4j.appender.A1=org.log4j.FileAppender
> log4j.appender.A1.File=System.out
>
> log4j.rootCategory=DEBUG, A1
>
> log4j.appender.A1.layout=org.log4j.PatternLayout
> log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x-%m%n
>
>
> When I run my test program I get the following error:
>
>
> log4j: Could not read configuration file [LogSetting].
> java.io.FileNotFoundException: LogSetting (The system cannot find
> the file specified)
>
> Any ideas or help in getting this to work will be greatly appreciated.
>
> Alex
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Photos - Share your holiday photos online!
> http://photos.yahoo.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org
>
>


Database appender

Posted by Eduardo Issao Ito <it...@integrationtech.com.br>.
Does anybody already done a Database appender, and could share it with us?


--
Eduardo Issao Ito <it...@integrationtech.com.br>
Integration Technologies Ltda. <http://www.integrationtech.com.br>
Rua Marina Saddi Haidar, 176
04650-050 / Sao Paulo / SP / Brasil
Phone: +55 11 5522-4848 x311
Fax:   +55 11 5524-1125


Re: Trying to figure out how to get Log4J to work with Properties

Posted by Ceki Gulcu <cg...@urbanet.ch>.
Alex,

When you call the PropertyConfigurator.configure() the argument must match 
the name of the file.
So, the call should 
be  PropertyConfigurator.configure("LogSetting.properties");

Hope this helps, Ceki

ps: To see what log4j is doing, define the system property 
log4j.configDebug as in

    java -Dlog4j.configDebug your.application

At 06:48 29.12.2000 -0800, Alex Colic wrote:
>Hi,
>
>I am trying to figure out how to get Log4J to work with a properties file 
>which I have created and
>I am having a bit of a problem. I think I have done everything correctly 
>but Log4J can't find my
>properties file. I have created a class called Test with the following 
>code in the Main:
>
>   PropertyConfigurator.configure("LogSetting");
>   Category cat=Category.getInstance("test");
>   cat.info("Info Entry");
>   cat.warn("Warn entry");
>   cat.error("Error entry");
>   cat.debug("Debug entry");
>
>I have also created a properties file called "LogSetting.properties" and 
>placed it with the test
>class file. I have checked and this is on my class path. The properties 
>file consists of:
>
>log4j.configDebug=true
>log4j.appender.A1=org.log4j.FileAppender
>log4j.appender.A1.File=System.out
>
>log4j.rootCategory=DEBUG, A1
>
>log4j.appender.A1.layout=org.log4j.PatternLayout
>log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x-%m%n
>
>
>When I run my test program I get the following error:
>
>
>log4j: Could not read configuration file [LogSetting].
>java.io.FileNotFoundException: LogSetting (The system cannot find the file 
>specified)
>
>Any ideas or help in getting this to work will be greatly appreciated.
>
>Alex
>
>
>
>__________________________________________________
>Do You Yahoo!?
>Yahoo! Photos - Share your holiday photos online!
>http://photos.yahoo.com/
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-user-help@jakarta.apache.org