Skip to content

Commit

Permalink
chore: merge branch 'feature/logger-android' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ghasemdev committed Aug 22, 2022
2 parents 8c3c793 + 2c37141 commit 6f4955b
Show file tree
Hide file tree
Showing 107 changed files with 6,441 additions and 250 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [🎉 1.5.0 Structure, Logger] - 2022-08-22

### 🚀 Features

* Add `logger-android` module
* `LogLevel` enum.
* `logcat` extension.
* Singleton `Logger`.

### 💥 Breaking Changes

* Rename checker class from **structure** module.

## [🎉 1.4.0 Structure, Metrica] - 2022-08-21

### 🚀 Features
Expand Down
33 changes: 29 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Version](https://shields.io/badge/VERSION-1.4.0-blue?style=for-the-badge)](https://github.com/ghasemdev/affogato/releases/tag/1.4.0)
[![Version](https://shields.io/badge/VERSION-1.5.0-blue?style=for-the-badge)](https://github.com/ghasemdev/affogato/releases/tag/1.5.0)
[![Kotlin](https://shields.io/badge/Kotlin-1.7.10-pink?style=for-the-badge)](https://kotlinlang.org/)
[![API](https://shields.io/badge/Api-+21-green?style=for-the-badge)](https://www.android.com/)
[![License MIT](https://shields.io/badge/LICENSE-MIT-orange?style=for-the-badge)](https://opensource.org/licenses/MIT)
Expand Down Expand Up @@ -41,6 +41,31 @@ suspend fun foo() = suspendedTryCatchNull {
}
```

### [Logger](https://github.com/ghasemdev/affogato/wiki/Logger)

Logger module contains a simple logger for Android. It's a wrapper for `Log` and`Logger` with some
extensions.

```Kotlin
// Setup
Logger.tag = "MyApp"

Logger.isDebug = BuildConfig.DEBUG // if debug mode false onRelease will be called.
Logger.onRealease = { tag, message, throwable ->
// do something
}

// Extension
logcat { "Hello Affogato" }
logcat(tag = "TAG") { "Hello Affogato" }
logcat(LogLevel.INFO) { "Hello Affogato" }
try {
// do something
} catch (e: Exception) {
logcat(throwable = e) { "Hello Affogato" }
}
```

### [Metrica-ktx](https://github.com/ghasemdev/affogato/wiki/Metrica-Ktx)

This module adds Yandex Metrica to your project. You can use it for crashlytics and reporting events
Expand Down Expand Up @@ -71,8 +96,8 @@ class SharedPref private constructor(private val context: Context) {
StringPool["key"] = "token"
StringPool["key"] // token

PhoneChecker("09123456789").isValid() // true
PhoneChecker("09123456789").format("IR") // +98 912 345 6789
Phone("09123456789").isValid() // true
Phone("09123456789").format("IR") // +98 912 345 6789
```

### [Compose Unit Size](https://github.com/ghasemdev/affogato/wiki/Unit-Size)
Expand All @@ -92,7 +117,7 @@ dimen.icon // 80.dp in device with width 480.dp
# Links

Affogato is currently available for maven/gradle builds
at [Jitpack](https://jitpack.io/#ghasemdev/affogato/1.4.0) (
at [Jitpack](https://jitpack.io/#ghasemdev/affogato/1.5.0) (
read [Getting started](https://github.com/ghasemdev/affogato/wiki/Getting-Started)).

* [Wiki](https://github.com/ghasemdev/affogato/wiki)
Expand Down
2 changes: 1 addition & 1 deletion affogato-core-ktx/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ afterEvaluate {
create<MavenPublication>("java") {
groupId = "com.parsuomash.affogato"
artifactId = "affogato-core-ktx"
version = "1.4.0"
version = "1.5.0"

from(components["java"])
}
Expand Down
2 changes: 1 addition & 1 deletion affogato-coroutines-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ afterEvaluate {
create<MavenPublication>("release") {
groupId = "com.parsuomash.affogato"
artifactId = "affogato-coroutines-android"
version = "1.4.0"
version = "1.5.0"

from(components["release"])
}
Expand Down
2 changes: 1 addition & 1 deletion affogato-coroutines-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ afterEvaluate {
create<MavenPublication>("java") {
groupId = "com.parsuomash.affogato"
artifactId = "affogato-coroutines-core"
version = "1.4.0"
version = "1.5.0"

from(components["java"])
}
Expand Down
2 changes: 2 additions & 0 deletions affogato-logger-android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
.gradle
51 changes: 51 additions & 0 deletions affogato-logger-android/build.gradle.kts
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.
21 changes: 21 additions & 0 deletions affogato-logger-android/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
2 changes: 2 additions & 0 deletions affogato-logger-android/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 package="com.parsuomash.affogato.logger.android" />
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)
}
}
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
}
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)
}
}
}
Loading

0 comments on commit 6f4955b

Please sign in to comment.