Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is println bad? #161

Closed
xanderdunn opened this issue Oct 2, 2015 · 3 comments
Closed

Is println bad? #161

xanderdunn opened this issue Oct 2, 2015 · 3 comments

Comments

@xanderdunn
Copy link

The default scalastyle config that's provided with it has println flagged as a warning in both the token and regex rules:

 <check class="org.scalastyle.file.RegexChecker" level="warning" enabled="true">
  <parameters>
   <parameter name="regex"><![CDATA[println]]></parameter>
  </parameters>
 </check>

Is this just an example that isn't meant for production use, or is println considered bad?

@matthewfarwell
Copy link
Member

It is just an example. There is nothing wrong with println.

However, for production code, there are better solutions, for example slf4j or log4j. So, a number of project that I have been involved with discourage the use of println. See, for example http://stackoverflow.com/questions/2750346/logger-vs-system-out-println

@xanderdunn
Copy link
Author

@matthewfarwell Thanks. Good advice.

@eshu
Copy link

eshu commented Oct 29, 2019

It is just an example. There is nothing wrong with println.

However, for production code, there are better solutions, for example slf4j or log4j. So, a number of project that I have been involved with discourage the use of println. See, for example http://stackoverflow.com/questions/2750346/logger-vs-system-out-println

There is PrintStream in the standard Java library, it has println in its methods and this check complains about it too. I updated the regular expression for my project:

 <check level="warning" class="org.scalastyle.file.RegexChecker" enabled="true">
  <parameters>
   <parameter name="regex"><![CDATA[(?<!\.)println]]></parameter>
  </parameters>
 </check>

Probably it should be in the scalastyle default configuration: the warning appears only for "bare" println call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants