r/learnjava • u/Melodic_Rip_3992 • Feb 15 '24
How stupid is this? set logging like this:
List<Review> findAllReviews() { log.info("find all reviews");
return .....
}4
u/lalalalalalalataken Feb 15 '24
If it is important for you to know each time that this method was called, then it is not stupid.
1
-17
u/Melodic_Rip_3992 Feb 15 '24
i asked about the code style
6
u/darksounds Feb 15 '24
You did not.
-3
u/Melodic_Rip_3992 Feb 16 '24
u know better what i asked?
2
u/darksounds Feb 16 '24
What you intended to ask and what you asked may be two separate things.
Clarity is important, both in communication and in software.
3
Feb 15 '24
Are you asking about the formatting i.e., putting the log.info() call on the same line as the open brace? If so, I'm opposed, damn opposed! I like putting the method declaration on its own line; the line ends after the opening brace.
If you have any method parameters or declare any thrown exception, the line is already getting long; adding actual code to the line just makes it even longer. Also, I bet a lot of people will only read enough of the line to see that it's a method declaration and not even see the logging call.
1
Feb 15 '24
It should be lowered to DEBUG, but it's a completely normal thing if you need to watch that you've entered a specific method.
1
u/Computerboy96 Feb 15 '24
The method retrieves all reviews, log a message indicating that it's doing so and return a list of reviews.
Is it stupid? No, once you implement a way to actually pull the reviews from a source it will do the job as it should do.
1
u/jlanawalt Feb 15 '24
It depends on the usage and need. It seems likely spammy with redundant information (“…findAllReviews find all reviews”)
It looks like the kind of case j.u.l.Logger.entering(…) was made for, but it’s verbose and can be emulated with log.finer(“ENTRY”).
1
u/djnattyp Feb 15 '24
What are you asking about?
I'd prefer a linefeed before "log", and to use .trace() instead of .info()...
•
u/AutoModerator Feb 15 '24
Please ensure that:
Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
You include any and all error messages in full - best also formatted as code block
You ask clear questions
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.