|
1 | | -# cloudopt-logger |
| 1 | + |
| 2 | + |
| 3 | +[](https://github.com/KotlinBy/awesome-kotlin) [](http://www.apache.org/licenses/LICENSE-2.0.html) [](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 | + |
| 9 | + |
| 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 | + <dependency> |
| 30 | + <groupId>net.cloudopt.logger</groupId> |
| 31 | + <artifactId>cloudopt-logger</artifactId> |
| 32 | + <version>1.0.0</version> |
| 33 | + </dependency> |
| 34 | +```` |
| 35 | +If you are using Slf4j, you need to introduce the appropriate libraries, such as: |
| 36 | + |
| 37 | +````xml |
| 38 | +<dependency> |
| 39 | + <groupId>org.slf4j</groupId> |
| 40 | + <artifactId>slf4j-api</artifactId> |
| 41 | + <version>1.7.25</version> |
| 42 | +</dependency> |
| 43 | +<dependency> |
| 44 | + <groupId>ch.qos.logback</groupId> |
| 45 | + <artifactId>logback-classic</artifactId> |
| 46 | + <version>1.2.3</version> |
| 47 | +</dependency> |
| 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 | +If you want to change the color of any output character, just wrap it in a Colorer. Eight colors are already built in. |
| 104 | + |
| 105 | +## How to extend |
| 106 | + |
| 107 | +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. |
| 108 | + |
| 109 | +## Follow us |
| 110 | + |
| 111 | +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. |
| 112 | + |
| 113 | + |
0 commit comments