ctongfei / progressbar

Terminal-based progress bar for Java / JVM
http://tongfei.me/progressbar/
MIT License
1.08k stars 103 forks source link

Allow custom progressbar consumers #54

Closed alexpeelman closed 4 years ago

alexpeelman commented 4 years ago

Hi, I extended this incredible useful tool a bit to allow any kind of consumer to print the progress bar. I need this to write the progress to an SLF4J log.

ctongfei commented 4 years ago

Hi Alex, thanks for this! Compatibility with SLF4J is of utmost importance -- I haven't got time to do it myself. Could you shed some light on how this extension would make it work with SLF4J, so that I could gain a better understanding of the underlying issue? You can paste a snippet here, or you could add a test that depends on SLF4J.

alexpeelman commented 4 years ago

Yes, you are completely right. I added a new DelegatingProgressBarConsumer and changed one of the tests so that it uses a SLF4J logger to print the progress bar.

The idea is that for each progress bar update the state is printed to the logger, without the carriage return.This logs the progress over time.

As an example

[me.tongfei.progressbar.ProgressBar] INFO Test - log.test   1% │▏                      │   1/100 (0:00:00 / 0:00:00) ?/s
[me.tongfei.progressbar.ProgressBar] INFO Test - log.test   8% │█▊                     │   8/100 (0:00:00 / 0:00:01) ?/s
[me.tongfei.progressbar.ProgressBar] INFO Test - log.test  15% │███▍                   │  15/100 (0:00:00 / 0:00:01) ?/s
[me.tongfei.progressbar.ProgressBar] INFO Test - log.test  22% │█████                  │  22/100 (0:00:00 / 0:00:01) ?/s
[me.tongfei.progressbar.ProgressBar] INFO Test - log.test  28% │██████▍                │  28/100 (0:00:00 / 0:00:01) ?/s
[me.tongfei.progressbar.ProgressBar] INFO Test - log.test  35% │████████               │  35/100 (0:00:00 / 0:00:00) ?/s
[me.tongfei.progressbar.ProgressBar] INFO Test - log.test  42% │█████████▋             │  42/100 (0:00:00 / 0:00:00) ?/s
[me.tongfei.progressbar.ProgressBar] INFO Test - log.test  48% │███████████            │  48/100 (0:00:00 / 0:00:00) ?/s
[me.tongfei.progressbar.ProgressBar] INFO Test - log.test  55% │████████████▋          │  55/100 (0:00:00 / 0:00:00) ?/s
[me.tongfei.progressbar.ProgressBar] INFO Test - log.test  62% │██████████████▎        │  62/100 (0:00:00 / 0:00:00) ?/s
[me.tongfei.progressbar.ProgressBar] INFO Test - log.test  68% │███████████████▏      │  69/100 (0:00:01 / 0:00:00) 68/s
[me.tongfei.progressbar.ProgressBar] INFO Test - log.test  75% │████████████████▌     │  75/100 (0:00:01 / 0:00:00) 75/s
[me.tongfei.progressbar.ProgressBar] INFO Test - log.test  82% │██████████████████    │  82/100 (0:00:01 / 0:00:00) 82/s
[me.tongfei.progressbar.ProgressBar] INFO Test - log.test  89% │███████████████████▌  │  89/100 (0:00:01 / 0:00:00) 89/s
[me.tongfei.progressbar.ProgressBar] INFO Test - log.test  95% │████████████████████▉ │  95/100 (0:00:01 / 0:00:00) 95/s
[me.tongfei.progressbar.ProgressBar] INFO Test - log.test 100% │█████████████████████│ 100/100 (0:00:01 / 0:00:00) 100/s
ctongfei commented 4 years ago

Thanks a lot @alexpeelman -- I'll review this when I got some time (hopefully this weekend).

alexpeelman commented 4 years ago

Hi just a small check if you are planning to review this any time soon ? No pressure just asking for an update here :)

ctongfei commented 4 years ago

Hooray! I merged this after some modifications to your code. See documentation at https://tongfei.me/progressbar/loggers/. Thanks @alexpeelman !

alexpeelman commented 4 years ago

Awesome ! Nice idea to introduce the renderer 👍

ctongfei commented 4 years ago

Now deployed as version 0.8.0. You'll see this on maven central in a few hours.