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

Log #5

Open
asgeek96 opened this issue Jul 25, 2019 · 5 comments
Open

Log #5

asgeek96 opened this issue Jul 25, 2019 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@asgeek96
Copy link

Hi
Can a option be added to create a log file for the optimized images.

@victordomingos victordomingos added enhancement New feature or request good first issue Good for newcomers labels Jul 26, 2019
@victordomingos
Copy link
Owner

I will consider adding it in a future version. I am quite busy right now, so if someone reading this is willing to contribute I may accept a pull request as long as it does not break existing funtionality.

@derenix
Copy link
Contributor

derenix commented Sep 25, 2021

We may can do something like this with pythons logging framework, e.g like this.

import logging
import sys

configured_handlers = [logging.FileHandler(args.log_file), logging.StreamHandler(sys.stdout)]
logging.basicConfig(level=logging.INFO, format="%(message)s", handlers=configured_handlers)

This will log to args.log_file and at the same time to stdout, but I don't know if its that what @asgeek96 is trying to archieve here?

@victordomingos
Copy link
Owner

I agree about using the standard library's logging module, not adding new dependencies.

I would keep logging and screen output as separate operations, since the features needed tend to be a bit different in each case. With regards to logging, I think we should have the ability to specify the file path and, either now or in a future update, a few customisation options. For instance:

1. Default (full) report

Write the full report (files, size changes, summary and errors, similar to what we are already printing to screen) to the specified file:

optimize-images --report ./report.txt

2. Errors log

Write a smaller report including just any errors found to the specified file:

optimize-images --log-errors ./errorslog.txt 
optimize-images --le ./errorslog.txt 

3. Processed files log

Write a smaller report including the list of all processed (i.e. modified) images paths (one file path per line, without further details, in order to allow integration with other tools) to the specified file:

optimize-images --log-files ./logfiles.txt 
optimize-images --lf ./logfiles.txt 

By keeping these options separate, we can implement it one at a time, but do it in a way that makes it easy to add the other options. Also, it would allow the user to combine those options in a single command, for instance, getting an error log and a processed files list (or even the 3 kinds of reports, if needed), in separate files:

optimize-images --log-files ./logfiles.txt --log-errors ./errorslog.txt 
optimize-images --lf ./logfiles.txt --le ./errorslog.txt 

What do you think?

@derenix
Copy link
Contributor

derenix commented Sep 25, 2021

But this is something different, isnt it? From my understanding, you're talking about a to save what happend (reporting), not redirecting the output on the screen to a file (logging).

Don't get me wrong, I don't want to do nitpicking here, just want to be clear what the desired outcome should be.

That said, I agree and like the idea to have a reporting interface (maybe a simple csv file would work?) to have the ability for further post-processing the results. For this we probably don't need to have the logging stuff (also for your second and third point), so I would just go for it and write it the informations to the given files.

Let me know what you think :)

@victordomingos
Copy link
Owner

Right. I try to envision the project as a whole, in order to come up with an implementation strategy that fits the needs not only of a single issue, but for a number of common use cases. It is indeed a different feature, while vaguely related.

I can see how a csv (or json or other structured format) could be useful. But I would let those to a later stage, as format options for the report or log files. Right now, I would start with the approach I described above. I believe the logging module can still be useful at least for error reporting, but I could be wrong. For the rest, probably you are right, no need for it. And later we could extend this reporting feature with additional file format options (e.g., CSV).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants