jColorLogger allows you to control the text color and background color and column alignment of statements logged to Standard Out in the Windows console and Linux or Mac terminal emulators. The color functionality doesn't work in the B4J IDE but the logging still does, it just appears as boring monochromatic text.
You can also use this library to get text input from the console both synchronously and asynchronously. This gives you a new way to control your non-UI apps (like servers).
This library makes use of the JNA project. You need the jna-4.1.0.jar which you can download here: https://github.com/twall/jna (at the link "jna.jar" in the Downloads section). Place the jna-4.1.0.jar in your B4J external libraries folder. The native DLLs are inspired by code featured in this article: http://www.cplusplus.com/articles/Eyhv0pDG/ . They are packaged into the library so you don't need to download anything extra, just the .zip attached to this post. Extract the .jar and .xml files contained therein to your B4J external libraries folder.
The library was compiled against JDK 6u26 so it should work on JDKs 6,7 and 8. Furthermore, I've written 64-bit and 32-bit DLLs for the library which means this library works on Windows in 32- and 64-bit JVMs. The Mac and Linux side don't use native access so this library can be used on 32- and 64-bit JVMs in those operating systems.
The following example code:
produces the following output in the Windows console:
EDIT(10JUL2015): Updated to version 1.1. See post #3 for details and a code example.
EDIT(11JUL2015): Fixed a minor bug. When multiple threads would try to log simultaneously, the colors weren't registered accurately. Now they are. The version number remains the same.
EDIT(12JUL2015): Updated to version 1.2. See post #4 for details and a code example.
EDIT(3AUG2015): Updated to version 1.3. See post #5 for details and a code example.
EDIT(4AUG2015): Updated to version 1.31. See post #6 for details and a code example.
EDIT(14AUG2015): Updated to version 1.4. See post #7 for details and a super cool code example.
EDIT(24OCT2015): Updated to version 1.5. Minor bugfix.
EDIT(12MAY2018): If you get an UnsatisfiedLinkError, you might need to install the Microsoft Visual C++ Redistributable Package 2010 (vcredist2010).
You can also use this library to get text input from the console both synchronously and asynchronously. This gives you a new way to control your non-UI apps (like servers).
This library makes use of the JNA project. You need the jna-4.1.0.jar which you can download here: https://github.com/twall/jna (at the link "jna.jar" in the Downloads section). Place the jna-4.1.0.jar in your B4J external libraries folder. The native DLLs are inspired by code featured in this article: http://www.cplusplus.com/articles/Eyhv0pDG/ . They are packaged into the library so you don't need to download anything extra, just the .zip attached to this post. Extract the .jar and .xml files contained therein to your B4J external libraries folder.
The library was compiled against JDK 6u26 so it should work on JDKs 6,7 and 8. Furthermore, I've written 64-bit and 32-bit DLLs for the library which means this library works on Windows in 32- and 64-bit JVMs. The Mac and Linux side don't use native access so this library can be used on 32- and 64-bit JVMs in those operating systems.
The following example code:
B4X:
Sub Process_Globals
Dim cl As ColorLogger
End Sub
Sub AppStart (Args() As String)
cl.Initialize("green", "black",false).ColorLogLine("ColorLogger initialized to these colors.", "", "")
Log("This is a normal B4J Log() call.")
cl.ColorLogLine("This sentence is red.", "aqua", "")
cl.ColorLogLine("The following sentence is green.", "", "")
cl.ColorLogLine("The previous sentence was blue.", "red", "aqua")
Log("Another normal B4J Log() call.")
cl.ColorLogLine(" ", "", "")
cl.ColorLogWord("OK, ", "", "").ColorLogWord("now seriously, ", "red", "").ColorLogWord("this is ", "aqua", "").ColorLogLine("yellow.", "yellow", "")
cl.ColorLogLine("Don't use red on purple.", "red", "purple")
cl.ColorLogWord("Default Back: ", "green", "black").ColorLogLine(cl.DefaultBackColor, cl.DefaultBackColor, "white")
cl.ColorLogWord("Default Text: ", "green", "black").ColorLogLine(cl.DefaultTextColor, cl.DefaultTextColor, "white")
cl.ColorLogLine(" ", "", "")
cl.DefaultBackColor = "dark_white"
cl.DefaultTextColor = "black"
cl.ColorLogWord("New Default Back: ", "green", "black").ColorLogLine(cl.DefaultBackColor, cl.DefaultBackColor, "white")
cl.ColorLogWord("New Default Text: ", "green", "black").ColorLogLine(cl.DefaultTextColor, cl.DefaultTextColor, "white")
cl.ColorLogLine("", "", "")
End Sub
produces the following output in the Windows console:
EDIT(10JUL2015): Updated to version 1.1. See post #3 for details and a code example.
EDIT(11JUL2015): Fixed a minor bug. When multiple threads would try to log simultaneously, the colors weren't registered accurately. Now they are. The version number remains the same.
EDIT(12JUL2015): Updated to version 1.2. See post #4 for details and a code example.
EDIT(3AUG2015): Updated to version 1.3. See post #5 for details and a code example.
EDIT(4AUG2015): Updated to version 1.31. See post #6 for details and a code example.
EDIT(14AUG2015): Updated to version 1.4. See post #7 for details and a super cool code example.
EDIT(24OCT2015): Updated to version 1.5. Minor bugfix.
EDIT(12MAY2018): If you get an UnsatisfiedLinkError, you might need to install the Microsoft Visual C++ Redistributable Package 2010 (vcredist2010).
Attachments
Last edited: