Skip to content

Commit

Permalink
Merge pull request #2 from philips77/fixes
Browse files Browse the repository at this point in the history
Minor improvements
  • Loading branch information
LionZXY authored Jun 28, 2024
2 parents b74f158 + a99b5a1 commit 244c966
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 37 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ artifacts to your project and use `slf4j` like before:
```kotlin
import com.sun.org.slf4j.internal.LoggerFactory

public class YourClass {
class YourClass {
private val logger = LoggerFactory.getLogger(YourClass::class.java)

fun yourMethod() {
Expand All @@ -49,12 +49,12 @@ Download [the latest AAR][4] or grab it via Maven:
or Gradle Kotlin DSL:

```kotlin
implementation("com.arcao:slf4j2-timber:1.0")
implementation("uk.kulikov:slf4j2-timber:1.0")
```
or Gradle Groovy:

```groovy
implementation 'com.arcao:slf4j2-timber:1.0'
implementation 'uk.kulikov:slf4j2-timber:1.0'
```

> Note: `timber` and `slf4j-api` are the transitive dependencies of `slf4j2-timber`,
Expand Down
5 changes: 3 additions & 2 deletions slf4j2-timber/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ android {
}

dependencies {
implementation(libs.slf4j)
implementation(libs.timber)
// Transitive dependencies
api(libs.slf4j)
api(libs.timber)

testImplementation(libs.festandroid)
testImplementation(libs.festassert)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,46 @@ import timber.log.Timber
/**
*
* A simple implementation that delegates all log requests to the Timber
* logging facilities. Note that this logger does not support [org.slf4j.Marker].
* logging facilities.
*
* Note that this logger does not support [org.slf4j.Marker].
*
* Methods taking marker data as parameter simply invoke the eponymous method
* without the Marker argument, discarding any marker data in the process.
*
*
* The logging levels specified for SLF4J can be almost directly mapped to
* the logging method that exist in Timber. The following table
* shows the mapping implemented by this logger.
*
* <table border="1">
* <tr><th>**SLF4J******</th><th>**Timber**</th></tr>
* <tr><td>TRACE</td><td>Timber.v(...)</td></tr>
* <tr><td>DEBUG</td><td>Timber.d(...)</td></tr>
* <tr><td>INFO</td><td>Timber.i(...)</td></tr>
* <tr><td>WARN</td><td>Timber.w(...)</td></tr>
* <tr><td>ERROR</td><td>Timber.e(...)</td></tr>
</table> *
* | **SLF4J** | **Timber** |
* | ----------| ------------- |
* | TRACE | Timber.v(...) |
* | DEBUG | Timber.d(...) |
* | INFO | Timber.i(...) |
* | WARN | Timber.w(...) |
* | ERROR | Timber.e(...) |
*
*
* Use loggers as usual:
*
* *
* Declare a logger<br></br>
* `private static final Logger logger = LoggerFactory.getLogger(MyClass.class);`
*
* *
* Invoke logging methods, e.g.,<br></br>
* `logger.debug("Some log message. Details: {}", someObject);`<br></br>
* `logger.debug("Some log message with varargs. Details: {}, {}, {}", someObject1, someObject2, someObject3);`
*
*
*
* * Declare a logger:
* ```java
* private static final Logger logger = LoggerFactory.getLogger(MyClass.class);
* ```
*
* * Invoke logging methods, e.g.:
* ```java
* logger.debug("Some log message. Details: {}", someObject);
* logger.debug("Some log message with varargs. Details: {}, {}, {}", someObject1, someObject2, someObject3);
* ```
*
* Logger instances created using the LoggerFactory are named either according to the name
* or the fully qualified class name of the class given as a parameter.
* Each logger name will be used as the tag for Timber if Timber has planted [timber.log.Timber.TaggedTree].
* Each logger name will be used as the tag for Timber if Timber has planted [timber.log.Timber.Tree].
* If tag contains also class package, it will be removed (same way like in [timber.log.Timber.DebugTree]).
*
*
* @author Martin Sloup <arcao></arcao>@arcao.com>
* @author Nikita Kulikov <a href="https://kulikov.uk">kulikov.uk</a>
* @author Martin Sloup <a href="https://arcao.com">arcao.com</a>
*/
internal class TimberLoggerAdapter(tag: String?) : MarkerIgnoringBase() {
private enum class LogType {
Expand All @@ -58,10 +57,6 @@ internal class TimberLoggerAdapter(tag: String?) : MarkerIgnoringBase() {
ERROR
}

/**
* Package access allows only [AndroidLoggerFactory] to instantiate
* SimpleLogger instances.
*/
init {
this.name = tag
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import java.util.regex.Pattern
* TimberLoggerFactory is an implementation of [ILoggerFactory] returning
* the appropriately named [org.slf4j.LoggerFactory] instance.
*
* @author Martin Sloup <arcao></arcao>@arcao.com>
* @author Nikita Kulikov <a href="https://kulikov.uk">kulikov.uk</a>
* @author Martin Sloup <a href="https://arcao.com">arcao.com</a>
*/
class TimberLoggerFactory : ILoggerFactory {
private val loggerMap: ConcurrentMap<String, Logger> = ConcurrentHashMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import org.slf4j.spi.SLF4JServiceProvider
* The binding of [org.slf4j.LoggerFactory] class with an actual instance of
* [ILoggerFactory] is performed using information returned by this class.
*
* @author Martin Sloup <arcao></arcao>@arcao.com>
* @author Nikita Kulikov <a href="https://kulikov.uk">kulikov.uk</a>
* @author Martin Sloup <a href="https://arcao.com">arcao.com</a>
*/
class TimberLoggerServiceProvider : SLF4JServiceProvider {
private val loggerFactory: ILoggerFactory = TimberLoggerFactory()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package uk.kulikov.slf4j2.timber

import android.util.Log
import org.fest.assertions.api.Assertions.assertThat
import java.util.List
import org.junit.After
import org.junit.Before
import org.junit.Test
Expand All @@ -13,7 +13,6 @@ import org.robolectric.shadows.ShadowLog.LogItem
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import timber.log.Timber
import android.util.Log

@RunWith(RobolectricTestRunner::class)
@Config(manifest = Config.NONE)
Expand Down

0 comments on commit 244c966

Please sign in to comment.