Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modularize: separate the core SLF4J binding from the optional handlers #21

Merged
merged 14 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ repositories {
and then declare a dependency inside a module:
```groovy
dependencies {
compile('com.github.bright:slf4android:0.1.6'){
transitive = true
}
//other dependencies
// just SLF4J binding
implementation("com.github.bright.slf4android:slf4android:$slf4androidVersion")

// (optional) a handler for file logging
implementation("com.github.bright.slf4android:slf4android-handler-file-log:$slf4androidVersion")

// (optional) a handler for notifying the developer in case of an error
implementation("com.github.bright.slf4android:slf4android-handler-notify-developer:$slf4androidVersion")
}
```
As with any slf4j compatible implementation using slf4android looks like this:
Expand Down Expand Up @@ -77,7 +81,7 @@ Note that we remove a default logcat handler since Crashlytics will push message
### Logging to a file
To print messages to a separate file just add:
```java
FileLogHandlerConfiguration fileHandler = LoggerConfiguration.fileLogHandler(this);
FileLogHandlerConfiguration fileHandler = FileLogHandlerConfiguration.create(this);
LoggerConfiguration.configuration().addHandlerToRootLogger(fileHandler);
String logFileName = fileHandler.getCurrentFileName();
// logFileName contains full path to logged file
Expand All @@ -86,7 +90,7 @@ inside your custom `android.app.Application` `onCreate` method. This will create

To change the location of log file you can use:
```java
FileLogHandlerConfiguration fileHandler = LoggerConfiguration.fileLogHandler(this);
FileLogHandlerConfiguration fileHandler = FileLogHandlerConfiguration.create(this);

fileHandler.setFullFilePathPattern("/sdcard/your.package/my_log.%g.%u.log");

Expand Down
85 changes: 0 additions & 85 deletions app/build.gradle

This file was deleted.

14 changes: 0 additions & 14 deletions app/src/androidTest/AndroidManifest.xml

This file was deleted.

This file was deleted.

This file was deleted.

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 {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.2.0'
classpath 'com.android.tools.build:gradle:8.4.0'
//classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}
Expand Down
1 change: 1 addition & 0 deletions core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
64 changes: 64 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
plugins {
id 'com.android.library'
id 'maven-publish'
}

android {
namespace 'pl.brightinventions.slf4android'
compileSdk 34

defaultConfig {
minSdk 14

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

publishing {
singleVariant('release') {
withSourcesJar()
}
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
api 'org.slf4j:slf4j-api:1.7.36'

testImplementation('junit:junit:4.13.2')
testImplementation 'org.hamcrest:hamcrest-core:1.3'
testImplementation 'org.hamcrest:hamcrest-library:1.3'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

publishing {
publications {
release(MavenPublication) {
groupId = 'com.github.bright.slf4android'
artifactId = 'slf4android'
version = '1.0'

afterEvaluate {
from components.release
}
}
}
}
Empty file added core/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions core/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.brightinventions.slf4android.androidTest;
package pl.brightinventions.slf4android;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
Expand All @@ -13,9 +13,6 @@
import java.io.IOException;
import java.io.InputStreamReader;

import pl.brightinventions.slf4android.LogLevel;
import pl.brightinventions.slf4android.LoggerConfiguration;

public class LoggerAdapterTests {

public static final String LOGGER_NAME = "ApplicationTest";
Expand Down Expand Up @@ -141,7 +138,7 @@ public void test_error_message_printed_when_level_is_set_to_debug() {
@Test
public void test_warning_message_printed_when_level_is_set_to_debug() {
setLevelTo(LogLevel.DEBUG);
getLogger().error("new warning message with exception", new NullPointerException("Bad"));
getLogger().warn("new warning message with exception", new NullPointerException("Bad"));
assertThat(getLastMessage(), containsString("new warning message with exception"));
}
}
2 changes: 2 additions & 0 deletions core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest />
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class HandlerFormatterCompiler {
private final LoggerPatternConfiguration configuration;

public HandlerFormatterCompiler(LoggerPatternConfiguration configuration) {
HandlerFormatterCompiler(LoggerPatternConfiguration configuration) {
this.configuration = configuration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public boolean isSmallerOrEqualTo(Level level) {
}

/**
* Converts a {@link pl.brightinventions.slf4android.LogLevel} logging level into an Android one.
* Converts a {@link LogLevel} logging level into an Android one.
*
* @return The resulting Android logging level.
*/
Expand All @@ -42,9 +42,9 @@ public int getAndroidLevel() {
}

/**
* Converts a {@link pl.brightinventions.slf4android.LogLevel} logging level into a {@link java.util.logging.Level}.
* Converts a {@link LogLevel} logging level into a {@link Level}.
*
* @return The resulting {@link java.util.logging.Level}.
* @return The resulting {@link Level}.
*/
public Level getUtilLogLevel() {
return utilLogLevel;
Expand Down
Loading
Loading