use of m.co.rh.id.alogger.CompositeLogger in project a-medic-log by rh-id.
the class BaseProviderModule method provides.
@Override
public void provides(Context context, ProviderRegistry providerRegistry, Provider provider) {
// thread pool to be used throughout this app lifecycle
providerRegistry.registerAsync(ExecutorService.class, () -> {
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), Integer.MAX_VALUE, 10, TimeUnit.SECONDS, new SynchronousQueue<>());
threadPoolExecutor.allowCoreThreadTimeOut(true);
threadPoolExecutor.prestartAllCoreThreads();
return threadPoolExecutor;
});
providerRegistry.register(ScheduledExecutorService.class, Executors.newSingleThreadScheduledExecutor());
providerRegistry.register(Handler.class, new Handler(Looper.getMainLooper()));
providerRegistry.registerAsync(ILogger.class, () -> {
ILogger defaultLogger = new AndroidLogger(ILogger.ERROR);
List<ILogger> loggerList = new ArrayList<>();
loggerList.add(defaultLogger);
try {
int logLevel = ILogger.DEBUG;
if (BuildConfig.DEBUG) {
logLevel = ILogger.VERBOSE;
}
ILogger fileLogger = new FileLogger(logLevel, provider.get(FileHelper.class).getLogFile());
loggerList.add(fileLogger);
} catch (IOException e) {
defaultLogger.e(TAG, "Error creating file logger", e);
}
try {
ILogger toastLogger = new ToastLogger(ILogger.INFO, context);
loggerList.add(toastLogger);
} catch (Throwable throwable) {
defaultLogger.e(TAG, "Error creating toast logger", throwable);
}
return new CompositeLogger(loggerList);
});
providerRegistry.register(FileHelper.class, new FileHelper(provider, context));
}
Aggregations