From e969213451caf1f0a964d20daee7509743b5612f Mon Sep 17 00:00:00 2001 From: str4d <str4d@mail.i2p> Date: Sat, 28 May 2016 23:39:13 +0000 Subject: [PATCH] Dynamically load Android LogWriter --- core/java/src/net/i2p/util/LogManager.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/core/java/src/net/i2p/util/LogManager.java b/core/java/src/net/i2p/util/LogManager.java index d608438065..684d495b18 100644 --- a/core/java/src/net/i2p/util/LogManager.java +++ b/core/java/src/net/i2p/util/LogManager.java @@ -12,6 +12,8 @@ package net.i2p.util; import java.io.File; import java.io.Flushable; import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.SimpleDateFormat; @@ -163,7 +165,21 @@ public class LogManager implements Flushable { // yeah, this doesn't always work, _writer should be volatile if (_writer != null) return; - _writer = new FileLogWriter(this); + if (SystemVersion.isAndroid()) { + try { + Class<?> clazz = Class.forName("net.i2p.util.AndroidLogWriter"); + Constructor<?> ctor = clazz.getDeclaredConstructor(LogManager.class); + _writer = (LogWriter) ctor.newInstance(this); + } catch (ClassNotFoundException e) { + } catch (InstantiationException e) { + } catch (IllegalAccessException e) { + } catch (InvocationTargetException e) { + } catch (NoSuchMethodException e) { + } + } + // Default writer + if (_writer == null) + _writer = new FileLogWriter(this); _writer.setFlushInterval(_flushInterval * 1000); // if you enable logging in I2PThread again, you MUST change this back to Thread Thread t = new I2PThread(_writer, "LogWriter"); -- GitLab