-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
136 changed files
with
9,152 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build | ||
.gradle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
plugins { | ||
id("com.android.library") | ||
kotlin("android") | ||
id("maven-publish") | ||
} | ||
|
||
android { | ||
compileSdk = 33 | ||
buildToolsVersion = "33.0.0" | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_11 | ||
targetCompatibility = JavaVersion.VERSION_11 | ||
} | ||
kotlinOptions { | ||
apiVersion = "1.7" | ||
languageVersion = "1.7" | ||
jvmTarget = "11" | ||
} | ||
} | ||
|
||
afterEvaluate { | ||
publishing { | ||
publications { | ||
create<MavenPublication>("release") { | ||
groupId = "com.parsuomash.affogato" | ||
artifactId = "affogato-logger-android" | ||
version = "1.5.0" | ||
|
||
from(components["release"]) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="com.parsuomash.affogato.logger.android" /> |
34 changes: 34 additions & 0 deletions
34
affogato-logger-android/src/main/java/com/parsuomash/affogato/logger/android/Ktx.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.parsuomash.affogato.logger.android | ||
|
||
/** | ||
* ### Top-level logging. | ||
* | ||
* Example : | ||
* ```kotlin | ||
* logcat { "Hello, Napier" } | ||
* logcat(tag = "your tag") { "Hello, Napier" } | ||
* ``` | ||
* @since 1.5.0 | ||
* @param priority enum: The priority/type of this log message Value is ASSERT, | ||
* ERROR, WARN, INFO, DEBUG, or VERBOSE | ||
* @param throwable Throwable: An exception to log This value may be null. | ||
* @param tag String: Used to identify the source of a log message. It usually | ||
* identifies the class or activity where the log call occurs. This value may be null. | ||
* @param message Lambda: The message you would like logged. This value cannot be null. | ||
* @see Logger | ||
*/ | ||
inline fun logcat( | ||
priority: LogLevel = LogLevel.DEBUG, | ||
throwable: Throwable? = null, | ||
tag: String? = null, | ||
message: () -> Any?, | ||
) { | ||
when (priority) { | ||
LogLevel.ASSERT -> Logger.assert(tag, message().toString(), throwable) | ||
LogLevel.VERBOSE -> Logger.verbose(tag, message().toString(), throwable) | ||
LogLevel.DEBUG -> Logger.debug(tag, message().toString(), throwable) | ||
LogLevel.INFO -> Logger.info(tag, message().toString(), throwable) | ||
LogLevel.WARN -> Logger.warn(tag, message().toString(), throwable) | ||
LogLevel.ERROR -> Logger.error(tag, message().toString(), throwable) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
affogato-logger-android/src/main/java/com/parsuomash/affogato/logger/android/LogLevel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.parsuomash.affogato.logger.android | ||
|
||
/** | ||
* LogLevel show priority of log message. | ||
* @since 1.5.0 | ||
* @see Logger | ||
*/ | ||
enum class LogLevel { | ||
VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT | ||
} |
165 changes: 165 additions & 0 deletions
165
affogato-logger-android/src/main/java/com/parsuomash/affogato/logger/android/Logger.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
@file:Suppress("MemberVisibilityCanBePrivate") | ||
|
||
package com.parsuomash.affogato.logger.android | ||
|
||
import android.util.Log | ||
|
||
/** | ||
* Logging class for manage logcat in debug/release mode. | ||
* | ||
* Example: | ||
* ```kotlin | ||
* with(Logger) { | ||
* tag = "Tick" | ||
* isDebug = BuildConfig.DEBUG | ||
* onRelease = { tag, message, throwable -> | ||
* if (tag != null) { | ||
* YandexMetrica.reportError(tag, message, throwable) | ||
* } else { | ||
* YandexMetrica.reportError(message, throwable) | ||
* } | ||
* } | ||
* Logger.info(message = "Hello world!") | ||
* ``` | ||
* @since 1.5.0 | ||
* @see logcat | ||
*/ | ||
object Logger { | ||
/** | ||
* Logging tag help for beter filter and search. | ||
* @since 1.5.0 | ||
*/ | ||
var tag: String = "Logger" | ||
|
||
/** | ||
* When is true printing logs, otherwise run onRelease block. | ||
* @since 1.5.0 | ||
*/ | ||
var isDebug: Boolean = true | ||
|
||
/** | ||
* With onRelease block we define our api for logging in release mode like use crash service. | ||
* @since 1.5.0 | ||
*/ | ||
var onRelease: ((tag: String?, message: String, throwable: Throwable) -> Unit)? = null | ||
|
||
/** | ||
* Send a VERBOSE log message and log the exception. | ||
* @since 1.5.0 | ||
* @param message String: The message you would like logged. This value cannot be null. | ||
* @param throwable Throwable: An exception to log This value may be null. | ||
* @param tag String: Used to identify the source of a log message. It usually | ||
* identifies the class or activity where the log call occurs. This value may be null. | ||
*/ | ||
fun verbose(tag: String?, message: String, throwable: Throwable?) { | ||
if (isDebug) { | ||
if (throwable != null) { | ||
Log.v(tag ?: Logger.tag, message, throwable) | ||
} else { | ||
Log.v(tag ?: Logger.tag, message) | ||
} | ||
} else if (throwable != null && onRelease != null) { | ||
onRelease!!.invoke(tag, message, throwable) | ||
} | ||
} | ||
|
||
/** | ||
* Send a DEBUG log message and log the exception. | ||
* @since 1.5.0 | ||
* @param message String: The message you would like logged. This value cannot be null. | ||
* @param throwable Throwable: An exception to log This value may be null. | ||
* @param tag String: Used to identify the source of a log message. It usually | ||
* identifies the class or activity where the log call occurs. This value may be null. | ||
*/ | ||
fun debug(tag: String?, message: String, throwable: Throwable?) { | ||
if (isDebug) { | ||
if (throwable != null) { | ||
Log.d(tag ?: Logger.tag, message, throwable) | ||
} else { | ||
Log.d(tag ?: Logger.tag, message) | ||
} | ||
} else if (throwable != null && onRelease != null) { | ||
onRelease!!.invoke(tag, message, throwable) | ||
} | ||
} | ||
|
||
/** | ||
* Send a INFO log message and log the exception. | ||
* @since 1.5.0 | ||
* @param message String: The message you would like logged. This value cannot be null. | ||
* @param throwable Throwable: An exception to log This value may be null. | ||
* @param tag String: Used to identify the source of a log message. It usually | ||
* identifies the class or activity where the log call occurs. This value may be null. | ||
*/ | ||
fun info(tag: String?, message: String, throwable: Throwable?) { | ||
if (isDebug) { | ||
if (throwable != null) { | ||
Log.i(tag ?: Logger.tag, message, throwable) | ||
} else { | ||
Log.i(tag ?: Logger.tag, message) | ||
} | ||
} else if (throwable != null && onRelease != null) { | ||
onRelease!!.invoke(tag, message, throwable) | ||
} | ||
} | ||
|
||
/** | ||
* Send a WARN log message and log the exception. | ||
* @since 1.5.0 | ||
* @param message String: The message you would like logged. This value cannot be null. | ||
* @param throwable Throwable: An exception to log This value may be null. | ||
* @param tag String: Used to identify the source of a log message. It usually | ||
* identifies the class or activity where the log call occurs. This value may be null. | ||
*/ | ||
fun warn(tag: String?, message: String, throwable: Throwable?) { | ||
if (isDebug) { | ||
if (throwable != null) { | ||
Log.w(tag ?: Logger.tag, message, throwable) | ||
} else { | ||
Log.w(tag ?: Logger.tag, message) | ||
} | ||
} else if (throwable != null && onRelease != null) { | ||
onRelease!!.invoke(tag, message, throwable) | ||
} | ||
} | ||
|
||
/** | ||
* Send a ERROR log message and log the exception. | ||
* @since 1.5.0 | ||
* @param message String: The message you would like logged. This value cannot be null. | ||
* @param throwable Throwable: An exception to log This value may be null. | ||
* @param tag String: Used to identify the source of a log message. It usually | ||
* identifies the class or activity where the log call occurs. This value may be null. | ||
*/ | ||
fun error(tag: String?, message: String, throwable: Throwable?) { | ||
if (isDebug) { | ||
if (throwable != null) { | ||
Log.e(tag ?: Logger.tag, message, throwable) | ||
} else { | ||
Log.e(tag ?: Logger.tag, message) | ||
} | ||
} else if (throwable != null && onRelease != null) { | ||
onRelease!!.invoke(tag, message, throwable) | ||
} | ||
} | ||
|
||
/** | ||
* What a Terrible Failure: Report an exception that should never happen. | ||
* @since 1.5.0 | ||
* @param message String: The message you would like logged. This value cannot be null. | ||
* @param throwable Throwable: An exception to log This value may be null. | ||
* @param tag String: Used to identify the source of a log message. It usually | ||
* identifies the class or activity where the log call occurs. This value may be null. | ||
*/ | ||
fun assert(tag: String?, message: String, throwable: Throwable?) { | ||
if (isDebug) { | ||
if (throwable != null) { | ||
Log.wtf(tag ?: Logger.tag, message, throwable) | ||
} else { | ||
Log.wtf(tag ?: Logger.tag, message) | ||
} | ||
} else if (throwable != null && onRelease != null) { | ||
onRelease!!.invoke(tag, message, throwable) | ||
} | ||
} | ||
} |
Oops, something went wrong.