# IdolLogger **Repository Path**: china-starsoft/idol-logger ## Basic Information - **Project Name**: IdolLogger - **Description**: 日志管理 - 支持多种日志输出方案,如:文件输出,控制台输出,窗口输出等。 - **Primary Language**: Kotlin - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-12-25 - **Last Updated**: 2021-12-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: logger, Kotlin, Android, Idol ## README # SuperIdol [![](https://jitpack.io/v/com.gitee.china-starsoft/idol-logger.svg)](https://jitpack.io/#com.gitee.china-starsoft/idol-logger) #### 介绍 {**IdolLogger** 日志系统 - 支持多种日志输出方案,如:文件输出,控制台输出,窗口输出等。} #### 效果展示 * [ => 控制台输出](./images/console.png) * [ => 文件输出](./images/file.png) * [ => 窗口输出](./images/window.png) #### UML示意图 * [ => IdolLogger UML 示意图](images/IdolLogger.png) * [ => WindowPrinter UML 示意图](images/WindowPrinterUML.png) #### 安装教程 1. 根目录“build.gradle”添加如下信息 ``` allprojects { repositories { ... maven { url 'https://jitpack.io' } } } ``` 2. 在module的“build.gradle”添加如下信息 ``` dependencies { implementation 'com.gitee.china-starsoft:idol-logger:$latest' } ``` 3. 当前最新版本[![](https://jitpack.io/v/com.gitee.china-starsoft/idol-logger.svg)](https://jitpack.io/#com.gitee.china-starsoft/idol-logger) #### 使用说明 1. 初始化IdolLogger日志系统 ```kotlin IdolLogger.setDebug(true) // 开启(true)、关闭(false)日志系统 .setTag("SuperIdol") // 日志默认 tag .setJsonParser(object : IdolToJson { // object对象转换string override fun toJson(vararg data: Any): String { // Gson().toJson(data) } }) ``` 2. 写入日志 ```kotlin class A { override fun toString() = "hello idol 520!" } val list = listOf("hello", "idol", "520!") d("Hello", " Idol ", 520, '!') dt("Idol", A(), '\n', list) ``` 3. 支持日志级别及方法 ```kotlin // level: VERBOSE fun v(vararg contents: Any) fun vt(tag: String, vararg contents: Any) // level: DEBUG fun d(vararg contents: Any) fun dt(tag: String, vararg contents: Any) // level: INFO fun i(vararg contents: Any) fun it(tag: String, vararg contents: Any) // level: WARN fun w(vararg contents: Any) fun wt(tag: String, vararg contents: Any) // level: ERROR fun e(vararg contents: Any) fun et(tag: String, vararg contents: Any) ``` 4. 设置输出方案:控制台输出(IdolConsolePrinter),文件输出(IdolFilePrinter),窗口输出(IdolWindowPrinter) ```kotlin // 控制台输出 IdolLogger.setPrinter(IdolConsolePrinter) ``` ```kotlin // 文件输出 IdolLogger.setPrinter(IdolFilePrinter .ins( cacheDir.absolutePath, // 文件输出位置 24 * 60 * 60 * 1000 // 文件保留时间,单位(毫秒) ) ) ``` ```kotlin // 窗口输出,需要获取悬浮窗口权限 IdolLogger.setPrinter(IdolWindowPrinter.setUp(application)) ``` ```kotlin // 同时输出到 控制台、文件、窗口 IdolLogger.setPrinters( IdolConsolePrinter, IdolFilePrinter.ins(cacheDir.absolutePath, 24 * 60 * 60 * 1000), IdolWindowPrinter.setUp(application) ) ``` 5. 开启线程信息 ```kotlin IdolLogger.setThread(true) // 开启(true)、关闭(false) ``` 6. 开启堆栈信息 ```kotlin val depth = 5 IdolLogger.setStackTraceDepth(depth) // 关闭(depth <= 0)、开启(depth > 0,同时堆栈输出深度为depth) ``` #### 先进功能 1. 自定义输出方案 ```kotlin class CustomPrinter: IdolPrinter { override fun print(level: Int, tag: String, printString: String) { // TODO:你的输出方案 } } // 调用自定义方案 IdolLogger.setPrinter(CustomPrinter()) ``` 2. 自定义线程输出式样 ```kotlin class CustomThreadFormat : IThreadFormat() { override fun formatter(thread: Thread): String { // TODO:return 你的输出方案 } } // 调用自定义式样 IdolLogger.setTreadFormat(CustomThreadFormat()) ``` 3. 自定义堆栈输出式样 ```kotlin class CustomStackTraceFormat : IStackTraceFormat() { override fun formatter(data: Array): String { // TODO:return 你的输出方案 } } // 调用自定义式样 IdolLogger.setStackTraceFormat(CustomStackTraceFormat()) ``` #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)