Pages

Wednesday, July 25, 2012

Example of Log4J

Log4J Example:

@Controller
public class VanityController {
    private static Logger logger = Logger.getLogger(VanityController.class.toString());

    @RequestMapping(value= "/user/{vanity}", method = RequestMethod.GET)
    public ModelAndView viewProfile(@PathVariable String vanity) {
        ModelAndView mv = new ModelAndView("vanity");
        logger.info(vanity + "vanity called!");
        mv.addObject("name", vanity);
        return mv;
    }

}

when called localhost:8080/user/todo
this is what was displayed in the output: 
INFO: todovanity called!

No comments:

Post a Comment