Search in sources :

Example 1 with ToastLogger

use of m.co.rh.id.alogger.ToastLogger 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

Handler (android.os.Handler)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)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 ILogger (m.co.rh.id.alogger.ILogger)1 ToastLogger (m.co.rh.id.alogger.ToastLogger)1