You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by siegfried <si...@heintze.com> on 2009/05/24 17:19:32 UTC

How to log in EJB

Can someone point me to a simple example of logging within an EJB? I'm using
openejb. 

When I run "mvn test" on the openejb examples I see lots of logging. Is
there a way for EJB log entries to appear mixed in with the client side log
entries that appear when I run the unit tests? That would be nice. If not,
how would I observe the log output? 

I was reading http://openejb.apache.org/logging.html. Would I have to modify
the openejb.base/conf/logging.properties file? 

Is the procedure observing server side ejb log entries any different for
JBOSS? Hmmm... maybe that is a question for a different forum.

Thanks, 
Siegfried

Re: How to log in EJB

Posted by David Blevins <da...@visi.com>.
Sorry for the delay, we were heads down on getting the release out and  
preparing for JavaOne.

On May 26, 2009, at 12:40 AM, siegfried wrote:

>
>> Is there something different that you would like?  Sure we can find a
>> way to do what you need if we can get a better picture of what you're
>> after.
>>
>> -David
>
> I've edited
> openejb-examples-3.1\simple-stateless\src\main\java\org\superbiz 
> \calculator\
> CalculatorImpl.java
> and added the line of code log.info("calling sum"); See below for  
> the entire
> file with my edits.
>
> This is working as desired and I see "calling sum" when I type "mvn  
> test".
>
> However, when I use log.fine("calling sum") it does not work.  
> Somewhere
> there is a properties file I need
> (1) bundle in the deployment using the pom.xml (how do I do that?)
> (2) modify to turn on fine grain logging for CalculatorImpl (how do  
> I do
> that?)
>
> Why does not the standard logging API have a function called debug  
> instead
> of fine?
>
>
> Could I use the log4j implementation too?

Ok, I see.  You can use what ever logging API you would like in your  
code and are able to configure that using the API the logger offers as  
normal.  As to why the java.util.logging API uses "fine" instead of  
"debug", I'm not sure; have wondered that myself.  In the case of  
log4j you just have to keep in mind that OpenEJB also uses log4j so  
any settings you choose may affect the log output.

If you go with log4j you can take advantage of some config options we  
have such as putting your logging configuration in the system or  
initial context properties.  An example would be:

   Properties properties = new Properties();
   properties.setProperty("log4j.category.OpenEJB.options", "DEBUG");
   InitialContext initialContext = new InitialContext(properties);

Basically any properties that start with "log4." we will automatically  
add to the log4 configuration.

-David


RE: How to log in EJB

Posted by siegfried <si...@heintze.com>.
>Is there something different that you would like?  Sure we can find a
>way to do what you need if we can get a better picture of what you're
>after.
>
>-David

I've edited
openejb-examples-3.1\simple-stateless\src\main\java\org\superbiz\calculator\
CalculatorImpl.java
and added the line of code log.info("calling sum"); See below for the entire
file with my edits.

This is working as desired and I see "calling sum" when I type "mvn test".

However, when I use log.fine("calling sum") it does not work. Somewhere
there is a properties file I need
(1) bundle in the deployment using the pom.xml (how do I do that?)
(2) modify to turn on fine grain logging for CalculatorImpl (how do I do
that?)

Why does not the standard logging API have a function called debug instead
of fine?

Could I use the log4j implementation too?

Thanks,
Siegfried

/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.superbiz.calculator;

import javax.ejb.Stateless;
import java.util.logging.*;

/**
 * This is an EJB 3 style pojo stateless session bean
 * Every stateless session bean implementation must be annotated
 * using the annotation @Stateless
 * This EJB has 2 business interfaces: CalculatorRemote, a remote business
 * interface, and CalculatorLocal, a local business interface
 * 
 */
//START SNIPPET: code
@Stateless
public class CalculatorImpl implements CalculatorRemote, CalculatorLocal {
  private static Logger log =
Logger.getLogger(CalculatorImpl.class.getName());

	public int sum(int add1, int add2) {
    log.info("calling sum");
		return add1+add2;
	}

	public int multiply(int mul1, int mul2) {
    log.info("calling multiply");
		return mul1*mul2;
	}

}
//END SNIPPET: code

Re: How to log in EJB

Posted by David Blevins <da...@visi.com>.
On May 24, 2009, at 8:19 AM, siegfried wrote:

> When I run "mvn test" on the openejb examples I see lots of logging.  
> Is
> there a way for EJB log entries to appear mixed in with the client  
> side log
> entries that appear when I run the unit tests? That would be nice.  
> If not,
> how would I observe the log output?

Not sure I have a clear picture of what you need.

The way things are setup by default, all the examples run with OpenEJB  
embedded in the vm of the unit test and all the log output goes to the  
console with all the other maven log messages.  So all log output  
should be visible in the build output (which I guess is the client  
technically as everything runs in the same VM).

Is there something different that you would like?  Sure we can find a  
way to do what you need if we can get a better picture of what you're  
after.

-David