Skip to content

Commit

Permalink
Make log level configurable
Browse files Browse the repository at this point in the history
Also:
* Upgrade gradle plugin, target versions, etc.

Fixes #3
  • Loading branch information
jasonwyatt committed Aug 20, 2018
1 parent 6a4ca4f commit 36fdd7e
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 28 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -14,6 +15,7 @@ buildscript {

allprojects {
repositories {
google()
jcenter()
}
}
Expand Down
19 changes: 9 additions & 10 deletions example-todo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
compileSdkVersion 27

defaultConfig {
applicationId "co.jasonwyatt.squeakytodo"
minSdkVersion 16
targetSdkVersion 25
targetSdkVersion 27
versionCode 1
versionName "1.0"

Expand All @@ -23,13 +22,13 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':library')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.yarolegovich:lovely-dialog:1.0.4'
testCompile 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.yarolegovich:lovely-dialog:1.0.4'
testImplementation 'junit:junit:4.12'
}
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 Nov 23 14:03:49 CET 2016
#Mon Aug 20 09:48:52 MDT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
19 changes: 9 additions & 10 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,30 @@ apply plugin: 'com.github.dcendents.android-maven'
group='com.github.jasonwyatt'

android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
compileSdkVersion 25

defaultConfig {
minSdkVersion 15
targetSdkVersion 24
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-annotations:24.2.1'
api fileTree(dir: 'libs', include: ['*.jar'])
api 'com.android.support:support-annotations:27.1.1'

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile 'junit:junit:4.12'
androidTestCompile "org.assertj:assertj-core:1.7.0"
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation "org.assertj:assertj-core:1.7.0"

testCompile 'junit:junit:4.12'
testImplementation 'junit:junit:4.12'
//noinspection GradleDynamicVersion
testCompile "org.mockito:mockito-core:1.+"
testImplementation "org.mockito:mockito-core:1.+"
}

// build a jar with source files
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.bandcamp.squeaky"/>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="co.jasonwyatt.squeaky"/>
5 changes: 5 additions & 0 deletions library/src/main/java/co/jasonwyatt/squeaky/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import android.util.Log;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -421,6 +422,10 @@ public SQLiteDatabase getReadableDB() {
return mReadableDB;
}

public void setLogLevel(@Logger.LogLevel int level) {
Logger.setLevel(level);
}

/**
* {@link Table} definition used to define the SQLite table which tracks the current versions of
* all other {@link Table}s in the database.
Expand Down
48 changes: 44 additions & 4 deletions library/src/main/java/co/jasonwyatt/squeaky/util/Logger.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package co.jasonwyatt.squeaky.util;

import android.database.Cursor;
import android.support.annotation.IntDef;
import android.util.Log;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;

import co.jasonwyatt.squeaky.Database;
import co.jasonwyatt.squeaky.Table;
Expand All @@ -12,44 +16,80 @@
* Created by jason on 2/25/15.
*/
public class Logger {
@Retention(RetentionPolicy.SOURCE)
@IntDef({Log.ASSERT, Log.DEBUG, Log.ERROR, Log.INFO, Log.VERBOSE, Log.WARN})
public @interface LogLevel {}

public static final String TAG = "Squeaky";
private static boolean sEnabled = true;

private static AtomicInteger sLogLevel = new AtomicInteger(Log.VERBOSE);

/**
* Gets whether or not the logger is enabled.
* @return True if logger is enabled.
* @deprecated Use {@link #enabled(int)} instead.
*/
@Deprecated
public static boolean enabled() {
return sEnabled;
return enabled(Log.DEBUG);
}

/**
* Gets whether or not the logger is enabled at the specified priority..
* @param level Level of logging to test against.
* @return True if it's enabled.
*/
public static boolean enabled(@LogLevel int level) {
return sEnabled && sLogLevel.get() <= level;
}

public static void setEnabled(boolean enabled) {
sEnabled = enabled;
}

public static void setLevel(@LogLevel int level) {
sLogLevel.set(level);
}

public static void d(Object...pieces) {
if (!enabled()) {
if (!enabled(Log.DEBUG)) {
return;
}
Log.d(TAG, join(pieces));
}

public static void e(Object...pieces) {
if (!enabled(Log.ERROR)) {
return;
}
Log.e(TAG, join(pieces));
}

public static void e(Throwable err, Object...pieces) {
if (!enabled(Log.ERROR)) {
return;
}
Log.e(TAG, join(pieces), err);
}

public static void i(Object...pieces) {
if (!enabled()) {
if (!enabled(Log.INFO)) {
return;
}
Log.i(TAG, join(pieces));
}

public static void w(Object...pieces) {
if (!enabled(Log.WARN)) {
return;
}
Log.w(TAG, join(pieces));
}

public static void w(Throwable err, Object...pieces) {
if (!enabled(Log.WARN)) {
return;
}
Log.w(TAG, join(pieces), err);
}

Expand Down

0 comments on commit 36fdd7e

Please sign in to comment.