From 7e23c7922a25493d8e02b657b3cb4aa6c3702095 Mon Sep 17 00:00:00 2001 From: Yuya Tanaka Date: Wed, 11 Nov 2015 23:01:30 +0900 Subject: [PATCH] Add log level to message --- .../CrashlyticsLogExceptionTree.java | 4 +-- .../timbertreeutils/CrashlyticsLogTree.java | 4 +-- .../timbertreeutils/LogMessageHelper.java | 29 +++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 lib/src/main/java/net/ypresto/timbertreeutils/LogMessageHelper.java diff --git a/lib/src/main/java/net/ypresto/timbertreeutils/CrashlyticsLogExceptionTree.java b/lib/src/main/java/net/ypresto/timbertreeutils/CrashlyticsLogExceptionTree.java index c7d4223..dc828e9 100644 --- a/lib/src/main/java/net/ypresto/timbertreeutils/CrashlyticsLogExceptionTree.java +++ b/lib/src/main/java/net/ypresto/timbertreeutils/CrashlyticsLogExceptionTree.java @@ -70,8 +70,8 @@ protected void log(int priority, String tag, String message, Throwable t) { if (t != null) { Crashlytics.logException(t); } else { - String messageWithTag = tag != null ? "[" + tag + "] " + message : message; - Crashlytics.logException(new StackTraceRecorder(messageWithTag)); + String formattedMessage = LogMessageHelper.format(priority, tag, message); + Crashlytics.logException(new StackTraceRecorder(formattedMessage)); } } } diff --git a/lib/src/main/java/net/ypresto/timbertreeutils/CrashlyticsLogTree.java b/lib/src/main/java/net/ypresto/timbertreeutils/CrashlyticsLogTree.java index fa61316..7295ecb 100644 --- a/lib/src/main/java/net/ypresto/timbertreeutils/CrashlyticsLogTree.java +++ b/lib/src/main/java/net/ypresto/timbertreeutils/CrashlyticsLogTree.java @@ -67,7 +67,7 @@ protected void log(int priority, String tag, String message, Throwable t) { return; } - String messageWithTag = tag != null ? "[" + tag + "] " + message : message; - Crashlytics.log(messageWithTag); + String formattedMessage = LogMessageHelper.format(priority, tag, message); + Crashlytics.log(formattedMessage); } } diff --git a/lib/src/main/java/net/ypresto/timbertreeutils/LogMessageHelper.java b/lib/src/main/java/net/ypresto/timbertreeutils/LogMessageHelper.java new file mode 100644 index 0000000..ec449dc --- /dev/null +++ b/lib/src/main/java/net/ypresto/timbertreeutils/LogMessageHelper.java @@ -0,0 +1,29 @@ +package net.ypresto.timbertreeutils; + +import android.util.Log; + +class LogMessageHelper { + public static String format(int priority, String tag, String message) { + String messageWithTag = tag != null ? "[" + tag + "] " + message : message; + return prefixForPriority(priority) + messageWithTag; + } + + public static String prefixForPriority(int priority) { + switch (priority) { + case Log.VERBOSE: + return "[VERBOSE] "; + case Log.DEBUG: + return "[DEBUG] "; + case Log.INFO: + return "[INFO] "; + case Log.WARN: + return "[WARN] "; + case Log.ERROR: + return "[ERROR] "; + case Log.ASSERT: + return "[ASSERT] "; + default: + return "[UNKNOWN(" + priority + ")] "; + } + } +}