-
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.
chore: merge branch 'feature/logger-android' into develop
- Loading branch information
Showing
107 changed files
with
6,441 additions
and
250 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
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,51 @@ | ||
plugins { | ||
id("com.android.library") | ||
kotlin("android") | ||
id("maven-publish") | ||
} | ||
|
||
android { | ||
compileSdk = 33 | ||
buildToolsVersion = "33.0.0" | ||
|
||
defaultConfig { | ||
minSdk = 14 | ||
targetSdk = 33 | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles("consumer-rules.pro") | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
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"]) | ||
} | ||
} | ||
} | ||
} |
Empty file.
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,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 |
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.