Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kotlin/logging #89

Open
wants to merge 9 commits into
base: feature/kotlin
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ext {
compileSdk : 28,
appcompat : '1.0.2',
androidx : '1.0.0',
fragment : '1.1.0',
material : '1.0.0',
lifecycle : '2.0.0',
dagger : '2.17',
Expand Down
3 changes: 3 additions & 0 deletions logging/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion versions.compileSdk
Expand All @@ -14,5 +16,6 @@ android {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.annotation:annotation:$versions.androidx"
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2019 RoboSwag (Gavriil Sitnikov, Vsevolod Ivanov)
*
* This file is part of RoboSwag library.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package ru.touchin.roboswag.core.log

import android.util.Log

/**
* Simple [LogProcessor] implementation which is logging messages to console (logcat).
*/
class ConsoleLogProcessor(lclevel: LcLevel) : LogProcessor(lclevel) {

companion object {
private const val MAX_LOG_LENGTH = 4000
}

@SuppressWarnings("WrongConstant", "LogConditional")
//WrongConstant, LogConditional: level.getPriority() is not wrong constant!
override fun processLogMessage(
group: LcGroup,
level: LcLevel,
tag: String,
message: String,
throwable: Throwable?
) {
message.plus(throwable?.let { "\n${Log.getStackTraceString(throwable)}" }.orEmpty())
.normalize()
.split('\n')
.map { msg -> msg.chunked(MAX_LOG_LENGTH) }
.flatten()
.forEach { msg ->
Log.println(level.priority, tag, msg)
}
}

private fun String.normalize(): String = this
.replace("\r\n", "\n")
.replace("\u0000", "")

}
Loading