At the moment I have connected the logger, but it looks something like this in all methods of each controller and something tells me that this is the wrong approach.

@RequestMapping(value="/list") public String getPlaceList(Model model){ List<PlaceType> placeTypeList = placeTypeService.getAllPlaceType(); List<Place> places = placeService.getAllPlaces(); logger.info("Info messages:"); logger.error("Error messages:"); model.addAttribute("placeTypesList", placeTypeList); model.addAttribute("places", places); return "placelist"; } @RequestMapping(value="/places") public String getPlaces(@RequestParam("id") String typeId, Model model) { logger.info("Info messages:"); logger.error("Error messages:"); PlaceType placeType = placeTypeService.getPlaceTypeById(Long.parseLong(typeId)); List<Place> places = new ArrayList<Place>(placeType.getPlaces()); model.addAttribute("places", places); return "placesList"; } 

    1 answer 1

    Usually, the very fact of calling the method and the parameters that were passed to this method and the result of executing the method before returning the value are logged. Also, if the method performs some complex calculations, it makes sense to log intermediate results. All this goes like DEBUG logs.

    All erroneous states (for example, catch block) go as ERROR logs.

    Some general information should get into the INFO logs, for example, that the application got stuck correctly, that some deployment step was executed correctly (for example, configs were found), but the contents of the configs are better in DEBUG , although if they are not large, you can leave it in INFO .

    • It turns out that these logs in the controller about anything? - raviga
    • @ Khodan.D. Well, the ones that you wrote yes, they do not contain 0 information. You should write some information in the logs, which will make it clear if your application is working correctly or if there is an error somewhere. - Vartlok
    • Where can I read how this is done? I can not understand what I do and what and how to log. In all examples, only stupid two lines how to make an import and create. No good tutorial. Maybe you have good material that will help to understand? - raviga
    • @ Khodan.D. And my answer is not what suits you? I tried to describe what to log “how” you already know, judging by the code. - Vartlok
    • Thanks for the answer, but I need to look at the code to understand what is being done and how. For example: I have no idea how to log the transferred parameters of a method or how to properly arrange the logging levels in that method. - raviga