-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add common Logger module implementation (#21)
- Loading branch information
Roman
authored
Mar 20, 2020
1 parent
66ffa78
commit 2a09133
Showing
21 changed files
with
679 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
IS_ANDROID_PROJECT=false | ||
POM_ARTIFACT_ID=annotations-processor | ||
POM_ARTIFACT_GROUP_ID=com.mapbox.base | ||
POM_ARTIFACT_TITLE=Mapbox Annotations Processor | ||
POM_DESCRIPTION=Artifact that provides Mapbox module and plugin generators |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
IS_ANDROID_PROJECT=false | ||
POM_ARTIFACT_ID=annotations | ||
POM_ARTIFACT_GROUP_ID=com.mapbox.base | ||
POM_ARTIFACT_TITLE=Mapbox Annotations | ||
POM_DESCRIPTION=Artifact that provides Mapbox module and plugin annotations |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
IS_ANDROID_PROJECT=true | ||
POM_ARTIFACT_ID=common | ||
POM_ARTIFACT_GROUP_ID=com.mapbox.base | ||
POM_ARTIFACT_TITLE=Mapbox Common | ||
POM_DESCRIPTION=Artifact that provides Mapbox module and plugin contracts |
59 changes: 59 additions & 0 deletions
59
common/src/main/java/com/mapbox/base/common/logger/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,59 @@ | ||
package com.mapbox.base.common.logger | ||
|
||
import com.mapbox.base.common.logger.model.Message | ||
import com.mapbox.base.common.logger.model.Tag | ||
|
||
/** | ||
* Logger definition | ||
*/ | ||
interface Logger { | ||
/** | ||
* Send a verbose log message and log the exception. | ||
* | ||
* @param tag is [Tag] used to identify the source of a log message. It usually identifies | ||
* the class or activity where the log call occurs. | ||
* @param msg is [Message] you would like logged. | ||
* @param tr An exception to log | ||
*/ | ||
fun v(tag: Tag? = null, msg: Message, tr: Throwable? = null) | ||
|
||
/** | ||
* Send a debug log message and log the exception. | ||
* | ||
* @param tag is [Tag] used to identify the source of a log message. It usually identifies | ||
* the class or activity where the log call occurs. | ||
* @param msg is [Message] you would like logged. | ||
* @param tr An exception to log | ||
*/ | ||
fun d(tag: Tag? = null, msg: Message, tr: Throwable? = null) | ||
|
||
/** | ||
* Send an info log message and log the exception. | ||
* | ||
* @param tag is [Tag] used to identify the source of a log message. It usually identifies | ||
* the class or activity where the log call occurs. | ||
* @param msg is [Message] you would like logged. | ||
* @param tr An exception to log | ||
*/ | ||
fun i(tag: Tag? = null, msg: Message, tr: Throwable? = null) | ||
|
||
/** | ||
* Send a warning log message and log the exception. | ||
* | ||
* @param tag is [Tag] used to identify the source of a log message. It usually identifies | ||
* the class or activity where the log call occurs. | ||
* @param msg is [Message] you would like logged. | ||
* @param tr An exception to log | ||
*/ | ||
fun w(tag: Tag? = null, msg: Message, tr: Throwable? = null) | ||
|
||
/** | ||
* Send an error log message and log the exception. | ||
* | ||
* @param tag is [Tag] used to identify the source of a log message. It usually identifies | ||
* the class or activity where the log call occurs. | ||
* @param msg is [Message] you would like logged. | ||
* @param tr An exception to log | ||
*/ | ||
fun e(tag: Tag? = null, msg: Message, tr: Throwable? = null) | ||
} |
8 changes: 8 additions & 0 deletions
8
common/src/main/java/com/mapbox/base/common/logger/model/Message.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,8 @@ | ||
package com.mapbox.base.common.logger.model | ||
|
||
/** | ||
* Wrapper class for loggers message. | ||
* | ||
* @param message The message you would like logged. | ||
*/ | ||
data class Message(val message: String) |
9 changes: 9 additions & 0 deletions
9
common/src/main/java/com/mapbox/base/common/logger/model/Tag.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,9 @@ | ||
package com.mapbox.base.common.logger.model | ||
|
||
/** | ||
* Wrapper class for loggers tag. | ||
* | ||
* @param tag used to identify the source of a log message. It usually identifies | ||
* the class or activity where the log call occurs. | ||
*/ | ||
data class Tag(val tag: String) |
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 @@ | ||
/build |
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,39 @@ | ||
plugins { | ||
id("com.android.library") | ||
kotlin("android") | ||
kotlin("kapt") | ||
id("com.jaredsburrows.license") | ||
id("org.jetbrains.dokka-android") | ||
} | ||
|
||
android { | ||
compileSdkVersion(AndroidVersions.compileSdkVersion) | ||
|
||
defaultConfig { | ||
minSdkVersion(AndroidVersions.minSdkVersion) | ||
targetSdkVersion(AndroidVersions.targetSdkVersion) | ||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
} | ||
|
||
dependencies { | ||
compileOnly(project(":annotations")) | ||
kapt(project(":annotations-processor")) | ||
implementation(project(":common")) | ||
implementation(Dependencies.kotlin) | ||
|
||
/** | ||
* Required for @Keep annotation by the annotation-processor and the resulting generated code | ||
*/ | ||
implementation(Dependencies.annotations) | ||
|
||
testImplementation(Dependencies.junit) | ||
testImplementation(Dependencies.mockk) | ||
} | ||
|
||
project.apply { | ||
from("$rootDir/gradle/ktlint.gradle") | ||
from("$rootDir/gradle/lint.gradle") | ||
from("$rootDir/gradle/android-artifacts.gradle") | ||
from("$rootDir/gradle/bintray-publish.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,5 @@ | ||
IS_ANDROID_PROJECT=true | ||
POM_ARTIFACT_ID=logger | ||
POM_ARTIFACT_GROUP_ID=com.mapbox.common | ||
POM_ARTIFACT_TITLE=Mapbox Logger | ||
POM_DESCRIPTION=Artifact that provides Mapbox Logger module implementation |
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 @@ | ||
<manifest package="com.mapbox.common.logger" /> |
15 changes: 15 additions & 0 deletions
15
liblogger/src/main/java/com/mapbox/common/logger/LogEntry.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,15 @@ | ||
package com.mapbox.common.logger | ||
|
||
/** | ||
* Model of Log entry. | ||
* | ||
* @property tag The tag you would like your message will marked. | ||
* @property message The message you would like logged. | ||
* @property throwable The throwable you would like to log. | ||
* @constructor Creates an [LogEntry] | ||
*/ | ||
data class LogEntry( | ||
val tag: String?, | ||
val message: String, | ||
val throwable: Throwable? | ||
) |
49 changes: 49 additions & 0 deletions
49
liblogger/src/main/java/com/mapbox/common/logger/LogPriority.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,49 @@ | ||
@file:JvmName("LogPriority") | ||
|
||
package com.mapbox.common.logger | ||
|
||
import android.util.Log | ||
|
||
/** | ||
* Priority constant for the println method; use Logger.v | ||
* | ||
* This log priority will print all logs. | ||
*/ | ||
const val VERBOSE = Log.VERBOSE | ||
|
||
/** | ||
* Priority constant for the println method; use Logger.d. | ||
* | ||
* This log priority will print all logs except verbose. | ||
*/ | ||
const val DEBUG = Log.DEBUG | ||
|
||
/** | ||
* Priority constant for the println method; use Logger.i. | ||
* | ||
* This log priority will print all logs except verbose and debug. | ||
* | ||
*/ | ||
const val INFO = Log.INFO | ||
|
||
/** | ||
* Priority constant for the println method; use Logger.w. | ||
* | ||
* This log priority will print only warn and error logs. | ||
* | ||
*/ | ||
const val WARN = Log.WARN | ||
|
||
/** | ||
* Priority constant for the println method; use Logger.e. | ||
* | ||
* This log priority will print only error logs. | ||
*/ | ||
const val ERROR = Log.ERROR | ||
|
||
/** | ||
* Priority constant for the println method. | ||
* | ||
* This log priority won't print any logs. | ||
*/ | ||
const val NONE = 99 |
17 changes: 17 additions & 0 deletions
17
liblogger/src/main/java/com/mapbox/common/logger/LoggerObserver.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,17 @@ | ||
package com.mapbox.common.logger | ||
|
||
import com.mapbox.common.logger.annotations.LogLevel | ||
|
||
/** | ||
* Interface for observe logs we want to catch | ||
*/ | ||
interface LoggerObserver { | ||
|
||
/** | ||
* Calls when [MapboxLogger] was log any [LogEntry]. | ||
* | ||
* @param level is [LogLevel] used to identify the level of logged [LogEntry] | ||
* @param entry is logged [LogEntry]. | ||
*/ | ||
fun log(@LogLevel level: Int, entry: LogEntry) | ||
} |
Oops, something went wrong.