Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
MFlisar committed Oct 24, 2023
1 parent 0179d9d commit 2329fae
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 59 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
### Lumberjack [![Release](https://jitpack.io/v/MFlisar/Lumberjack.svg)](https://jitpack.io/#MFlisar/Lumberjack)
### About

[![Release](https://jitpack.io/v/MFlisar/Lumberjack.svg)](https://jitpack.io/#MFlisar/Lumberjack)
![License](https://img.shields.io/github/license/MFlisar/Lumberjack)

### What does it do?

A simple logger for JackWhartons [Timber](https://github.com/JakeWharton/timber) logging library (v4!) with following *features*:
A simple logger for *Jack Whartons* [Timber](https://github.com/JakeWharton/timber) logging library (v4!) with following *features*:

* trees for:
* logging to console (with the ability to add clickable links to the calling line in the calling class)
* files (one file per day, select between numbered log file names or date based log file names)
* customise each tree to whatever you want or extend them or add your own tree
* little utility class to log time and laps (the `T` class)
* by default, this library will create tags if no custom tag is provided like "[CLASSNAME:LINE] FUNCTION" e.g. `[MainActivity:32 onCreate]: Some log`
* by default, this library will create tags if no custom tag is provided like **[CLASSNAME:LINE] FUNCTION** e.g. `[MainActivity:32 onCreate]: Some log`
* feedback module that contains extension functions for `L` to send feedback or to show a notification that will send a feedback on click:
* `L.sendFeedback()`... sends a feedback via IntentChooser with an optional files appended
* notification module that contains functions to show info/error notifications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object CoreUtil {
return darkness >= 0.5
}

internal fun Int.getDarknessFactor(): Double {
private fun Int.getDarknessFactor(): Double {
return 1 - (0.299 * Color.red(this) + 0.587 * Color.green(this) + 0.114 * Color.blue(this)) / 255
}
}
103 changes: 52 additions & 51 deletions library/src/main/java/timber/log/BaseTree.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ abstract class BaseTree : Timber.Tree() {

// we overwrite all log functions because the base classes Timber.prepareLog is private and we need to make a small adjustment
// to get correct line numbers for kotlin exceptions (only the IDE does convert the line limbers correctly based on a mapping table)

override fun v(message: String?, vararg args: Any?) {
prepareLog(
Log.VERBOSE,
null,
message,
*args
Log.VERBOSE,
null,
message,
*args
)
}

override fun v(t: Throwable?, message: String?, vararg args: Any?) {
prepareLog(
Log.VERBOSE,
t,
message,
*args
Log.VERBOSE,
t,
message,
*args
)
}

Expand All @@ -39,10 +39,10 @@ abstract class BaseTree : Timber.Tree() {

override fun d(t: Throwable?, message: String?, vararg args: Any?) {
prepareLog(
Log.DEBUG,
t,
message,
*args
Log.DEBUG,
t,
message,
*args
)
}

Expand All @@ -56,10 +56,10 @@ abstract class BaseTree : Timber.Tree() {

override fun i(t: Throwable?, message: String?, vararg args: Any?) {
prepareLog(
Log.INFO,
t,
message,
*args
Log.INFO,
t,
message,
*args
)
}

Expand All @@ -73,10 +73,10 @@ abstract class BaseTree : Timber.Tree() {

override fun w(t: Throwable?, message: String?, vararg args: Any?) {
prepareLog(
Log.WARN,
t,
message,
*args
Log.WARN,
t,
message,
*args
)
}

Expand All @@ -90,10 +90,10 @@ abstract class BaseTree : Timber.Tree() {

override fun e(t: Throwable?, message: String?, vararg args: Any?) {
prepareLog(
Log.ERROR,
t,
message,
*args
Log.ERROR,
t,
message,
*args
)
}

Expand All @@ -103,19 +103,19 @@ abstract class BaseTree : Timber.Tree() {

override fun wtf(message: String?, vararg args: Any?) {
prepareLog(
Log.ASSERT,
null,
message,
*args
Log.ASSERT,
null,
message,
*args
)
}

override fun wtf(t: Throwable?, message: String?, vararg args: Any?) {
prepareLog(
Log.ASSERT,
t,
message,
*args
Log.ASSERT,
t,
message,
*args
)
}

Expand All @@ -125,19 +125,19 @@ abstract class BaseTree : Timber.Tree() {

override fun log(priority: Int, message: String?, vararg args: Any?) {
prepareLog(
priority,
null,
message,
*args
priority,
null,
message,
*args
)
}

override fun log(priority: Int, t: Throwable?, message: String?, vararg args: Any?) {
prepareLog(
priority,
t,
message,
*args
priority,
t,
message,
*args
)
}

Expand Down Expand Up @@ -198,27 +198,28 @@ abstract class BaseTree : Timber.Tree() {
}

final override fun log(
priority: Int,
tag: String?,
message: String,
t: Throwable?
priority: Int,
tag: String?,
message: String,
t: Throwable?
) {
/* empty, we use our own function with StackData */
}

abstract fun log(
priority: Int,
prefix: String,
message: String,
t: Throwable?,
stackData: StackData
priority: Int,
prefix: String,
message: String,
t: Throwable?,
stackData: StackData
)

// --------------------
// custom code - extended tag
// --------------------

protected fun formatLine(prefix: String, message: String) = L.formatter.formatLine(this, prefix, message)
protected fun formatLine(prefix: String, message: String) =
L.formatter.formatLine(this, prefix, message)

// --------------------
// custom code - extended tag
Expand Down
9 changes: 5 additions & 4 deletions library/src/main/java/timber/log/ConsoleTree.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ class ConsoleTree(
t: Throwable?,
stackData: StackData
) {


val msg = if (replaceBracketsIfAppendableLinks && appendClickableLink) message.replace("(", "{").replace(")", "}") else message
val msg = if (replaceBracketsIfAppendableLinks && appendClickableLink) {
message
.replace("(", "{")
.replace(")", "}")
} else message
val fullMessage = if (appendClickableLink) appendLink(msg, stackData) else msg


if (fullMessage.length < MAX_LOG_LENGTH) {
logLine(priority, prefix, fullMessage)
return
Expand Down

0 comments on commit 2329fae

Please sign in to comment.