• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

log4j --- info()

 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import org.apache.log4j.*;

I added these two lines in my code:
static Logger logger = Logger.getLogger(Study.class.getName());
logger.info("within class");
Whether this log informantion 'within class' is showed in the console?

Why i got the following two errors ?
<identifier> expected
[javac] logger.info("within class");

cannot resolve symbol
[javac] symbol : class info
[javac] location: package logger
[javac] logger.info("within class");
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you are trying something like this:


You can have declarations (line 2) at the class level but you can't have statements (line 3). Think about it, when would line 3 run? Who knows, because there's no context to tell the compiler what you want to do.
If you want to run line 3 at load time, wrap it in a "static initializer block":

There's also an "instance initalizer block" which gets run before the constructor when an instance is created:

Otherwise use logger inside methods.
 
kri shan
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PropertyConfigurator.configure("/src/resources/log4j.properties");
when i use this PropertyConfigurator, i am getting the following compilation error

cannot resolve symbol
[javac] symbol : class configure
[javac] location: class org.apache.log4j.PropertyConfigurator
 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
which version of log4j are you using?
Check whether the log4j.jar is present inside WEB-INF/lib folder.

log4j.properties should be kept in classpath. rather than keeping it in src, keep it in WEB-INF/classes folder.

This should be sufficient to use log4j in your web application.
 
kri shan
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Arun, mine is not a web application, it's a core java application.
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you provide more details? Where exactly are you putting the line:

PropertyConfigurator.configure("/src/resources/log4j.properties");

What exact command are you running? What does your classpath look like? What java version and log4j version are you using?

The compile error makes it sound like you've modified the PropertyConfigurator class.

cannot resolve symbol
[javac] symbol : class configure <<-- symbol not found = "configure"
[javac] location: class org.apache.log4j.PropertyConfigurator <<-- location where not found symbol was encountered
 
kri shan
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Carol Enderlin,
jdk version 1.3.1
log4j version 1.2.8
ClassPath
/hai/jboss-3.2.3-src/thirdparty/apache/log4j/lib/log4j.jar:/hai/jboss-3.2.3-src/messaging/src/resources/log4j.properties

PropertyConfigurator.configure();
How can i pass the paramenter value to the configure()?

and one more thing i am changing JBoss source code, when i do ./build.sh every time i am getting the following warnings also
compile-mbean-sources:
[jmxdoclet] log4j:WARN No appenders could be found for logger (xdoclet.util.Translator.getString).
[jmxdoclet] log4j:WARN Please initialize the log4j system properly.
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If log4j finds your property file in the classpath, then do you really need to call PropertyConfigurator.configure() ?

Looks like your ./build.sh is running something that is trying to log with log4j but doesn't have a logger. Do you have a logger configured to log at the root level?

Why don't you post your log4j properties file and if you still have troublesome code, a bigger snippet of code.

If you don't already have this, you might want to set log4j.debug to true in your properties file until you get things worked out:
log4j.debug=true

You can also add that on the command-line (-Dlog4j.debug), but since it's happening in your build you may not have control overall all the java commmands.
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All of your errors make me think that you are putting them in illegal places. Are the ones you're posting the only errors you're getting, or are you just showing us this one? Finally, to really help you, you need to post more code around the line with the error.

My guess is that the line before the one you're looking at has a syntax error (first post in this thread), and the second one looks like you have that at the class level. You cannot have code like that at the class level -- only in a method, constructor, or initializer block.
 
You get good luck from rubbing the belly of a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic