-
Notifications
You must be signed in to change notification settings - Fork 7
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
saifer2505
wants to merge
9
commits into
feature/kotlin
Choose a base branch
from
kotlin/logging
base: feature/kotlin
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
kotlin/logging #89
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
125b749
added versions.fragment
saifer2505 00d1c97
added Kotlin plugin
saifer2505 ba16c91
removed Java classes
saifer2505 65cd508
added Kotlin classes
saifer2505 40ab587
small fixes
saifer2505 77047a8
Merge remote-tracking branch 'origin/feature/kotlin' into kotlin/logging
saifer2505 a340f42
code review
saifer2505 341df57
code review
saifer2505 22b073c
removed SuppressWarnings
saifer2505 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
63 changes: 0 additions & 63 deletions
63
logging/src/main/java/ru/touchin/roboswag/core/log/ConsoleLogProcessor.java
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
logging/src/main/java/ru/touchin/roboswag/core/log/ConsoleLogProcessor.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,63 @@ | ||
/* | ||
* 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 | ||
import kotlin.math.min | ||
|
||
/** | ||
* 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 | ||
} | ||
|
||
private fun normalize(message: String): String = message | ||
.replace("\r\n", "\n") | ||
.replace("\u0000", "") | ||
|
||
@SuppressWarnings("WrongConstant", "LogConditional") | ||
//WrongConstant, LogConditional: level.getPriority() is not wrong constant! | ||
override fun processLogMessage( | ||
group: LcGroup, | ||
level: LcLevel, | ||
tag: String, | ||
message: String, | ||
throwable: Throwable? | ||
) { | ||
val messageToLog = normalize(message + if (throwable != null) '\n' + Log.getStackTraceString(throwable) else "") | ||
val length = messageToLog.length | ||
var i = 0 | ||
while (i < length) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Перепиши без циклов. В Kotlin стиле |
||
var newline = messageToLog.indexOf('\n', i) | ||
newline = if (newline != -1) newline else length | ||
do { | ||
val end = min(newline, i + MAX_LOG_LENGTH) | ||
Log.println(level.priority, tag, messageToLog.substring(i, end)) | ||
i = end | ||
} while (i < newline) | ||
i++ | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно сделать extension