Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading file logged via slf4android?

I'm writing logs using slf4android (https://github.com/bright/slf4android) but it is not obvious how to read them (ideally I would just like to download them to my computer). The internal storage of the app is not accessible to other apps. Can I configure the slf4android to log to a shared directory? I've tried this but I get NOENT:

FileLogHandlerConfiguration fileHandler = LoggerConfiguration.fileLogHandler(this);
File lol = this.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS);
fileHandler.setFullFilePathPattern(fileHandler.toString() + "/my_log.%g.%u.log");
LoggerConfiguration.configuration().addHandlerToRootLogger(fileHandler);
like image 556
Mattias Petter Johansson Avatar asked Nov 21 '16 21:11

Mattias Petter Johansson


1 Answers

Once you configured logging to a file by:

FileLogHandlerConfiguration fileHandler = LoggerConfiguration.fileLogHandler(this);
fileHandler.setFullFilePathPattern("/sdcard/your.package/my_log.log");
LoggerConfiguration.configuration().addHandlerToRootLogger(fileHandler);

There are two (both simple) ways to get a log file:

  1. Using NotifyDeveloperHandler (my favourite)

    slf4android has a very nice feature (for some reason undocumented) which allows sending an email to a given address with logs and screenshot included in an attachment.

    NotifyDeveloperHandler handler = LoggerConfiguration.configuration().notifyDeveloperHandler(this, "[email protected]");
    handler.notifyWhenDeviceIsShaken();
    LoggerConfiguration.configuration().addHandlerToRootLogger(handler);
    

it's really handy to use (literally) because you can trigger a send action by shaking your device.

enter image description here enter image description here

  1. Using adb

    Run adb pull /sdcard/your.package/my_log.log ~/my_log.log in terminal to copy log file from the device to home directory.

like image 136
klimat Avatar answered Sep 23 '22 16:09

klimat