From ea0d1471fcef47bcf77ee8dec843cd93f2d8ada7 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 16 Aug 2020 20:29:09 -0400 Subject: [PATCH] console logger for Android --- .../com/rusefi/app/RusefiApplication.java | 10 +++++++++ .../src/main/java/com/rusefi/app/rusEFI.java | 3 +++ .../com/devexperts/logging/ConsoleLogger.java | 21 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 java_console/logging-api/src/main/java/com/devexperts/logging/ConsoleLogger.java diff --git a/android/app/src/main/java/com/rusefi/app/RusefiApplication.java b/android/app/src/main/java/com/rusefi/app/RusefiApplication.java index 6be576998f..7f8dcb69b1 100644 --- a/android/app/src/main/java/com/rusefi/app/RusefiApplication.java +++ b/android/app/src/main/java/com/rusefi/app/RusefiApplication.java @@ -8,6 +8,16 @@ import org.acra.config.MailSenderConfigurationBuilder; import org.acra.config.ToastConfigurationBuilder; public class RusefiApplication extends Application { + static { + /** + * We better not touch real classes in order not to trigger class loading + * + * Logging#LOG_CLASS_NAME + * @see ConsoleLogger + */ + System.setProperty("log.className", "com.devexperts.logging.ConsoleLogger"); + } + @Override public void onCreate() { super.onCreate(); diff --git a/android/app/src/main/java/com/rusefi/app/rusEFI.java b/android/app/src/main/java/com/rusefi/app/rusEFI.java index 5822f9e0f5..ee2138f7b4 100644 --- a/android/app/src/main/java/com/rusefi/app/rusEFI.java +++ b/android/app/src/main/java/com/rusefi/app/rusEFI.java @@ -38,6 +38,7 @@ import android.view.WindowManager; import android.widget.EditText; import android.widget.TextView; +import com.devexperts.logging.Logging; import com.google.android.material.snackbar.BaseTransientBottomBar; import com.google.android.material.snackbar.Snackbar; import com.rusefi.Callable; @@ -57,6 +58,7 @@ import com.rusefi.proxy.NetworkConnector; import com.rusefi.proxy.NetworkConnectorContext; public class rusEFI extends Activity { + private final static Logging log = Logging.getLogging(rusEFI.class); private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION"; // private static final byte REQUEST_TYPE_CLASS = 32; @@ -81,6 +83,7 @@ public class rusEFI extends Activity { @SuppressLint("SetTextI18n") @Override protected void onCreate(Bundle savedInstanceState) { + log.info("onCreate"); super.onCreate(savedInstanceState); setContentView(R.layout.activity_usb); diff --git a/java_console/logging-api/src/main/java/com/devexperts/logging/ConsoleLogger.java b/java_console/logging-api/src/main/java/com/devexperts/logging/ConsoleLogger.java new file mode 100644 index 0000000000..2469e15690 --- /dev/null +++ b/java_console/logging-api/src/main/java/com/devexperts/logging/ConsoleLogger.java @@ -0,0 +1,21 @@ +package com.devexperts.logging; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.logging.ConsoleHandler; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class ConsoleLogger extends DefaultLogging { + @Override + Map configureLogFile(String log_file) { + Logger root = Logger.getLogger(""); + Handler handler = new ConsoleHandler(); + handler.setFormatter(new LogFormatter()); + handler.setLevel(Level.ALL); + root.addHandler(handler); + + return new LinkedHashMap<>(); + } +}