Note, that it will replace current logging handler.
If you need I can expand logging wrapper in Halcyon to be more elastic, allow to add more handlers, formatters etc.
Artur Hefczyc commented 4 years ago
I really need something simple. Replacing current logging handler works for me too. I just need a way to redirect all log records to my view to see what is going on on an actual device.
When you have something please provide some code examples on how to use my own logger.
I already have implementation, you can take a look at it: tigase.convene.view.DebugView
Bartosz Małkowski commented 4 years ago
With this code, you can redirect all logs generated by Halcyon to your view. I think I don't know what you really need.
Bartosz Małkowski commented 4 years ago
I checked DebugView. It looks OK. I understand that instance of DebugView is in memory all the time?
Artur Hefczyc commented 4 years ago
Yes, DebugView is in memory only. Just to see some info about app running on device.
Will this work, the above code even if I execute it after halcyon has been instantiated? I mean, after Halcyon created log instances?
Bartosz Małkowski commented 4 years ago
Ah… That way!
No. It will not work as you need. Every Logger object has own SPI given on object creation.
Now I know what exactly you need.
Bartosz Małkowski commented 4 years ago
I added new class: LoggerSPIBuffer. It has buffer for last N log entries.
To configure it, use this code at the beginning:
val bufferLogger= LoggerSPIBuffer(5) // buffer size is set to 5
LoggerFactory.spiFactory = bufferLogger::create
When instance of DebugView will be created you can get log entries from buffer and you should register callback in LoggerSPIBuffer to be informed about new entries added to buffer.
// access to buffered entries
val listOfLastEntries=bufferLogger.getBuffer()
// adding callback
bufferLogger.callback = {entry: LoggerSPIBuffer.Entry ->
println("Nowy log entry $entry")
}
Bartosz Małkowski commented 4 years ago
Implemented. I also adjusted your client code.
Artur Hefczyc commented 4 years ago
Thank you.
To be honest I did not mean that. I was just asking, because it did not work for me. Eventually, I changed my code and got it working. Thank you anyway :-)
Logging messages needs to be shown in custom log console.