Skip to content

Commit

Permalink
Add common Logger module implementation (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman authored Mar 20, 2020
1 parent 66ffa78 commit 2a09133
Show file tree
Hide file tree
Showing 21 changed files with 679 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ commands:
steps:
- restore_cache:
keys:
- v1-dependencies-{{ checksum "build.gradle.kts" }}-{{ checksum "annotations/build.gradle.kts" }}-{{ checksum "annotations-processor/build.gradle.kts" }}-{{ checksum "common/build.gradle.kts" }}
- v1-dependencies-{{ checksum "build.gradle.kts" }}-{{ checksum "annotations/build.gradle.kts" }}-{{ checksum "annotations-processor/build.gradle.kts" }}-{{ checksum "common/build.gradle.kts" }}-{{ checksum "liblogger/build.gradle.kts" }}
- v1-dependencies-
- run:
name: Download dependencies
command: ./gradlew dependencies
- save_cache:
paths:
- ~/.gradle
key: v1-dependencies-{{ checksum "build.gradle.kts" }}-{{ checksum "annotations/build.gradle.kts" }}-{{ checksum "annotations-processor/build.gradle.kts" }}-{{ checksum "common/build.gradle.kts" }}
key: v1-dependencies-{{ checksum "build.gradle.kts" }}-{{ checksum "annotations/build.gradle.kts" }}-{{ checksum "annotations-processor/build.gradle.kts" }}-{{ checksum "common/build.gradle.kts" }}-{{ checksum "liblogger/build.gradle.kts" }}

run-unit-tests:
steps:
Expand Down
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,30 @@ check:
buildDebug:
./gradlew annotations:assemble && \
./gradlew annotations-processor:assemble && \
./gradlew common:assembleDebug
./gradlew common:assembleDebug && \
./gradlew liblogger:assembleDebug

.PHONY: buildRelease
buildRelease:
./gradlew annotations:assemble && \
./gradlew annotations-processor:assemble && \
./gradlew common:assembleRelease
./gradlew common:assembleRelease && \
./gradlew liblogger:assembleRelease

.PHONY: bintrayPublish
bintrayPublish:
./gradlew :annotations:bintrayUpload ; \
./gradlew :annotations-processor:bintrayUpload ; \
./gradlew :common:bintrayUpload ; \
./gradlew :liblogger:bintrayUpload ; \

.PHONY: artifactoryPublish
artifactoryPublish:
./gradlew :annotations:artifactoryPublish ; \
./gradlew :annotations-processor:artifactoryPublish ; \
./gradlew :common:artifactoryPublish ; \
./gradlew :liblogger:artifactoryPublish ; \

.PHONY: runUnitTests
runUnitTests:
./gradlew examples:test
./gradlew test
1 change: 1 addition & 0 deletions annotations-processor/gradle.properties
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
1 change: 1 addition & 0 deletions annotations/gradle.properties
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
1 change: 1 addition & 0 deletions common/gradle.properties
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 common/src/main/java/com/mapbox/base/common/logger/Logger.kt
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)
}
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)
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)
2 changes: 1 addition & 1 deletion gradle/artifact-settings.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ext {
mapboxArtifactGroupId = 'com.mapbox.base'
mapboxArtifactGroupId = project.property('POM_ARTIFACT_GROUP_ID')
mapboxArtifactId = project.property('POM_ARTIFACT_ID')
mapboxArtifactTitle = project.property('POM_ARTIFACT_TITLE')
mapboxArtifactDescription = project.property('POM_DESCRIPTION')
Expand Down
2 changes: 1 addition & 1 deletion gradle/bintray-publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bintray {
publications('MapboxBasePublication')
pkg {
repo = project.ext.mapboxBintrayRepoName
name = project.ext.mapboxArtifactId
name = group + ':' + project.ext.mapboxArtifactId
userOrg = project.ext.mapboxBintrayUserOrg
licenses = [project.ext.mapboxArtifactLicenseName]
vcsUrl = project.ext.mapboxArtifactVcsUrl
Expand Down
1 change: 1 addition & 0 deletions liblogger/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
39 changes: 39 additions & 0 deletions liblogger/build.gradle.kts
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")
}
5 changes: 5 additions & 0 deletions liblogger/gradle.properties
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
1 change: 1 addition & 0 deletions liblogger/src/main/AndroidManifest.xml
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 liblogger/src/main/java/com/mapbox/common/logger/LogEntry.kt
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 liblogger/src/main/java/com/mapbox/common/logger/LogPriority.kt
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 liblogger/src/main/java/com/mapbox/common/logger/LoggerObserver.kt
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)
}
Loading

0 comments on commit 2a09133

Please sign in to comment.