Skip to content

Commit 3c9ad29

Browse files
committed
Update to the latest version.
1 parent 094b041 commit 3c9ad29

File tree

12 files changed

+392
-16
lines changed

12 files changed

+392
-16
lines changed

pom.xml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>net.cloudopt.logger</groupId>
77
<artifactId>cloudopt-logger</artifactId>
8-
<version>1.0.0-SNAPSHOT</version>
8+
<version>1.0.0</version>
99
<packaging>jar</packaging>
1010

1111
<pluginRepositories>
@@ -80,6 +80,22 @@
8080
<version>${junit.version}</version>
8181
<scope>test</scope>
8282
</dependency>
83+
<dependency>
84+
<groupId>org.slf4j</groupId>
85+
<artifactId>slf4j-api</artifactId>
86+
<version>1.7.25</version>
87+
</dependency>
88+
<dependency>
89+
<groupId>ch.qos.logback</groupId>
90+
<artifactId>logback-classic</artifactId>
91+
<version>1.2.3</version>
92+
<scope>test</scope>
93+
</dependency>
94+
<dependency>
95+
<groupId>org.fusesource.jansi</groupId>
96+
<artifactId>jansi</artifactId>
97+
<version>1.13</version>
98+
</dependency>
8399
</dependencies>
84100

85101
<build>

screenshots/01.jpg

11.5 KB
Loading

screenshots/02.jpg

6.96 KB
Loading
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
}

src/main/kotlin/net/cloudopt/logger/Hello.kt

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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:")
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
}

src/test/kotlin/net/cloudopt/HelloTest.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)