├── .gitignore ├── LICENSE ├── README.md ├── README_ZH.md ├── pom.xml ├── screenshots ├── 01.jpg ├── 02.jpg └── qrcode.jpg └── src ├── main └── kotlin │ └── net │ └── cloudopt │ └── logger │ ├── Colorer.kt │ ├── Logger.kt │ ├── LoggerConfiguration.kt │ ├── LoggerJava.java │ └── provider │ ├── LoggerProvider.kt │ └── Slf4jLoggerProvider.kt └── test ├── kotlin └── net │ └── cloudopt │ └── logger │ ├── TestCase.kt │ └── TestJavaCase.java └── resource └── logback.xml /.gitignore: -------------------------------------------------------------------------------- 1 | ### Maven template 2 | target/ 3 | pom.xml.tag 4 | pom.xml.releaseBackup 5 | pom.xml.versionsBackup 6 | pom.xml.next 7 | release.properties 8 | dependency-reduced-pom.xml 9 | buildNumber.properties 10 | .mvn/timing.properties 11 | 12 | # Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) 13 | !/.mvn/wrapper/maven-wrapper.jar 14 | ### JetBrains template 15 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 16 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 17 | 18 | # User-specific stuff: 19 | .idea/ 20 | .idea/**/workspace.xml 21 | .idea/**/tasks.xml 22 | .idea/dictionaries 23 | 24 | # Sensitive or high-churn files: 25 | .idea/**/dataSources/ 26 | .idea/**/dataSources.ids 27 | .idea/**/dataSources.xml 28 | .idea/**/dataSources.local.xml 29 | .idea/**/sqlDataSources.xml 30 | .idea/**/dynamic.xml 31 | .idea/**/uiDesigner.xml 32 | 33 | # Gradle: 34 | .idea/**/gradle.xml 35 | .idea/**/libraries 36 | 37 | # CMake 38 | cmake-build-debug/ 39 | 40 | # Mongo Explorer plugin: 41 | .idea/**/mongoSettings.xml 42 | 43 | ## File-based project format: 44 | *.iws 45 | 46 | ## Plugin-specific files: 47 | 48 | # IntelliJ 49 | out/ 50 | *.iml 51 | # mpeltonen/sbt-idea plugin 52 | .idea_modules/ 53 | 54 | # JIRA plugin 55 | atlassian-ide-plugin.xml 56 | 57 | # Cursive Clojure plugin 58 | .idea/replstate.xml 59 | 60 | # Crashlytics plugin (for Android Studio and IntelliJ) 61 | com_crashlytics_export_strings.xml 62 | crashlytics.properties 63 | crashlytics-build.properties 64 | fabric.properties 65 | 66 | # Vertx 67 | .vertx/ 68 | 69 | # Javadocs 70 | javadocs/ 71 | 72 | # File Upload 73 | file-uploads/ 74 | 75 | *.log -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Cloudopt Next](https://github.com/cloudoptlab/cloudopt-next/raw/master/logo.png) 2 | 3 | [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Apache Licenses Badge](https://img.shields.io/hexpm/l/plug.svg)](http://www.apache.org/licenses/LICENSE-2.0.html) [![Twitter Badge](https://img.shields.io/twitter/url/http/shields.io.svg?style=social&logo=twitter)](https://twitter.com/CloudoptLab) 4 | 5 | 6 | Cloudopt-logger is an extensible and configurable logging framework extension based on Kotlin, supporting Java, Kotlin and Android. 7 | 8 | ![screenshot](https://github.com/cloudoptlab/cloudopt-logger/raw/master/screenshots/01.jpg) 9 | ![screenshot](https://github.com/cloudoptlab/cloudopt-logger/raw/master/screenshots/02.jpg) 10 | 11 | Features: 12 | 13 | 14 | - supports color log output. 15 | 16 | - support multiple logging frameworks, such as Slf4j, Log4j, and so on. 17 | 18 | - easy to extend. 19 | 20 | - more user-friendly and convenient to debug output. 21 | 22 | [中文文档](https://github.com/cloudoptlab/cloudopt-logger/blob/master/README_ZH.md) 23 | 24 | # Installation 25 | 26 | Introduce in Maven: 27 | 28 | ````xml 29 | 30 | net.cloudopt.logger 31 | cloudopt-logger 32 | 1.0.1 33 | 34 | ```` 35 | If you are using Slf4j, you need to introduce the appropriate libraries, such as: 36 | 37 | ````xml 38 | 39 | org.slf4j 40 | slf4j-api 41 | 1.7.25 42 | 43 | 44 | ch.qos.logback 45 | logback-classic 46 | 1.2.3 47 | 48 | ```` 49 | 50 | ## How to use 51 | 52 | Simple to use, just introduce the Logger class. Here are a few examples: 53 | 54 | ````kotlin 55 | package net.cloudopt.logger 56 | 57 | import org.junit.Test 58 | 59 | class TestCase { 60 | 61 | private val logger = Logger.getLogger(TestCase::class.java) 62 | 63 | @Test 64 | fun example1() { 65 | logger.debug("Start init....") 66 | logger.info("Operation successful!") 67 | logger.warn("The value must be not nul.") 68 | logger.error("Unable to acquire lock!") 69 | } 70 | 71 | @Test 72 | fun example2() { 73 | logger.info("Please Wait.... ${Colorer.blue("100")}") 74 | logger.info("Please Wait.... ${Colorer.yellow("200")}") 75 | logger.info("Please Wait.... ${Colorer.red("300")}") 76 | } 77 | 78 | @Test 79 | fun example3() { 80 | val configuration = LoggerConfiguration() 81 | configuration.run { 82 | this.color = false 83 | } 84 | Logger.configuration = configuration 85 | example1() 86 | } 87 | 88 | @Test 89 | fun example4() { 90 | val configuration = LoggerConfiguration() 91 | configuration.run { 92 | this.debugPrefix = "DEBUG" 93 | this.infoPrefix = "INFO" 94 | this.warnPrefix = "WARN" 95 | this.errorPrefix = "ERROR" 96 | } 97 | Logger.configuration = configuration 98 | example1() 99 | } 100 | } 101 | ```` 102 | 103 | ````java 104 | public class TestJavaCase { 105 | private Logger logger = Logger.Companion.getLogger(TestCase.class); 106 | 107 | @Test 108 | public void example1() { 109 | logger.debug("Start init...."); 110 | logger.info("Operation successful!"); 111 | logger.warn("The value must be not nul."); 112 | logger.error("Unable to acquire lock!"); 113 | } 114 | 115 | @Test 116 | public void example2() { 117 | logger.info("Please Wait.... " + Colorer.INSTANCE.blue("100")); 118 | logger.info("Please Wait.... " + Colorer.INSTANCE.yellow("200")); 119 | logger.info("Please Wait.... " + Colorer.INSTANCE.red("300")); 120 | } 121 | 122 | @Test 123 | public void example3() { 124 | LoggerConfiguration configuration = new LoggerConfiguration(); 125 | configuration.setColor(false); 126 | Logger.Companion.setConfiguration(configuration); 127 | example1(); 128 | } 129 | 130 | @Test 131 | public void example4() { 132 | LoggerConfiguration configuration = new LoggerConfiguration(); 133 | configuration.setDebugPrefix("DEBUG"); 134 | configuration.setInfoPrefix("INFO"); 135 | configuration.setWarnPrefix("WARN"); 136 | configuration.setErrorPrefix("ERROR"); 137 | Logger.Companion.setConfiguration(configuration); 138 | example1(); 139 | } 140 | } 141 | ```` 142 | 143 | If you want to change the color of any output character, just wrap it in a Colorer. Eight colors are already built in. 144 | 145 | ## How to extend 146 | 147 | Support for Slf4j is now built in, and with Slf4j you can support logback, log4j, log4j2, etc. If you need to support it directly or support other logging frameworks, you can do so by referring to Slf4jLoggerProvider. 148 | 149 | ## Follow us 150 | 151 | You can focus on our [twitter](https://twitter.com/CloudoptLab) or is to focus on the micro letter, public the latest news we will via twitter or released to the public. 152 | 153 | ![](https://github.com/cloudoptlab/cloudopt-logger/raw/master/screenshots/qrcode.jpg) -------------------------------------------------------------------------------- /README_ZH.md: -------------------------------------------------------------------------------- 1 | ![Cloudopt Next](https://github.com/cloudoptlab/cloudopt-next/raw/master/logo.png) 2 | 3 | [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Apache Licenses Badge](https://img.shields.io/hexpm/l/plug.svg)](http://www.apache.org/licenses/LICENSE-2.0.html) [![Twitter Badge](https://img.shields.io/twitter/url/http/shields.io.svg?style=social&logo=twitter)](https://twitter.com/CloudoptLab) 4 | 5 | 6 | cloudopt-logger是一个基于Kotlin开发的可扩展、可配置的日志框架扩展,支持Java、Kotlin及Android。 7 | 8 | ![screenshot](https://github.com/cloudoptlab/cloudopt-logger/raw/master/screenshots/01.jpg) 9 | ![screenshot](https://github.com/cloudoptlab/cloudopt-logger/raw/master/screenshots/02.jpg) 10 | 11 | 具有以下特性: 12 | 13 | - 支持彩色的日志输出。 14 | - 支持多种日志框架,如Slf4j、Log4j等等。 15 | - 易于扩展。 16 | - 更人性化和方便调试的输出。 17 | 18 | [中文文档](https://github.com/cloudoptlab/cloudopt-logger/blob/master/README_ZH.md) 19 | 20 | # 安装 21 | 22 | 在Maven中引入: 23 | 24 | ````xml 25 | 26 | net.cloudopt.logger 27 | cloudopt-logger 28 | 1.0.1 29 | 30 | ```` 31 | 32 | 如果您是使用Slf4j的话,需要引入相应的库,如: 33 | 34 | ````xml 35 | 36 | org.slf4j 37 | slf4j-api 38 | 1.7.25 39 | 40 | 41 | ch.qos.logback 42 | logback-classic 43 | 1.2.3 44 | 45 | ```` 46 | 47 | ## 如何使用 48 | 49 | 使用起来非常简单,只需要引入Logger类即可,下面是几个示例: 50 | 51 | ````kotlin 52 | package net.cloudopt.logger 53 | 54 | import org.junit.Test 55 | 56 | class TestCase { 57 | 58 | private val logger = Logger.getLogger(TestCase::class.java) 59 | 60 | @Test 61 | fun example1() { 62 | logger.debug("Start init....") 63 | logger.info("Operation successful!") 64 | logger.warn("The value must be not nul.") 65 | logger.error("Unable to acquire lock!") 66 | } 67 | 68 | @Test 69 | fun example2() { 70 | logger.info("Please Wait.... ${Colorer.blue("100")}") 71 | logger.info("Please Wait.... ${Colorer.yellow("200")}") 72 | logger.info("Please Wait.... ${Colorer.red("300")}") 73 | } 74 | 75 | @Test 76 | fun example3() { 77 | val configuration = LoggerConfiguration() 78 | configuration.run { 79 | this.color = false 80 | } 81 | Logger.configuration = configuration 82 | example1() 83 | } 84 | 85 | @Test 86 | fun example4() { 87 | val configuration = LoggerConfiguration() 88 | configuration.run { 89 | this.debugPrefix = "DEBUG" 90 | this.infoPrefix = "INFO" 91 | this.warnPrefix = "WARN" 92 | this.errorPrefix = "ERROR" 93 | } 94 | Logger.configuration = configuration 95 | example1() 96 | } 97 | } 98 | ```` 99 | 100 | ````java 101 | public class TestJavaCase { 102 | private Logger logger = Logger.Companion.getLogger(TestCase.class); 103 | 104 | @Test 105 | public void example1() { 106 | logger.debug("Start init...."); 107 | logger.info("Operation successful!"); 108 | logger.warn("The value must be not nul."); 109 | logger.error("Unable to acquire lock!"); 110 | } 111 | 112 | @Test 113 | public void example2() { 114 | logger.info("Please Wait.... " + Colorer.INSTANCE.blue("100")); 115 | logger.info("Please Wait.... " + Colorer.INSTANCE.yellow("200")); 116 | logger.info("Please Wait.... " + Colorer.INSTANCE.red("300")); 117 | } 118 | 119 | @Test 120 | public void example3() { 121 | LoggerConfiguration configuration = new LoggerConfiguration(); 122 | configuration.setColor(false); 123 | Logger.Companion.setConfiguration(configuration); 124 | example1(); 125 | } 126 | 127 | @Test 128 | public void example4() { 129 | LoggerConfiguration configuration = new LoggerConfiguration(); 130 | configuration.setDebugPrefix("DEBUG"); 131 | configuration.setInfoPrefix("INFO"); 132 | configuration.setWarnPrefix("WARN"); 133 | configuration.setErrorPrefix("ERROR"); 134 | Logger.Companion.setConfiguration(configuration); 135 | example1(); 136 | } 137 | } 138 | ```` 139 | 140 | 如果您想要修改任何输出的字符的颜色,只需要通过Colorer.xxx的方法包裹即可。目前已经内置了八种颜色。 141 | 142 | ## 如何扩展 143 | 144 | 目前已经内置了对Slf4j的支持,通过Slf4j可以支持logback、log4j、log4j2等等,如果您需要直接支持或者支持其他日志框架,您可以参考Slf4jLoggerProvider,自行实现。 145 | 146 | ## 关注我们 147 | 148 | 您可以关注我们的[推特](https://twitter.com/CloudoptLab)或者是关注我们的微信公众号,最新消息我们会通过推特或者公众号发布。 149 | 150 | ![](https://github.com/cloudoptlab/cloudopt-logger/raw/master/screenshots/qrcode.jpg) 151 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 4.0.0 6 | 7 | net.cloudopt.logger 8 | cloudopt-logger 9 | 1.0.1 10 | jar 11 | 12 | 13 | 14 | jcenter 15 | JCenter 16 | https://jcenter.bintray.com/ 17 | 18 | 19 | 20 | cloudopt-logger 21 | cloudopt-logger is a super lightweight logging library implemented in pure Kotlin. 22 | It is designed to be used in Kotlin, Java and Android. 23 | 24 | https://www.cloudopt.net 25 | 26 | Cloudopt 27 | https://www.cloudopt.net 28 | 29 | 30 | 31 | Github Issue 32 | https://github.com/cloudoptlab/cloudopt-logger/issues 33 | 34 | 35 | 36 | 37 | The Apache Software License, Version 2.0 38 | http://www.apache.org/licenses/LICENSE-2.0.txt 39 | 40 | 41 | 42 | 43 | 44 | Cloudopt 45 | Cloudopt 46 | https://www.cloudopt.net 47 | 48 | 49 | 50 | 51 | scm:git@github.com:cloudoptlab/cloudopt-logger.git 52 | scm:git@github.com:cloudoptlab/cloudopt-logger.git 53 | git@github.com:cloudoptlab/cloudopt-logger.git 54 | 55 | 56 | 57 | 1.8 58 | UTF-8 59 | 1.2.71 60 | 4.12 61 | ${java.version} 62 | ${java.version} 63 | true 64 | 0.9.17 65 | 66 | 67 | 68 | 69 | org.jetbrains.kotlin 70 | kotlin-stdlib 71 | ${kotlin.version} 72 | 73 | 74 | org.jetbrains.kotlin 75 | kotlin-test-junit 76 | ${kotlin.version} 77 | test 78 | 79 | 80 | junit 81 | junit 82 | ${junit.version} 83 | test 84 | 85 | 86 | org.slf4j 87 | slf4j-api 88 | 1.7.25 89 | provided 90 | 91 | 92 | ch.qos.logback 93 | logback-classic 94 | 1.2.3 95 | test 96 | 97 | 98 | org.fusesource.jansi 99 | jansi 100 | 1.13 101 | 102 | 103 | 104 | 105 | ${project.name}-v${project.version} 106 | 107 | 108 | src/main/java 109 | 110 | **/*.xml 111 | 112 | 113 | 114 | src/main/resources 115 | 116 | **/* 117 | 118 | 119 | 120 | ${project.basedir}/src/main/kotlin 121 | ${project.basedir}/src/test/kotlin 122 | 123 | 124 | org.jetbrains.kotlin 125 | kotlin-maven-plugin 126 | ${kotlin.version} 127 | 128 | ${java.version} 129 | 1.2 130 | 1.2 131 | 132 | 133 | all-open 134 | no-arg 135 | jpa 136 | spring 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | org.jetbrains.kotlin 150 | kotlin-maven-allopen 151 | 1.2.30 152 | 153 | 154 | org.jetbrains.kotlin 155 | kotlin-maven-noarg 156 | 1.2.30 157 | 158 | 159 | 160 | 161 | compile 162 | compile 163 | 164 | compile 165 | 166 | 167 | 168 | test-compile 169 | test-compile 170 | 171 | test-compile 172 | 173 | 174 | 175 | 176 | 177 | org.apache.maven.plugins 178 | maven-jar-plugin 179 | 3.0.2 180 | 181 | 182 | org.apache.maven.plugins 183 | maven-compiler-plugin 184 | 3.3 185 | 186 | ${maven.compiler.source} 187 | ${maven.compiler.target} 188 | 189 | 190 | 191 | 192 | org.jetbrains.dokka 193 | dokka-maven-plugin 194 | ${dokka.version} 195 | 196 | 197 | pre-site 198 | 199 | dokka 200 | 201 | 202 | 203 | 204 | html 205 | ${project.basedir}/target/dokka 206 | 8 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | release 216 | 217 | 218 | oss 219 | https://oss.sonatype.org/content/repositories/snapshots/ 220 | 221 | 222 | oss 223 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 224 | 225 | 226 | 227 | 228 | 229 | 230 | org.apache.maven.plugins 231 | maven-source-plugin 232 | 3.0.1 233 | 234 | 235 | package 236 | 237 | jar-no-fork 238 | 239 | 240 | 241 | 242 | 243 | 244 | org.apache.maven.plugins 245 | maven-gpg-plugin 246 | 1.6 247 | 248 | 249 | sign-artifacts 250 | verify 251 | 252 | sign 253 | 254 | 255 | 256 | 257 | 258 | 259 | org.apache.maven.plugins 260 | maven-javadoc-plugin 261 | 2.10.3 262 | 263 | 264 | package 265 | 266 | jar 267 | 268 | 269 | -Xdoclint:none 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | -------------------------------------------------------------------------------- /screenshots/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudoptlab/cloudopt-logger/1e9de9736a3480036791f2a758bb88c8b451ba6e/screenshots/01.jpg -------------------------------------------------------------------------------- /screenshots/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudoptlab/cloudopt-logger/1e9de9736a3480036791f2a758bb88c8b451ba6e/screenshots/02.jpg -------------------------------------------------------------------------------- /screenshots/qrcode.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudoptlab/cloudopt-logger/1e9de9736a3480036791f2a758bb88c8b451ba6e/screenshots/qrcode.jpg -------------------------------------------------------------------------------- /src/main/kotlin/net/cloudopt/logger/Colorer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Cloudopt. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Apache License v2.0 which accompanies this distribution. 6 | * 7 | * The Apache License v2.0 is available at 8 | * http://www.opensource.org/licenses/apache2.0.php 9 | * 10 | * You may elect to redistribute this code under either of these licenses. 11 | */ 12 | package net.cloudopt.logger 13 | 14 | import org.fusesource.jansi.Ansi 15 | 16 | /* 17 | * @author: Cloudopt 18 | * @Time: 2018/10/18 19 | * @Description: Used to help the console output colored text 20 | */ 21 | 22 | object Colorer { 23 | 24 | /** 25 | * Output black text 26 | * @param value Hope to output the text 27 | * @return This is the processed text 28 | */ 29 | fun black(value: String): String { 30 | return diy("black", value) 31 | } 32 | 33 | /** 34 | * Output white text 35 | * @param value Hope to output the text 36 | * @return Handled text 37 | */ 38 | fun white(value: String): String { 39 | return diy("white", value) 40 | } 41 | 42 | /** 43 | * Output green text 44 | * @param value Hope to output the text 45 | * @return Handled text 46 | */ 47 | fun green(value: String): String { 48 | return diy("green", value) 49 | } 50 | 51 | /** 52 | * Output yellow text 53 | * @param value Hope to output the text 54 | * @return Handled text 55 | */ 56 | fun yellow(value: String): String { 57 | return diy("yellow", value) 58 | } 59 | 60 | /** 61 | * Output pink text 62 | * @param value Hope to output the text 63 | * @return Handled text 64 | */ 65 | fun magenta(value: String): String { 66 | return diy("magenta", value) 67 | } 68 | 69 | /** 70 | * Output red text 71 | * @param value Hope to output the text 72 | * @return Handled text 73 | */ 74 | fun red(value: String): String { 75 | return diy("red", value) 76 | } 77 | 78 | /** 79 | * Output cyan text 80 | * @param value Hope to output the text 81 | * @return Handled text 82 | */ 83 | fun cyan(value: String): String { 84 | return diy("cyan", value) 85 | } 86 | 87 | /** 88 | * Output blue text 89 | * @param value Hope to output the text 90 | * @return Handled text 91 | */ 92 | fun blue(value: String): String { 93 | return diy("blue", value) 94 | } 95 | 96 | /** 97 | * Preprocess the text 98 | * @param color The name of the color 99 | * @param value Hope to output the text 100 | * @return Handled text 101 | */ 102 | private fun diy(color: String, value: String): String { 103 | return if(Logger.configuration.color){ 104 | Ansi.ansi().eraseScreen().render("@|$color $value|@").toString() 105 | }else{ 106 | value 107 | } 108 | } 109 | 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/main/kotlin/net/cloudopt/logger/Logger.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Cloudopt. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Apache License v2.0 which accompanies this distribution. 6 | * 7 | * The Apache License v2.0 is available at 8 | * http://www.opensource.org/licenses/apache2.0.php 9 | * 10 | * You may elect to redistribute this code under either of these licenses. 11 | */ 12 | package net.cloudopt.logger 13 | 14 | import net.cloudopt.logger.LoggerConfiguration 15 | 16 | /* 17 | * @author: Cloudopt 18 | * @Time: 2018/10/18 19 | * @Description: Abstract class for log output 20 | */ 21 | abstract class Logger { 22 | 23 | abstract fun isDebugEnabled(): Boolean 24 | 25 | abstract fun isInfoEnabled(): Boolean 26 | 27 | abstract fun isWarnEnabled(): Boolean 28 | 29 | abstract fun isErrorEnabled(): Boolean 30 | 31 | abstract fun debug(format: String, vararg args: Any) 32 | 33 | abstract fun debug(format: String, t: Throwable, vararg args: Any) 34 | 35 | abstract fun info(format: String, vararg args: Any) 36 | 37 | abstract fun info(format: String, t: Throwable, vararg args: Any) 38 | 39 | abstract fun warn(format: String, vararg args: Any) 40 | 41 | abstract fun warn(format: String, t: Throwable, vararg args: Any) 42 | 43 | abstract fun error(format: String, vararg args: Any) 44 | 45 | abstract fun error(format: String, t: Throwable, vararg args: Any) 46 | 47 | 48 | companion object { 49 | 50 | @JvmStatic 51 | open var configuration = LoggerConfiguration() 52 | 53 | fun getLogger(clazz: Class<*>): Logger { 54 | return configuration.loggerProvider.getLogger(clazz) 55 | } 56 | 57 | fun getLogger(clazzName: String): Logger { 58 | return configuration.loggerProvider.getLogger(clazzName) 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/kotlin/net/cloudopt/logger/LoggerConfiguration.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Cloudopt. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Apache License v2.0 which accompanies this distribution. 6 | * 7 | * The Apache License v2.0 is available at 8 | * http://www.opensource.org/licenses/apache2.0.php 9 | * 10 | * You may elect to redistribute this code under either of these licenses. 11 | */ 12 | package net.cloudopt.logger 13 | 14 | import net.cloudopt.logger.provider.LoggerProvider 15 | import net.cloudopt.logger.provider.Slf4jLoggerProvider 16 | 17 | /* 18 | * @author: Cloudopt 19 | * @Time: 2018/10/18 20 | * @Description: Configuration file 21 | */ 22 | 23 | data class LoggerConfiguration(var color:Boolean = true, 24 | var loggerProvider: LoggerProvider = Slf4jLoggerProvider(), 25 | var debugPrefix:String = "\uD83D\uDD25 DEBUG:", 26 | var infoPrefix:String = "✔ INFO:", 27 | var warnPrefix:String = "⚠ WARN:", 28 | var errorPrefix:String = "❌ ERRROR:") -------------------------------------------------------------------------------- /src/main/kotlin/net/cloudopt/logger/LoggerJava.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Cloudopt. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Apache License v2.0 which accompanies this distribution. 6 | * 7 | * The Apache License v2.0 is available at 8 | * http://www.opensource.org/licenses/apache2.0.php 9 | * 10 | * You may elect to redistribute this code under either of these licenses. 11 | */ 12 | package net.cloudopt.logger; 13 | 14 | /* 15 | * @author: Cloudopt 16 | * @Time: 2018/10/25 17 | * @Description: Used to generate javadoc 18 | */ 19 | 20 | 21 | public class LoggerJava { 22 | } 23 | -------------------------------------------------------------------------------- /src/main/kotlin/net/cloudopt/logger/provider/LoggerProvider.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Cloudopt. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Apache License v2.0 which accompanies this distribution. 6 | * 7 | * The Apache License v2.0 is available at 8 | * http://www.opensource.org/licenses/apache2.0.php 9 | * 10 | * You may elect to redistribute this code under either of these licenses. 11 | */ 12 | package net.cloudopt.logger.provider 13 | 14 | import net.cloudopt.logger.Logger 15 | 16 | 17 | /* 18 | * @author: Cloudopt 19 | * @Time: 2018/10/18 20 | * @Description: Log interface 21 | */ 22 | interface LoggerProvider { 23 | 24 | fun getLogger(clazz: Class<*>): Logger 25 | 26 | fun getLogger(clazzName: String): Logger 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/kotlin/net/cloudopt/logger/provider/Slf4jLoggerProvider.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Cloudopt. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Apache License v2.0 which accompanies this distribution. 6 | * 7 | * The Apache License v2.0 is available at 8 | * http://www.opensource.org/licenses/apache2.0.php 9 | * 10 | * You may elect to redistribute this code under either of these licenses. 11 | */ 12 | package net.cloudopt.logger.provider 13 | 14 | import net.cloudopt.logger.Colorer 15 | import net.cloudopt.logger.Logger 16 | 17 | /* 18 | * @author: Cloudopt 19 | * @Time: 2018/10/18 20 | * @Description: SLF4J log implementation class 21 | */ 22 | class Slf4jLoggerProvider : LoggerProvider { 23 | 24 | override fun getLogger(clazz: Class<*>): Logger { 25 | return Slf4JLogger(org.slf4j.LoggerFactory.getLogger(clazz)) 26 | } 27 | 28 | override fun getLogger(clazzName: String): Logger { 29 | return Slf4JLogger(org.slf4j.LoggerFactory.getLogger(clazzName)) 30 | } 31 | 32 | 33 | inner class Slf4JLogger internal constructor(private val logger: org.slf4j.Logger) : Logger() { 34 | 35 | @JvmOverloads 36 | override fun debug(message: String, vararg args: Any) { 37 | logger.debug("${Colorer.magenta(Logger.configuration.debugPrefix)} ${String.format(message, *args)}", *args) 38 | } 39 | 40 | @JvmOverloads 41 | override fun debug(message: String, t: Throwable, vararg args: Any) { 42 | logger.debug("${Colorer.green(Logger.configuration.debugPrefix)} ${String.format(message, *args)}", t) 43 | } 44 | 45 | @JvmOverloads 46 | override fun info(message: String, vararg args: Any) { 47 | logger.info("${Colorer.blue(Logger.configuration.infoPrefix)} ${String.format(message, *args)}", *args) 48 | } 49 | 50 | @JvmOverloads 51 | override fun info(message: String, t: Throwable, vararg args: Any) { 52 | logger.info("${Colorer.blue(Logger.configuration.infoPrefix)} ${String.format(message, *args)}", t) 53 | } 54 | 55 | @JvmOverloads 56 | override fun warn(message: String, vararg args: Any) { 57 | logger.warn("${Colorer.yellow(Logger.configuration.warnPrefix)} ${String.format(message, *args)}", *args) 58 | } 59 | 60 | @JvmOverloads 61 | override fun warn(message: String, t: Throwable, vararg args: Any) { 62 | logger.warn("${Colorer.yellow(Logger.configuration.warnPrefix)} ${String.format(message, *args)}", t) 63 | } 64 | 65 | @JvmOverloads 66 | override fun error(message: String, vararg args: Any) { 67 | logger.error("${Colorer.red(Logger.configuration.errorPrefix)} ${String.format(message, *args)}", *args) 68 | } 69 | 70 | @JvmOverloads 71 | override fun error(message: String, t: Throwable, vararg args: Any) { 72 | logger.error("${Colorer.red(Logger.configuration.errorPrefix)} ${String.format(message, *args)}", t) 73 | } 74 | 75 | override fun isDebugEnabled(): Boolean { 76 | return logger.isDebugEnabled 77 | } 78 | 79 | override fun isInfoEnabled(): Boolean { 80 | return logger.isInfoEnabled 81 | } 82 | 83 | override fun isWarnEnabled(): Boolean { 84 | return logger.isWarnEnabled 85 | } 86 | 87 | override fun isErrorEnabled(): Boolean { 88 | return logger.isErrorEnabled 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/test/kotlin/net/cloudopt/logger/TestCase.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Cloudopt. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package net.cloudopt.logger 17 | 18 | import org.junit.Test 19 | 20 | /* 21 | * @author: Cloudopt 22 | * @Time: 2018/1/9 23 | * @Description: Test Case 24 | */ 25 | class TestCase { 26 | 27 | private val logger = Logger.getLogger(TestCase::class.java) 28 | 29 | @Test 30 | fun example1() { 31 | logger.debug("Start init....") 32 | logger.info("Operation successful!") 33 | logger.warn("The value must be not nul.") 34 | logger.error("Unable to acquire lock!") 35 | } 36 | 37 | @Test 38 | fun example2() { 39 | logger.info("Please Wait.... ${Colorer.blue("100")}") 40 | logger.info("Please Wait.... ${Colorer.yellow("200")}") 41 | logger.info("Please Wait.... ${Colorer.red("300")}") 42 | } 43 | 44 | @Test 45 | fun example3() { 46 | val configuration = LoggerConfiguration() 47 | configuration.run { 48 | color = false 49 | } 50 | Logger.configuration = configuration 51 | example1() 52 | } 53 | 54 | @Test 55 | fun example4() { 56 | val configuration = LoggerConfiguration() 57 | configuration.run { 58 | debugPrefix = "DEBUG" 59 | infoPrefix = "INFO" 60 | warnPrefix = "WARN" 61 | errorPrefix = "ERROR" 62 | } 63 | Logger.configuration = configuration 64 | example1() 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/kotlin/net/cloudopt/logger/TestJavaCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Cloudopt. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package net.cloudopt.logger; 17 | 18 | import org.junit.Test; 19 | 20 | /* 21 | * @author: Cloudopt 22 | * @Time: 2018/10/26 23 | * @Description: Test Case 24 | */ 25 | public class TestJavaCase { 26 | 27 | private Logger logger = Logger.Companion.getLogger(TestCase.class); 28 | 29 | @Test 30 | public void example1() { 31 | logger.debug("Start init...."); 32 | logger.info("Operation successful!"); 33 | logger.warn("The value must be not nul."); 34 | logger.error("Unable to acquire lock!"); 35 | } 36 | 37 | @Test 38 | public void example2() { 39 | logger.info("Please Wait.... " + Colorer.INSTANCE.blue("100")); 40 | logger.info("Please Wait.... " + Colorer.INSTANCE.yellow("200")); 41 | logger.info("Please Wait.... " + Colorer.INSTANCE.red("300")); 42 | } 43 | 44 | @Test 45 | public void example3() { 46 | LoggerConfiguration configuration = new LoggerConfiguration(); 47 | configuration.setColor(false); 48 | Logger.Companion.setConfiguration(configuration); 49 | example1(); 50 | } 51 | 52 | @Test 53 | public void example4() { 54 | LoggerConfiguration configuration = new LoggerConfiguration(); 55 | configuration.setDebugPrefix("DEBUG"); 56 | configuration.setInfoPrefix("INFO"); 57 | configuration.setWarnPrefix("WARN"); 58 | configuration.setErrorPrefix("ERROR"); 59 | Logger.Companion.setConfiguration(configuration); 60 | example1(); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/resource/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%logger{36}] > %msg%n 6 | utf-8 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | --------------------------------------------------------------------------------