In the same vein: how does one specify a tab character in the pattern
layout, \t does not work. I would not want to type a TAB in the file since
some editors would replace that with spaces.

Gary


On Tue, Jun 24, 2014 at 11:52 PM, Gary Gregory <[email protected]>
wrote:

> The next question is what should a better configuration look like?
>
> Putting \r in the Java String seems wrong, that's the job of the pattern
> layout.
>
> Something like:
>
> <PatternLayout pattern="%cr%highlight{%-5level: %msg%throwable}" />
>
> Where %cr and %lf would be supported. %n denotes the platform line ending
> and therefore is not suitable for a progress bar.
>
> That or we could also support actual escape sequences in the pattern.
>
> I do not know if using \r in a pattern is supposed to print "\r" or a CR.
>
> Thoughts?
>
> Gary
>
>
> On Tue, Jun 24, 2014 at 11:24 PM, Gary Gregory <[email protected]>
> wrote:
>
>> Petar,
>>
>> Yeah, the problem is that a \r in the pattern layout prints "\r" and not
>> the real CR.
>>
>> Out of the box (trunk and probably the imminent RC2 in a couple of days),
>> the best I can do is:
>>
>>     private static void updateProgress(final double progressPercentage) {
>>
>>         final int width = 50; // progress bar width in chars
>>
>>         String s = "[";
>>         int i = 0;
>>         for (; i <= (int) (progressPercentage * width); i++) {
>>
>>             s += ".";
>>         }
>>         for (; i < width; i++) {
>>             s += " ";
>>         }
>>         s += "](" + (new
>> DecimalFormat("#0.00")).format(progressPercentage * 100) + "%)\r";
>>         LOG.info(s);
>>     }
>>
>> Note that the \r is at the end, not the beginning.
>>
>> AND:
>>
>> <PatternLayout pattern="%highlight{%-5level: %msg%throwable}" />
>>
>> Which would not work for general logging. You'd need a special appender
>> configured just for progress bars and another for normal logging where you
>> do want the plain old %n
>>
>> Gary
>>
>>
>> On Fri, Jun 20, 2014 at 11:30 AM, Petar Tahchiev <[email protected]>
>> wrote:
>>
>>> 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
>>>
>>
>>
>>
>> --
>> 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
>>
>
>
>
> --
> 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
>



-- 
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

Reply via email to