Search in sources :

Example 1 with ILogger

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);
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ILogger(m.co.rh.id.alogger.ILogger)

Example 2 with ILogger

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));
}
Also used : AndroidLogger(m.co.rh.id.alogger.AndroidLogger) ArrayList(java.util.ArrayList) Handler(android.os.Handler) IOException(java.io.IOException) ToastLogger(m.co.rh.id.alogger.ToastLogger) ILogger(m.co.rh.id.alogger.ILogger) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) FileLogger(m.co.rh.id.alogger.FileLogger) CompositeLogger(m.co.rh.id.alogger.CompositeLogger)

Aggregations

ILogger (m.co.rh.id.alogger.ILogger)2 Handler (android.os.Handler)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 AndroidLogger (m.co.rh.id.alogger.AndroidLogger)1 CompositeLogger (m.co.rh.id.alogger.CompositeLogger)1 FileLogger (m.co.rh.id.alogger.FileLogger)1 ToastLogger (m.co.rh.id.alogger.ToastLogger)1