use of m.co.rh.id.alogger.ILogger in project a-medic-log by rh-id.
the class BaseProviderModule method dispose.
@Override
public void dispose(Context context, Provider provider) {
ILogger iLogger = provider.get(ILogger.class);
ExecutorService executorService = provider.get(ExecutorService.class);
ScheduledExecutorService scheduledExecutorService = provider.get(ScheduledExecutorService.class);
try {
executorService.shutdown();
boolean terminated = executorService.awaitTermination(1500, TimeUnit.MILLISECONDS);
iLogger.d(TAG, "ExecutorService shutdown? " + terminated);
} catch (Throwable throwable) {
iLogger.e(TAG, "Failed to shutdown ExecutorService", throwable);
}
try {
scheduledExecutorService.shutdown();
boolean terminated = scheduledExecutorService.awaitTermination(1500, TimeUnit.MILLISECONDS);
iLogger.d(TAG, "ScheduledExecutorService shutdown? " + terminated);
} catch (Throwable throwable) {
iLogger.e(TAG, "Failed to shutdown ScheduledExecutorService", throwable);
}
}
use of m.co.rh.id.alogger.ILogger 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