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

[Feature] Replace System.out/System.err with logging framework or logging facade #1418

Open
valfirst opened this issue Nov 9, 2023 · 9 comments

Comments

@valfirst
Copy link

valfirst commented Nov 9, 2023

Why is System.out/System.err poor?
Here is just one example of multiple explanations: https://owasp.org/www-community/vulnerabilities/Poor_Logging_Practice

Proposal:
Replace System.out/System.err with logging facade SLF4J: https://www.slf4j.org/. Having this approach users will have freedom in choosing actual logging framework and will be able to configure log levels and log outputs (console, file, etc.)

@yury-s
Copy link
Member

yury-s commented Nov 10, 2023

Do you have a particular use case where current logging approach causes problems?

@valfirst
Copy link
Author

I'm working on implementation of PW plugin for test automation solution. We redirect logs to files and our reporting system (technically endpoint is REST API). If there are solutions to redirect System.out/System.err streams, please share.

@yury-s
Copy link
Member

yury-s commented Nov 10, 2023

Without knowing much about the plugin and how it runs playwright it's hard to provide a solution. You can use System.setOut/setErr to capture standard output in-process. If it runs in a separate process, just redirect the output to a file with > bash operator or pipe it (|) to you log processor.

@valfirst
Copy link
Author

here is an example of repo with implementation of Log4J2 Appender: https://github.com/reportportal/logger-java-log4j.

but it seems my original idea behind this request was lost, let me put the quote:

The problem is that writing directly to standard output or standard error is often used as an unstructured form of logging. Structured logging facilities provide features like: Logging levels, uniform formatting, a logger identifier, timestamps, and perhaps most critically; the ability to direct the log messages to the right place.

@yury-s
Copy link
Member

yury-s commented Nov 10, 2023

Ok, let's collect more feedback. So far I'm not convinced that there is a good justification for adding complexity of such logging frameworks to the project. One of the main reasons is that for debugging tests we recommend recording Playwright traces, they contain way more details than printed to stdout/err and in a better structured form. Such trace files would have to be uploaded to the report separately anyway.

@nirtal85
Copy link

allure framework is a great logging solution

@valfirst
Copy link
Author

Allure is a reporting framework, but not logging. Logging frameworks are Log4J, Logback, JUL. SLF4J is a logging facade.

@rtretyak
Copy link

Using println is not a logging solution at all. Or at least not a recommended one in Java world

@melloware
Copy link

melloware commented Oct 26, 2024

SL4L API would be the way to go as its very popular and its super lightweight facade. I can also be convinced to use just java.util.logging since most logging facades have ways of getting to java.util.logging nowawadys including all the major libraries.

The benefit of java.util.logging is it adds 0 dependencies to Playwright.

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

No branches or pull requests

5 participants