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 Jacob Kjome <ho...@visi.com> on 2007/03/05 23:37:39 UTC

Re: Log4J and Tomcat 5.5 - Trouble getting started

Quoting Chris Chappell <Ch...@Dive100.Freeserve.co.uk>:

> Hi
>
> I'm developing an app with Tomcat 5.5 and am trying to add logging to it.
> I've tried lots of things and none seem to work:
>
> I have code like:
>
> import java.sql.Connection;
> import java.sql.SQLException;
> import java.sql.Statement;
>
> import javax.naming.Context;
> import javax.naming.InitialContext;
> import javax.sql.DataSource;
>
> import org.apache.log4j.Logger;
>
> public class DBConnectivity
> {
>
>     org.apache.log4j.Logger logger =
> Logger.getLogger(myapp.DBConnectivity.class);
> //also tried org.apache.log4j.Logger logger = Logger.getLogger("MyApp");
>     logger.error("Hello");
>
> Eclipse reports an error for the .error line - saying:
>
> Syntax error on token "Hello" - delete this token
> Syntax error on token(s) misplaced contructs.
>

Exactly how does this have anything to do with Tomcat 5.5?  Sounds like you are
having an issue with Eclipse recognizing the Log4j library.  What you have
should work fine, though I would write it simply as...

private final transient Logger logger = Logger.getLogger(DBConnectivity.class);
logger.error("Hello");

Notice that I set the Logger instance as transient. Replace "transient" with
"static" if you want your logger to be static.  It's not so important if your
enclosing class is not Serializable, but if it is, you need to make sure that
loggers aren't serialized with the enclosing class because they are not
serializable.


Beyond that, I don't know what your issue is.  If this truly is an issue related
to Tomcat, you'll need to explain exactly how.

Jake

>
>
> The jars in WEB-INF\lib are:
>
>  commons-beanutils-1.7.0.jar
>  commons-codec-1.3.jar
>  commons-collections-3.1.jar
>  commons-digester-1.7.jar
>  commons-el-1.0.jar
>  commons-fileupload-1.0.jar
>  commons-io-1.1.jar
>  commons-lang-2.1.jar
>  commons-logging-1.1.jar
>  jstl-1.1.0.jar
>  log4j-1.2.14.jar
>  myfaces-api-1.1.4.jar
>  myfaces-impl-1.1.4.jar
>  mysql-connector-java-5.0.4-bin.jar
>  standard-1.1.2.jar
>  tomahawk-1.1.3.jar
>
> As you can see it is an initial stab at a faces app - is this anything
> to do with the prob?
>
> Any help greatfully recieved
>
> Chris
>
>
>
>
> ---------------------------------------------------------------------
> 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: Log4J and Tomcat 5.5 - Trouble getting started

Posted by Chris Chappell <ch...@dive100.freeserve.co.uk>.
Ahh - it's been a while since doing this stuff so I'm a bit rusty.
Was rather obvious - but I was off round the houses trying to find something 
wrong elsewhere.
Thanks for the help.

Chris

----- Original Message ----- 
From: "Jacob Kjome" <ho...@visi.com>
To: "Log4J Users List" <lo...@logging.apache.org>
Sent: Wednesday, March 07, 2007 5:30 AM
Subject: Re: Log4J and Tomcat 5.5 - Trouble getting started


> At 05:29 PM 3/6/2007, you wrote:
> >You cannot log or add any other statement outside of a method. You will
> >have to learn some more Java ;-)
> >
>
> I just looked back at his example.  Indeed, it's not within a method.  I 
> guess I just took for granted that logging was being done inside a method 
> because, well, where else would you do it?  Then again, try/catch has to 
> be within a method or a static block as well, and that's where he said he 
> was finally able to get logging working.  Hmm.... Strange.
>
> Jake
>
> >Regards Sebastian
> >Chris Chappell schrieb:
> >> Hi
> >>
> >> thanks to Jacob for the reply and tips.
> >>
> >> I have found that I can use logger.error("etc") as long as it is
> >> nested in a catch statement.
> >> If in "straight code" eclipse shows the error.
> >> I am not sure why this might be - examples on the net show that it
> >> should be poss.
> >> However I only need to show exceptions so we can make progess.
> >>
> >> The reason I mentioned TC5.5 was in case the changes in logging had
> >> affected things- it is a while since I've been developing with java
> >> and wanted to note the environment I'm using.
> >>
> >>
> >>
> >>
> >> ----- Original Message ----- From: "Jacob Kjome" <ho...@visi.com>
> >> To: "Log4J Users List" <lo...@logging.apache.org>
> >> Sent: Monday, March 05, 2007 10:37 PM
> >> Subject: Re: Log4J and Tomcat 5.5 - Trouble getting started
> >>
> >>
> >>> Quoting Chris Chappell <Ch...@Dive100.Freeserve.co.uk>:
> >>>
> >>>> Hi
> >>>>
> >>>> I'm developing an app with Tomcat 5.5 and am trying to add logging
> >>>> to it.
> >>>> I've tried lots of things and none seem to work:
> >>>>
> >>>> I have code like:
> >>>>
> >>>> import java.sql.Connection;
> >>>> import java.sql.SQLException;
> >>>> import java.sql.Statement;
> >>>>
> >>>> import javax.naming.Context;
> >>>> import javax.naming.InitialContext;
> >>>> import javax.sql.DataSource;
> >>>>
> >>>> import org.apache.log4j.Logger;
> >>>>
> >>>> public class DBConnectivity
> >>>> {
> >>>>
> >>>>     org.apache.log4j.Logger logger =
> >>>> Logger.getLogger(myapp.DBConnectivity.class);
> >>>> //also tried org.apache.log4j.Logger logger =
> >>>> Logger.getLogger("MyApp");
> >>>>     logger.error("Hello");
> >>>>
> >>>> Eclipse reports an error for the .error line - saying:
> >>>>
> >>>> Syntax error on token "Hello" - delete this token
> >>>> Syntax error on token(s) misplaced contructs.
> >>>>
> >>>
> >>> Exactly how does this have anything to do with Tomcat 5.5?  Sounds
> >>> like you are
> >>> having an issue with Eclipse recognizing the Log4j library.  What you
> >>> have
> >>> should work fine, though I would write it simply as...
> >>>
> >>> private final transient Logger logger =
> >>> Logger.getLogger(DBConnectivity.class);
> >>> logger.error("Hello");
> >>>
> >>> Notice that I set the Logger instance as transient. Replace
> >>> "transient" with
> >>> "static" if you want your logger to be static.  It's not so important
> >>> if your
> >>> enclosing class is not Serializable, but if it is, you need to make
> >>> sure that
> >>> loggers aren't serialized with the enclosing class because they are 
> >>> not
> >>> serializable.
> >>>
> >>>
> >>> Beyond that, I don't know what your issue is.  If this truly is an
> >>> issue related
> >>> to Tomcat, you'll need to explain exactly how.
> >>>
> >>> Jake
> >>>
> >>>>
> >>>>
> >>>> The jars in WEB-INF\lib are:
> >>>>
> >>>>  commons-beanutils-1.7.0.jar
> >>>>  commons-codec-1.3.jar
> >>>>  commons-collections-3.1.jar
> >>>>  commons-digester-1.7.jar
> >>>>  commons-el-1.0.jar
> >>>>  commons-fileupload-1.0.jar
> >>>>  commons-io-1.1.jar
> >>>>  commons-lang-2.1.jar
> >>>>  commons-logging-1.1.jar
> >>>>  jstl-1.1.0.jar
> >>>>  log4j-1.2.14.jar
> >>>>  myfaces-api-1.1.4.jar
> >>>>  myfaces-impl-1.1.4.jar
> >>>>  mysql-connector-java-5.0.4-bin.jar
> >>>>  standard-1.1.2.jar
> >>>>  tomahawk-1.1.3.jar
> >>>>
> >>>> As you can see it is an initial stab at a faces app - is this 
> >>>> anything
> >>>> to do with the prob?
> >>>>
> >>>> Any help greatfully recieved
> >>>>
> >>>> Chris
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> 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
> >>>
> >>>
> >>>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> 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
>
>
> ---------------------------------------------------------------------
> 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: Log4J and Tomcat 5.5 - Trouble getting started

Posted by Jacob Kjome <ho...@visi.com>.
At 05:29 PM 3/6/2007, you wrote:
 >You cannot log or add any other statement outside of a method. You will
 >have to learn some more Java ;-)
 >

I just looked back at his example.  Indeed, it's not within a 
method.  I guess I just took for granted that logging was being done 
inside a method because, well, where else would you do it?  Then 
again, try/catch has to be within a method or a static block as well, 
and that's where he said he was finally able to get logging 
working.  Hmm.... Strange.

Jake

 >Regards Sebastian
 >Chris Chappell schrieb:
 >> Hi
 >>
 >> thanks to Jacob for the reply and tips.
 >>
 >> I have found that I can use logger.error("etc") as long as it is
 >> nested in a catch statement.
 >> If in "straight code" eclipse shows the error.
 >> I am not sure why this might be - examples on the net show that it
 >> should be poss.
 >> However I only need to show exceptions so we can make progess.
 >>
 >> The reason I mentioned TC5.5 was in case the changes in logging had
 >> affected things- it is a while since I've been developing with java
 >> and wanted to note the environment I'm using.
 >>
 >>
 >>
 >>
 >> ----- Original Message ----- From: "Jacob Kjome" <ho...@visi.com>
 >> To: "Log4J Users List" <lo...@logging.apache.org>
 >> Sent: Monday, March 05, 2007 10:37 PM
 >> Subject: Re: Log4J and Tomcat 5.5 - Trouble getting started
 >>
 >>
 >>> Quoting Chris Chappell <Ch...@Dive100.Freeserve.co.uk>:
 >>>
 >>>> Hi
 >>>>
 >>>> I'm developing an app with Tomcat 5.5 and am trying to add logging
 >>>> to it.
 >>>> I've tried lots of things and none seem to work:
 >>>>
 >>>> I have code like:
 >>>>
 >>>> import java.sql.Connection;
 >>>> import java.sql.SQLException;
 >>>> import java.sql.Statement;
 >>>>
 >>>> import javax.naming.Context;
 >>>> import javax.naming.InitialContext;
 >>>> import javax.sql.DataSource;
 >>>>
 >>>> import org.apache.log4j.Logger;
 >>>>
 >>>> public class DBConnectivity
 >>>> {
 >>>>
 >>>>     org.apache.log4j.Logger logger =
 >>>> Logger.getLogger(myapp.DBConnectivity.class);
 >>>> //also tried org.apache.log4j.Logger logger =
 >>>> Logger.getLogger("MyApp");
 >>>>     logger.error("Hello");
 >>>>
 >>>> Eclipse reports an error for the .error line - saying:
 >>>>
 >>>> Syntax error on token "Hello" - delete this token
 >>>> Syntax error on token(s) misplaced contructs.
 >>>>
 >>>
 >>> Exactly how does this have anything to do with Tomcat 5.5?  Sounds
 >>> like you are
 >>> having an issue with Eclipse recognizing the Log4j library.  What you
 >>> have
 >>> should work fine, though I would write it simply as...
 >>>
 >>> private final transient Logger logger =
 >>> Logger.getLogger(DBConnectivity.class);
 >>> logger.error("Hello");
 >>>
 >>> Notice that I set the Logger instance as transient. Replace
 >>> "transient" with
 >>> "static" if you want your logger to be static.  It's not so important
 >>> if your
 >>> enclosing class is not Serializable, but if it is, you need to make
 >>> sure that
 >>> loggers aren't serialized with the enclosing class because they are not
 >>> serializable.
 >>>
 >>>
 >>> Beyond that, I don't know what your issue is.  If this truly is an
 >>> issue related
 >>> to Tomcat, you'll need to explain exactly how.
 >>>
 >>> Jake
 >>>
 >>>>
 >>>>
 >>>> The jars in WEB-INF\lib are:
 >>>>
 >>>>  commons-beanutils-1.7.0.jar
 >>>>  commons-codec-1.3.jar
 >>>>  commons-collections-3.1.jar
 >>>>  commons-digester-1.7.jar
 >>>>  commons-el-1.0.jar
 >>>>  commons-fileupload-1.0.jar
 >>>>  commons-io-1.1.jar
 >>>>  commons-lang-2.1.jar
 >>>>  commons-logging-1.1.jar
 >>>>  jstl-1.1.0.jar
 >>>>  log4j-1.2.14.jar
 >>>>  myfaces-api-1.1.4.jar
 >>>>  myfaces-impl-1.1.4.jar
 >>>>  mysql-connector-java-5.0.4-bin.jar
 >>>>  standard-1.1.2.jar
 >>>>  tomahawk-1.1.3.jar
 >>>>
 >>>> As you can see it is an initial stab at a faces app - is this anything
 >>>> to do with the prob?
 >>>>
 >>>> Any help greatfully recieved
 >>>>
 >>>> Chris
 >>>>
 >>>>
 >>>>
 >>>>
 >>>> ---------------------------------------------------------------------
 >>>> 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
 >>>
 >>>
 >>>
 >>
 >>
 >> ---------------------------------------------------------------------
 >> 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


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


Re: Log4J and Tomcat 5.5 - Trouble getting started

Posted by Sebastian Hennebrueder <us...@laliluna.de>.
You cannot log or add any other statement outside of a method. You will
have to learn some more Java ;-)

Regards Sebastian
Chris Chappell schrieb:
> Hi
>
> thanks to Jacob for the reply and tips.
>
> I have found that I can use logger.error("etc") as long as it is
> nested in a catch statement.
> If in "straight code" eclipse shows the error.
> I am not sure why this might be - examples on the net show that it
> should be poss.
> However I only need to show exceptions so we can make progess.
>
> The reason I mentioned TC5.5 was in case the changes in logging had
> affected things- it is a while since I've been developing with java
> and wanted to note the environment I'm using.
>
>
>
>
> ----- Original Message ----- From: "Jacob Kjome" <ho...@visi.com>
> To: "Log4J Users List" <lo...@logging.apache.org>
> Sent: Monday, March 05, 2007 10:37 PM
> Subject: Re: Log4J and Tomcat 5.5 - Trouble getting started
>
>
>> Quoting Chris Chappell <Ch...@Dive100.Freeserve.co.uk>:
>>
>>> Hi
>>>
>>> I'm developing an app with Tomcat 5.5 and am trying to add logging
>>> to it.
>>> I've tried lots of things and none seem to work:
>>>
>>> I have code like:
>>>
>>> import java.sql.Connection;
>>> import java.sql.SQLException;
>>> import java.sql.Statement;
>>>
>>> import javax.naming.Context;
>>> import javax.naming.InitialContext;
>>> import javax.sql.DataSource;
>>>
>>> import org.apache.log4j.Logger;
>>>
>>> public class DBConnectivity
>>> {
>>>
>>>     org.apache.log4j.Logger logger =
>>> Logger.getLogger(myapp.DBConnectivity.class);
>>> //also tried org.apache.log4j.Logger logger =
>>> Logger.getLogger("MyApp");
>>>     logger.error("Hello");
>>>
>>> Eclipse reports an error for the .error line - saying:
>>>
>>> Syntax error on token "Hello" - delete this token
>>> Syntax error on token(s) misplaced contructs.
>>>
>>
>> Exactly how does this have anything to do with Tomcat 5.5?  Sounds
>> like you are
>> having an issue with Eclipse recognizing the Log4j library.  What you
>> have
>> should work fine, though I would write it simply as...
>>
>> private final transient Logger logger =
>> Logger.getLogger(DBConnectivity.class);
>> logger.error("Hello");
>>
>> Notice that I set the Logger instance as transient. Replace
>> "transient" with
>> "static" if you want your logger to be static.  It's not so important
>> if your
>> enclosing class is not Serializable, but if it is, you need to make
>> sure that
>> loggers aren't serialized with the enclosing class because they are not
>> serializable.
>>
>>
>> Beyond that, I don't know what your issue is.  If this truly is an
>> issue related
>> to Tomcat, you'll need to explain exactly how.
>>
>> Jake
>>
>>>
>>>
>>> The jars in WEB-INF\lib are:
>>>
>>>  commons-beanutils-1.7.0.jar
>>>  commons-codec-1.3.jar
>>>  commons-collections-3.1.jar
>>>  commons-digester-1.7.jar
>>>  commons-el-1.0.jar
>>>  commons-fileupload-1.0.jar
>>>  commons-io-1.1.jar
>>>  commons-lang-2.1.jar
>>>  commons-logging-1.1.jar
>>>  jstl-1.1.0.jar
>>>  log4j-1.2.14.jar
>>>  myfaces-api-1.1.4.jar
>>>  myfaces-impl-1.1.4.jar
>>>  mysql-connector-java-5.0.4-bin.jar
>>>  standard-1.1.2.jar
>>>  tomahawk-1.1.3.jar
>>>
>>> As you can see it is an initial stab at a faces app - is this anything
>>> to do with the prob?
>>>
>>> Any help greatfully recieved
>>>
>>> Chris
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> 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: Log4J and Tomcat 5.5 - Trouble getting started

Posted by Jacob Kjome <ho...@visi.com>.
Quoting Chris Chappell <ch...@dive100.freeserve.co.uk>:

> Hi
>
> thanks to Jacob for the reply and tips.
>
> I have found that I can use logger.error("etc") as long as it is nested in a
> catch statement.
> If in "straight code" eclipse shows the error.
> I am not sure why this might be - examples on the net show that it should be
> poss.
> However I only need to show exceptions so we can make progess.
>

It makes zero sense that you can only use logger.error("string") within a
"catch" block.  Your Eclipse install or "straight code" plugin is broken.  Try
compiling outside eclipse.  I bet you get no errors no matter where you put
logger.error("string").

> The reason I mentioned TC5.5 was in case the changes in logging had affected
> things- it is a while since I've been developing with java and wanted to
> note the environment I'm using.
>

But Tomcat is the runtime environment.  Your issue is coming at compile-time,
though it's not really a compile-time issue because there's nothing wrong with
the code.  There's something wrong with how Eclipse is interpreting the code as
you view it in the editor.  Given this, the deployment environment is
superfluous to the issue at hand.


Jake

>
>
>
> ----- Original Message -----
> From: "Jacob Kjome" <ho...@visi.com>
> To: "Log4J Users List" <lo...@logging.apache.org>
> Sent: Monday, March 05, 2007 10:37 PM
> Subject: Re: Log4J and Tomcat 5.5 - Trouble getting started
>
>
> > Quoting Chris Chappell <Ch...@Dive100.Freeserve.co.uk>:
> >
> >> Hi
> >>
> >> I'm developing an app with Tomcat 5.5 and am trying to add logging to it.
> >> I've tried lots of things and none seem to work:
> >>
> >> I have code like:
> >>
> >> import java.sql.Connection;
> >> import java.sql.SQLException;
> >> import java.sql.Statement;
> >>
> >> import javax.naming.Context;
> >> import javax.naming.InitialContext;
> >> import javax.sql.DataSource;
> >>
> >> import org.apache.log4j.Logger;
> >>
> >> public class DBConnectivity
> >> {
> >>
> >>     org.apache.log4j.Logger logger =
> >> Logger.getLogger(myapp.DBConnectivity.class);
> >> //also tried org.apache.log4j.Logger logger = Logger.getLogger("MyApp");
> >>     logger.error("Hello");
> >>
> >> Eclipse reports an error for the .error line - saying:
> >>
> >> Syntax error on token "Hello" - delete this token
> >> Syntax error on token(s) misplaced contructs.
> >>
> >
> > Exactly how does this have anything to do with Tomcat 5.5?  Sounds like
> > you are
> > having an issue with Eclipse recognizing the Log4j library.  What you have
> > should work fine, though I would write it simply as...
> >
> > private final transient Logger logger =
> > Logger.getLogger(DBConnectivity.class);
> > logger.error("Hello");
> >
> > Notice that I set the Logger instance as transient. Replace "transient"
> > with
> > "static" if you want your logger to be static.  It's not so important if
> > your
> > enclosing class is not Serializable, but if it is, you need to make sure
> > that
> > loggers aren't serialized with the enclosing class because they are not
> > serializable.
> >
> >
> > Beyond that, I don't know what your issue is.  If this truly is an issue
> > related
> > to Tomcat, you'll need to explain exactly how.
> >
> > Jake
> >
> >>
> >>
> >> The jars in WEB-INF\lib are:
> >>
> >>  commons-beanutils-1.7.0.jar
> >>  commons-codec-1.3.jar
> >>  commons-collections-3.1.jar
> >>  commons-digester-1.7.jar
> >>  commons-el-1.0.jar
> >>  commons-fileupload-1.0.jar
> >>  commons-io-1.1.jar
> >>  commons-lang-2.1.jar
> >>  commons-logging-1.1.jar
> >>  jstl-1.1.0.jar
> >>  log4j-1.2.14.jar
> >>  myfaces-api-1.1.4.jar
> >>  myfaces-impl-1.1.4.jar
> >>  mysql-connector-java-5.0.4-bin.jar
> >>  standard-1.1.2.jar
> >>  tomahawk-1.1.3.jar
> >>
> >> As you can see it is an initial stab at a faces app - is this anything
> >> to do with the prob?
> >>
> >> Any help greatfully recieved
> >>
> >> Chris
> >>
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> 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
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> 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: Log4J and Tomcat 5.5 - Trouble getting started

Posted by Chris Chappell <ch...@dive100.freeserve.co.uk>.
Hi

thanks to Jacob for the reply and tips.

I have found that I can use logger.error("etc") as long as it is nested in a 
catch statement.
If in "straight code" eclipse shows the error.
I am not sure why this might be - examples on the net show that it should be 
poss.
However I only need to show exceptions so we can make progess.

The reason I mentioned TC5.5 was in case the changes in logging had affected 
things- it is a while since I've been developing with java and wanted to 
note the environment I'm using.




----- Original Message ----- 
From: "Jacob Kjome" <ho...@visi.com>
To: "Log4J Users List" <lo...@logging.apache.org>
Sent: Monday, March 05, 2007 10:37 PM
Subject: Re: Log4J and Tomcat 5.5 - Trouble getting started


> Quoting Chris Chappell <Ch...@Dive100.Freeserve.co.uk>:
>
>> Hi
>>
>> I'm developing an app with Tomcat 5.5 and am trying to add logging to it.
>> I've tried lots of things and none seem to work:
>>
>> I have code like:
>>
>> import java.sql.Connection;
>> import java.sql.SQLException;
>> import java.sql.Statement;
>>
>> import javax.naming.Context;
>> import javax.naming.InitialContext;
>> import javax.sql.DataSource;
>>
>> import org.apache.log4j.Logger;
>>
>> public class DBConnectivity
>> {
>>
>>     org.apache.log4j.Logger logger =
>> Logger.getLogger(myapp.DBConnectivity.class);
>> //also tried org.apache.log4j.Logger logger = Logger.getLogger("MyApp");
>>     logger.error("Hello");
>>
>> Eclipse reports an error for the .error line - saying:
>>
>> Syntax error on token "Hello" - delete this token
>> Syntax error on token(s) misplaced contructs.
>>
>
> Exactly how does this have anything to do with Tomcat 5.5?  Sounds like 
> you are
> having an issue with Eclipse recognizing the Log4j library.  What you have
> should work fine, though I would write it simply as...
>
> private final transient Logger logger = 
> Logger.getLogger(DBConnectivity.class);
> logger.error("Hello");
>
> Notice that I set the Logger instance as transient. Replace "transient" 
> with
> "static" if you want your logger to be static.  It's not so important if 
> your
> enclosing class is not Serializable, but if it is, you need to make sure 
> that
> loggers aren't serialized with the enclosing class because they are not
> serializable.
>
>
> Beyond that, I don't know what your issue is.  If this truly is an issue 
> related
> to Tomcat, you'll need to explain exactly how.
>
> Jake
>
>>
>>
>> The jars in WEB-INF\lib are:
>>
>>  commons-beanutils-1.7.0.jar
>>  commons-codec-1.3.jar
>>  commons-collections-3.1.jar
>>  commons-digester-1.7.jar
>>  commons-el-1.0.jar
>>  commons-fileupload-1.0.jar
>>  commons-io-1.1.jar
>>  commons-lang-2.1.jar
>>  commons-logging-1.1.jar
>>  jstl-1.1.0.jar
>>  log4j-1.2.14.jar
>>  myfaces-api-1.1.4.jar
>>  myfaces-impl-1.1.4.jar
>>  mysql-connector-java-5.0.4-bin.jar
>>  standard-1.1.2.jar
>>  tomahawk-1.1.3.jar
>>
>> As you can see it is an initial stab at a faces app - is this anything
>> to do with the prob?
>>
>> Any help greatfully recieved
>>
>> Chris
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>
> 


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