Android log tool class to avoid incomplete log printing

Quick start

If you like the project, welcome Star, fork, and suggest improvements in issue

implementation 'the IO. Making. Sakurajimamaii: VastTools: 0.0.3'
Copy the code

summary

Private property

Param Name Param Class
logContent LogContent?
defaultByteLength Int
defaultMaxPrintTimes Int

Public attribute

Param Name Param Class
logEnabled Boolean
maxPrintTimes Int

Private methods

Returns Method
Unit fun logPrint(priority: Int,@Nullable key: String? ,@Nullable content: String? ,@Nullable clz: Class<*>?)
Unit fun print(priority: Int, tag: String, content: String)
String? fun cutStr(bytes: ByteArray?)

Public methods

Returns Method
Unit fun i(@Nullable clz: Class<*>? , @Nullable key: String? , @Nullable content: String?)
Unit fun v(@Nullable clz: Class<*>? , @Nullable key: String? , @Nullable content: String?)
Unit fun w(@Nullable clz: Class<*>? , @Nullable key: String? , @Nullable content: String?)
Unit fun e(@Nullable clz: Class<*>? , @Nullable key: String? , @Nullable content: String?)
Unit fun d(@Nullable clz: Class<*>? , @Nullable key: String? , @Nullable content: String?)
Unit fun setLogEnabled(logEnabled: Boolean)
Unit fun setLogContentFormat(logContent: LogContent)

Private property

logContent

To customize the output content format, see setLogContentFormat

defaultByteLength

The maximum number of bytes printed at a time.

defaultMaxPrintTimes

Default maximum number of print repeats

Public attribute

logEnabled

True indicates that logs are generated. False indicates that logs are not generated

maxPrintTimes

Maximum number of print repeats

Private methods

print

/**
* Print the log(In order to solve the length limit)
*
* @param priority The priority/type of this log message
* @param tag Used to identify the source of a log message.It usually identifies
*            the class or activity where the log call occurs.
* @param content The message you would like logged.
*/
fun print(priority: Int, tag: String, content: String)
Copy the code

Print logs (to address length constraints)

cutStr

/**
* Truncate the byte array as a string according to [defaultByteLength].
*
* @param bytes byte array
* @return The string obtained by [defaultByteLength]
*/
fun cutStr(bytes: ByteArray?).: String?
Copy the code

Truncate the byte array to a string according to defaultByteLength.

Public methods

setLogEnabled

fun setLogEnabled(logEnabled: Boolean)
Copy the code

Set whether to print logs

parameter

LogEnabled: Boolean True indicates that logs are generated. False indicates that logs are not generated

use

//Use in java
LogUtils.INSTANCE.setLogEnabled(true);
Copy the code
//Use in Kotlin
LogUtils.setLogEnabled(true)
Copy the code

setLogContentFormat

fun setLogContentFormat(logContent: LogContent)
Copy the code

Define your log format by implementing LogContent

use

//Use in java
LogUtils.INSTANCE.setLogContentFormat(new LogContent() {
    @NonNull
    @Override
    public String logContentFormat(@NonNull String s, @Nullable String s1, @Nullable String s2) {
        returns1+s2; }});Copy the code
//Use in Kotlin
LogUtils.setLogContentFormat(object :LogContent{
    override fun logContentFormat(methodName: String, key: String? , content:String?).: String {
        return super.logContentFormat(methodName, key, content)
    }
})
Copy the code