简体   繁体   中英

Tapestry 5, Logging in the classes that are not pages

I'm using Mark W. Shead's 10 Minute Demo (the link is visible from here ) on Tomcat, and it works fine. The direct link to the source code is here

I would like put some logging into the classes that are not page classes. For example, the .services.AppModule class.

In the Tapestry documentation it has an example for a page class like this:

import org.apache.tapestry5.ioc.annotations.Inject;

public class MyPage
{
    @Inject
    private Logger logger;

    void onSuccessFromForm()
    {
        logger.info("Changes saved successfully");
    }

But I can't get that to work for the other classes, like AppModule. I get a null pointer exception when I try to use the log.

I also tried this:

@Inject
public static Logger logger = LoggerFactory.getLogger(AppModule.class);

This runs but I get no messages.

Any ideas? Thanks!

You should try this:

public static Logger logger = LoggerFactory.getLogger(AppModule.class);

because of the injecting, I should not to initialise the logger, or you init the logger without inject

I think the problem is that logger is not defined in spring or somewhere, that's why the tapestry can not inject just a null reference. If you want to inject the logger, and not create it, you should find out, why dont the tapestry-project init the logger.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM