Skip to content

Commit

Permalink
Release 9.7.0 (#496)
Browse files Browse the repository at this point in the history
* Make it possible to disable default logging

* Release 9.7.0
  • Loading branch information
rlepinski authored Jan 22, 2019
1 parent c55d8da commit 31b6132
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 80 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ Android ChangeLog

[Migration Guides](https://github.com/urbanairship/android-library/tree/master/documentation/migration)

Version 9.7.0 - January 22, 2019
================================
Minor release that allows listing for Urban Airship log messages.

Changes
-------
- Added ability to listen for logs using a LoggerListener on the Logger class.
- Modal, HTML in-app automation window animations are now defined in the style sheets to
make them easier to override.


Version 9.6.1 - January 10, 2019
================================

Expand Down
2 changes: 1 addition & 1 deletion airship.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Airship Version - major.minor.patch
version = 9.6.1
version = 9.7.0

# Airship Version Qualifier beta, release, etc...
#versionQualifier = beta
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0'
classpath 'com.google.gms:google-services:4.2.0'
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Dec 05 09:45:50 PST 2018
#Tue Jan 22 14:33:38 PST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
177 changes: 101 additions & 76 deletions urbanairship-core/src/main/java/com/urbanairship/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RestrictTo;
import android.util.Log;

import com.urbanairship.util.UAStringUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.CopyOnWriteArrayList;

/**
* Shared logging wrapper for all Urban Airship log entries.
Expand All @@ -25,19 +27,67 @@ public class Logger {
/**
* The current log level, as defined by <code>android.util.Log</code>.
* Defaults to <code>android.util.Log.ERROR</code>.
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public static int logLevel = Log.ERROR;

/**
* The current log tag.
* Defaults to "UALib".
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public static String TAG = "UALib";

/**
* A list of listeners.
*/
private static List<LoggerListener> listeners = new ArrayList<>();
private static final List<LoggerListener> listeners = new CopyOnWriteArrayList<>();

/**
* Default logger.
*/
private static final LoggerListener defaultLogger = new LoggerListener() {
@Override
public void onLog(int priority, @Nullable Throwable throwable, @Nullable String message) {
// Log directly if we do not have a throwable
if (throwable == null) {
if (priority == Log.ASSERT) {
Log.wtf(TAG, message);
} else {
Log.println(priority, TAG, message);
}
return;
}

// Log using one of the provided log methods
switch (priority) {
case Log.INFO:
Log.i(TAG, message, throwable);
break;
case Log.DEBUG:
Log.d(TAG, message, throwable);
break;
case Log.VERBOSE:
Log.v(TAG, message, throwable);
break;
case Log.WARN:
Log.w(TAG, message, throwable);
break;
case Log.ERROR:
Log.e(TAG, message, throwable);
break;
case Log.ASSERT:
Log.wtf(TAG, message, throwable);
break;
}
}
};

static {
listeners.add(defaultLogger);
}

/**
* Private, unused constructor
Expand All @@ -53,9 +103,7 @@ private Logger() { }
* @param listener The listener.
*/
public static void addListener(@NonNull LoggerListener listener) {
synchronized (listeners) {
listeners.add(listener);
}
listeners.add(listener);
}

/**
Expand All @@ -64,134 +112,139 @@ public static void addListener(@NonNull LoggerListener listener) {
* @param listener The listener.
*/
public static void removeListener(@NonNull LoggerListener listener) {
synchronized (listeners) {
listeners.remove(listener);
}
listeners.remove(listener);
}

/**
* Disables Urban Airship from using the standard {@link Log} for logging.
*/
public static void disableDefaultLogger() {
removeListener(defaultLogger);
}

/**
* Send a warning log message.
*
* @param s The message you would like logged.
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public static void warn(String s) {
if (logLevel <= Log.WARN && s != null) {
log(Log.WARN, s);
}
log(Log.WARN, s);
}

/**
* Send a warning log message.
*
* @param s The message you would like logged.
* @param t An exception to log
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public static void warn(String s, Throwable t) {
if (logLevel <= Log.WARN && s != null && t != null) {
log(Log.WARN, s, t);
}
log(Log.WARN, s, t);
}

/**
* Send a warning log message.
*
* @param t An exception to log
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public static void warn(Throwable t) {
if (logLevel <= Log.WARN && t != null) {
log(Log.WARN, t);
}
log(Log.WARN, t);
}

/**
* Send a verbose log message.
*
* @param s The message you would like logged.
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public static void verbose(String s) {
if (logLevel <= Log.VERBOSE && s != null) {
log(Log.VERBOSE, s);
}
log(Log.VERBOSE, s);
}

/**
* Send a debug log message.
*
* @param s The message you would like logged.
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public static void debug(String s) {
if (logLevel <= Log.DEBUG && s != null) {
log(Log.DEBUG, s);
}
log(Log.DEBUG, s);
}

/**
* Send a debug log message.
*
* @param s The message you would like logged.
* @param t An exception to log
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public static void debug(String s, Throwable t) {
if (logLevel <= Log.DEBUG && s != null && t != null) {
log(Log.DEBUG, s, t);
}
log(Log.DEBUG, s, t);
}

/**
* Send an info log message.
*
* @param s The message you would like logged.
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public static void info(String s) {
if (logLevel <= Log.INFO && s != null) {
log(Log.INFO, s);
}
log(Log.INFO, s);
}

/**
* Send an info log message.
*
* @param s The message you would like logged.
* @param t An exception to log
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public static void info(String s, Throwable t) {
if (logLevel <= Log.INFO && s != null && t != null) {
log(Log.INFO, s, t);
}
log(Log.INFO, s, t);
}

/**
* Send an error log message.
*
* @param s The message you would like logged.
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public static void error(String s) {
if (logLevel <= Log.ERROR && s != null) {
log(Log.ERROR, s);
}
log(Log.ERROR, s);
}

/**
* Send an error log message.
*
* @param t An exception to log
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public static void error(Throwable t) {
if (logLevel <= Log.ERROR && t != null) {
log(Log.ERROR, t);
}
log(Log.ERROR, t);
}

/**
* Send an error log message.
*
* @param s The message you would like logged.
* @param t An exception to log
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public static void error(String s, Throwable t) {
if (logLevel <= Log.ERROR && s != null && t != null) {
log(Log.ERROR, s, t);
}
log(Log.ERROR, s, t);
}

/**
Expand All @@ -201,7 +254,9 @@ public static void error(String s, Throwable t) {
* @param defaultValue Default value if the value is empty.
* @return The log level.
* @throws IllegalArgumentException
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
static int parseLogLevel(String value, int defaultValue) throws IllegalArgumentException {
if (UAStringUtil.isEmpty(value)) {
return defaultValue;
Expand Down Expand Up @@ -245,49 +300,19 @@ private static void log(int priority, @Nullable String message) {
}

private static void log(int priority, @Nullable String message, @Nullable Throwable throwable) {
if (message == null && throwable == null) {
return;
}

if (logLevel > priority) {
return;
}

String formattedMessage = UAStringUtil.isEmpty(message) ? "" : message;

// Call through to listeners
synchronized (listeners) {
for (LoggerListener listener : new ArrayList<>(listeners)) {
listener.onLog(priority, throwable, formattedMessage);
}
}

// Log directly if we do not have a throwable
if (throwable == null) {
if (priority == Log.ASSERT) {
Log.wtf(TAG, formattedMessage);
} else {
Log.println(priority, TAG, formattedMessage);
}
return;
}

// Log using one of the provided log methods
switch (priority) {
case Log.INFO:
Log.i(TAG, formattedMessage, throwable);
break;
case Log.DEBUG:
Log.d(TAG, formattedMessage, throwable);
break;
case Log.VERBOSE:
Log.v(TAG, formattedMessage, throwable);
break;
case Log.WARN:
Log.w(TAG, formattedMessage, throwable);
break;
case Log.ERROR:
Log.e(TAG, formattedMessage, throwable);
break;
case Log.ASSERT:
Log.wtf(TAG, formattedMessage, throwable);
break;
for (LoggerListener listener : listeners) {
listener.onLog(priority, throwable, formattedMessage);
}
}
}

0 comments on commit 31b6132

Please sign in to comment.