Hi Gary,

I made it "\r%highlight{%-5level: %msg%n%throwable}"

but now it prints this:

\rINFO : Starting the progress...
[..                                                ](2.86%)
[...                                               ](5.71%)
[.....                                             ](8.57%)
[......                                            ](11.43%)
[........                                          ](14.29%)
[.........                                         ](17.14%)
[...........                                       ](20.00%)
[............                                      ](22.86%)
[.............                                     ](25.71%)
[...............                                   ](28.57%)
[................                                  ](31.43%)
[..................                                ](34.29%)
[...................                               ](37.14%)
[.....................                             ](40.00%)
[......................                            ](42.86%)
[.......................                           ](45.71%)
[.........................                         ](48.57%)
[..........................                        ](51.43%)
[............................                      ](54.29%)
[.............................                     ](57.14%)
[...............................                   ](60.00%)
[................................                  ](62.86%)
[.................................                 ](65.71%)
[...................................               ](68.57%)
[....................................              ](71.43%)
[......................................            ](74.29%)
[.......................................           ](77.14%)
[.........................................         ](80.00%)
[..........................................        ](82.86%)
[...........................................       ](85.71%)
[.............................................     ](88.57%)
[..............................................    ](91.43%)
[................................................  ](94.29%)
[................................................. ](97.14%)
[...................................................](100.00%)
\rINFO : Done!

This looks weird because it doesn't display the INFO before the [....].

Here's the update progress method:
    private void updateProgress(double progressPercentage) {
        final int width = 50; // progress bar width in chars

        String s = "\r[";
        int i = 0;
        for (; i <= (int)(progressPercentage*width); i++) {
            s += ".";
        }
        for (; i < width; i++) {
            s += " ";
        }
        s += "](" + (new DecimalFormat("#0.00")).format(progressPercentage
* 100) + "%)";
        LOG.info(s);
    }



2014-06-20 17:50 GMT+03:00 Gary Gregory <[email protected]>:

> I do not know off the top of my head and I cannot dig into this ATM but...
> how about putting the \r in the pattern in your log4j.xml config?
>
> Gary
>
>
> On Fri, Jun 20, 2014 at 9:43 AM, Petar Tahchiev <[email protected]>
> wrote:
>
> > Hi Gary,
> >
> > it doesn't, and I'm wondering where's the problem. I have Jansi and it
> > colors my output just fine, however calling multiple times
> >
> > System.out.print("\r [......          ]")
> >
> > will result in
> >
> > [.........       ]
> >
> > being displayed on the same line. And calling multiple times
> >
> > LOG.info("\r [......          ]")
> >
> > will result in a new line every time it is called:
> > [.               ]
> > [..              ]
> > [...             ]
> > [....            ]
> >
> > Any idea why is that?
> >
> >
> >
> >
> > 2014-06-20 15:49 GMT+03:00 Gary Gregory <[email protected]>:
> >
> > > Log4j 2 supports JAnsi out of the box which should work for that. For
> > Log4j
> > > 1, you'd have to write your own appender on top of JAnsi.
> > >
> > > Gary
> > >
> > >
> > > On Fri, Jun 20, 2014 at 8:28 AM, Petar Tahchiev <[email protected]
> >
> > > wrote:
> > >
> > > > Hi guys,
> > > >
> > > > I was wondering if there's a LOG4J console appender out there that
> > > supports
> > > > a carriage return \r (to put the cursor back on the same line).
> > > >
> > > > Cheers, Petar.
> > > >
> > > > --
> > > > Regards, Petar!
> > > > Karlovo, Bulgaria.
> > > > ---
> > > > Public PGP Key at:
> > > >
> > >
> >
> https://keyserver1.pgp.com/vkd/DownloadKey.event?keyid=0x19658550C3110611
> > > > Key Fingerprint: A369 A7EE 61BC 93A3 CDFF  55A5 1965 8550 C311 0611
> > > >
> > >
> > >
> > >
> > > --
> > > E-Mail: [email protected] | [email protected]
> > > Java Persistence with Hibernate, Second Edition
> > > <http://www.manning.com/bauer3/>
> > > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > > Spring Batch in Action <http://www.manning.com/templier/>
> > > Blog: http://garygregory.wordpress.com
> > > Home: http://garygregory.com/
> > > Tweet! http://twitter.com/GaryGregory
> > >
> >
> >
> >
> > --
> > Regards, Petar!
> > Karlovo, Bulgaria.
> > ---
> > Public PGP Key at:
> >
> https://keyserver1.pgp.com/vkd/DownloadKey.event?keyid=0x19658550C3110611
> > Key Fingerprint: A369 A7EE 61BC 93A3 CDFF  55A5 1965 8550 C311 0611
> >
>
>
>
> --
> E-Mail: [email protected] | [email protected]
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
Regards, Petar!
Karlovo, Bulgaria.
---
Public PGP Key at:
https://keyserver1.pgp.com/vkd/DownloadKey.event?keyid=0x19658550C3110611
Key Fingerprint: A369 A7EE 61BC 93A3 CDFF  55A5 1965 8550 C311 0611

Reply via email to