Log file name
MohammedAlaaMorsi opened this issue · 4 comments
MohammedAlaaMorsi commented
if there is a method to change log file name other than the default name so that I can get this file by it's name and send it over network ?
bosphere commented
yes, you can customise the file name by supplying your own implementation of FileFormatter
during initialisation via FLConfig.Builder
. with it you'll be able to customise both the file name and each line of logs
MohammedAlaaMorsi commented
can you give me some code example of doing that
bosphere commented
you can find the default implementation of FileFormatter
in FLConfig.DefaultFormatter
. that should serve as a fair guide for you to start with.
public class CustomFormatter implements FileFormatter {
public String formatFileName(long timeInMillis) {
return "custom_log_name.txt";
}
...
}
FL.init(new FLConfig.Builder(this).formatter(new CustomFormatter()).build());
FL.setEnabled(true);
CoolMind commented
class CustomLogFormatter : FileFormatter {
private val format = SimpleDateFormat("dd.MM.yyyy HH:mm:ss", Locale.getDefault())
override fun formatLine(timeInMillis: Long, level: String?, tag: String?, log: String?): String {
val date = convertLongToTime(timeInMillis)
return "$date: $level: $tag: $log"
}
override fun formatFileName(timeInMillis: Long): String {
return "custom_log_name.txt";
}
private fun convertLongToTime(time: Long): String {
val date = Date(time)
return format.format(date)
}
}