mihnita / java-color-loggers

Color console logging for log4j and jdk
http://www.mihai-nita.net/java/
Apache License 2.0
38 stars 6 forks source link

Bug when using "newline escape in log" #3

Closed martin-vavrusak closed 11 years ago

martin-vavrusak commented 11 years ago

Hi I use your color loggers its fine. But I found problem when message contains formatting escapes in text. For example new line or tab escapes.

logger.warn("this is ok \n And all \n this have only\n\tblack color \n and here is colour again?");
System.out.println("Is it black again?");

will print: "this is ok" - in colour "And all this have black color" - this is without color "and here is colour again?" - again in color

its quite strange behaviour. I would expect that all next messages will be colored but consequent print prints normally.

mihnita commented 11 years ago

It would help to know:

I have tried to reproduce this by changing src/test/java/ColorLogTest.java with your logging, instead of the current code, and all works fine (jdk, log4j, logback, with the config files used by the unit test) Did it on Windows, using ansicon.

martin-vavrusak commented 11 years ago

Hello, I'm sorry I use log4j. Netbeans 7.3 IDE and Windows XP. I downloaded your source code from github and test it with deful configuration and it appears again. But I also tried to use log4j2 API and theirs coloring and noticed that there is problem too. So it seems it is not a problem with your code. Further I noticed that problem is only with \n (new line) escape. Tabulators are ok. I tried some things and find workaround that using \r (CR) instead of \n solved the problem. In the attachements I'm sending you edited source codea and image of output.

Bye, Martin

2013/6/3 Mihai Nita notifications@github.com

It would help to know:

  • what logger are you using (jdk, log4j, logback)
  • what the configuration file for the logger looks like (especially the ConversionPattern)
  • OS

I have tried to reproduce this by changing src/test/java/ColorLogTest.java with your logging, instead of the current code, and all works fine (jdk, log4j, logback, with the config files used by the unit test) Did it on Windows, using ansicon.

— Reply to this email directly or view it on GitHubhttps://github.com/mihnita/java-color-loggers/issues/3#issuecomment-18826113 .

mihnita commented 11 years ago

Sorry, the attachment (if it was one) did not make it. Although you might get this by email, it comes from notifications@github.com, and I guess that discards the attachments...

Anyway, I did not know that Netbeans recognize ANSI escapes in output, I might try to play with it. But will have to wait for the week-end, not much time now :-)

But if the problem is in Netbeans, what about trying to eliminate any logger to begin with. Just do a regular print: System.out.println("\u001b[1;31mThis is red \n And all \n this have only\n\tblack color \n and here is colour again?\u001b[0m");

martin-vavrusak commented 11 years ago

Well, it was good point from you. I tried that System print and find out that this bug is probably in Netbeans IDE. Because like before colored is only beggining and the eng of the message. I wanted to try this in eclipse bud Eclipse would need some plugins and I dont have time to play with it right now. I build it into runnable jar with Jansi and it works well. So it looks like it is problem in Netbeans IDE.

Bye Martin

2013/6/4 Mihai Nita notifications@github.com

Sorry, the attachment (if it was one) did not make it. Although you might get this by email, it comes from notifications@github.com, and I guess that discards the attachments...

Anyway, I did not know that Netbeans recognize ANSI escapes in output, I might try to play with it. But will have to wait for the week-end, not much time now :-)

But if the problem is in Netbeans, what about trying to eliminate any logger to begin with. Just do a regular print: System.out.println("\u001b[1;31mThis is red \n And all \n this have only\n\tblack color \n and here is colour again?\u001b[0m");

— Reply to this email directly or view it on GitHubhttps://github.com/mihnita/java-color-loggers/issues/3#issuecomment-18891720 .

mihnita commented 11 years ago

I tried that System print and find out that this bug is probably in Netbeans IDE Thank you. This means I will close this as "not a bug" But it does not mean discussion closed, if you add something I will answer :-)

Choosing an IDE depends on things more important that color support in console :-) But if you want / have the time to try Eclipse, the plugin is ansi-econsole (also mine, and also here, in GitHub)

Quick install: In Eclipse select “Help” -> “Install New Software...” and click “Add...” to add the following URL: http://www.mihai-nita.net/eclipse You can then select the site in the “Work with” list and continue the installation like with any other plugin. Detailed info and screen-shots at http://www.mihai-nita.net/java

mihnita commented 11 years ago

I want to close this bug, but I am not sure if you can still comment on an issue if I close it. But if you can't, you can contact me thru http://mihai-nita.net/contact-me/ Cheers, Mihai