-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit add support for linux x64 module. All the code for linux exists but it still lacks of packaging as we failed to deploy it to github packages properly. * Created linuxX64 module, and updated Kotlin to 1.3.72. * Implemented functionality for console logging. * Used AtomicReference for all properties in KotlinLoggingConfiguration.kt. * Adjusted encapsulation with KotlinLoggingConfiguration.kt.
- Loading branch information
Showing
14 changed files
with
398 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package mu | ||
|
||
interface Appender { | ||
fun trace(message: Any?) | ||
fun debug(message: Any?) | ||
fun info(message: Any?) | ||
fun warn(message: Any?) | ||
fun error(message: Any?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package mu | ||
|
||
import platform.posix.fprintf | ||
import platform.posix.stderr | ||
|
||
object ConsoleOutputAppender : Appender { | ||
override fun trace(message: Any?) = println(message) | ||
override fun debug(message: Any?) = println(message) | ||
override fun info(message: Any?) = println(message) | ||
override fun warn(message: Any?) = println(message) | ||
|
||
override fun error(message: Any?) { | ||
fprintf(stderr, "$message\n") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package mu | ||
|
||
import mu.internal.toStringSafe | ||
|
||
object DefaultMessageFormatter : Formatter { | ||
override fun formatMessage(level: KotlinLoggingLevel, loggerName: String, msg: () -> Any?) = | ||
"${level.name}: [$loggerName] ${msg.toStringSafe()}" | ||
|
||
override fun formatMessage(level: KotlinLoggingLevel, loggerName: String, t: Throwable?, msg: () -> Any?) = | ||
"${level.name}: [$loggerName] ${msg.toStringSafe()}${t.throwableToString()}" | ||
|
||
override fun formatMessage(level: KotlinLoggingLevel, loggerName: String, marker: Marker?, msg: () -> Any?) = | ||
"${level.name}: [$loggerName] ${marker?.getName()} ${msg.toStringSafe()}" | ||
|
||
override fun formatMessage( | ||
level: KotlinLoggingLevel, | ||
loggerName: String, | ||
marker: Marker?, | ||
t: Throwable?, | ||
msg: () -> Any? | ||
) = | ||
"${level.name}: [$loggerName] ${marker?.getName()} ${msg.toStringSafe()}${t.throwableToString()}" | ||
|
||
private fun Throwable?.throwableToString(): String { | ||
if (this == null) { | ||
return "" | ||
} | ||
var msg = "" | ||
var current = this | ||
while (current != null && current.cause != current) { | ||
msg += ", Caused by: '${current.message}'" | ||
current = current.cause | ||
} | ||
return msg | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package mu | ||
|
||
interface Formatter { | ||
fun formatMessage(level: KotlinLoggingLevel, loggerName: String, msg: () -> Any?): Any? | ||
fun formatMessage(level: KotlinLoggingLevel, loggerName: String, t: Throwable?, msg: () -> Any?): Any? | ||
fun formatMessage(level: KotlinLoggingLevel, loggerName: String, marker: Marker?, msg: () -> Any?): Any? | ||
fun formatMessage( | ||
level: KotlinLoggingLevel, | ||
loggerName: String, | ||
marker: Marker?, | ||
t: Throwable?, | ||
msg: () -> Any? | ||
): Any? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package mu | ||
|
||
actual interface KLogger { | ||
|
||
/** | ||
* Lazy add a log message if isTraceEnabled is true | ||
*/ | ||
actual fun trace(msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message if isDebugEnabled is true | ||
*/ | ||
actual fun debug(msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message if isInfoEnabled is true | ||
*/ | ||
actual fun info(msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message if isWarnEnabled is true | ||
*/ | ||
actual fun warn(msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message if isErrorEnabled is true | ||
*/ | ||
actual fun error(msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message with throwable payload if isTraceEnabled is true | ||
*/ | ||
actual fun trace(t: Throwable?, msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message with throwable payload if isDebugEnabled is true | ||
*/ | ||
actual fun debug(t: Throwable?, msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message with throwable payload if isInfoEnabled is true | ||
*/ | ||
actual fun info(t: Throwable?, msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message with throwable payload if isWarnEnabled is true | ||
*/ | ||
actual fun warn(t: Throwable?, msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message with throwable payload if isErrorEnabled is true | ||
*/ | ||
actual fun error(t: Throwable?, msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message if isTraceEnabled is true | ||
*/ | ||
actual fun trace(marker: Marker?, msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message if isDebugEnabled is true | ||
*/ | ||
actual fun debug(marker: Marker?, msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message if isInfoEnabled is true | ||
*/ | ||
actual fun info(marker: Marker?, msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message if isWarnEnabled is true | ||
*/ | ||
actual fun warn(marker: Marker?, msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message if isErrorEnabled is true | ||
*/ | ||
actual fun error(marker: Marker?, msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message with throwable payload if isTraceEnabled is true | ||
*/ | ||
actual fun trace(marker: Marker?, t: Throwable?, msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message with throwable payload if isDebugEnabled is true | ||
*/ | ||
actual fun debug(marker: Marker?, t: Throwable?, msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message with throwable payload if isInfoEnabled is true | ||
*/ | ||
actual fun info(marker: Marker?, t: Throwable?, msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message with throwable payload if isWarnEnabled is true | ||
*/ | ||
actual fun warn(marker: Marker?, t: Throwable?, msg: () -> Any?) | ||
|
||
/** | ||
* Lazy add a log message with throwable payload if isErrorEnabled is true | ||
*/ | ||
actual fun error(marker: Marker?, t: Throwable?, msg: () -> Any?) | ||
|
||
/** | ||
* Add a log message with all the supplied parameters along with method name | ||
*/ | ||
actual fun entry(vararg argArray: Any?) | ||
|
||
/** | ||
* Add log message indicating exit of a method | ||
*/ | ||
actual fun exit() | ||
|
||
/** | ||
* Add a log message with the return value of a method | ||
*/ | ||
actual fun <T> exit(result: T): T where T : Any? | ||
|
||
/** | ||
* Add a log message indicating an exception will be thrown along with the stack trace. | ||
*/ | ||
actual fun <T> throwing(throwable: T): T where T : Throwable | ||
|
||
/** | ||
* Add a log message indicating an exception is caught along with the stack trace. | ||
*/ | ||
actual fun <T> catching(throwable: T) where T : Throwable | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package mu | ||
|
||
import mu.internal.MarkerLinux | ||
|
||
actual object KMarkerFactory { | ||
|
||
actual fun getMarker(name: String): Marker = MarkerLinux(name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package mu | ||
|
||
import mu.internal.KLoggerLinux | ||
|
||
|
||
actual object KotlinLogging { | ||
/** | ||
* This method allow defining the logger in a file in the following way: | ||
* ``` | ||
* val logger = KotlinLogging.logger {} | ||
* ``` | ||
*/ | ||
actual fun logger(func: () -> Unit): KLogger = KLoggerLinux(func::class.qualifiedName ?: "") | ||
|
||
actual fun logger(name: String): KLogger = KLoggerLinux(name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package mu | ||
|
||
import kotlin.native.concurrent.AtomicReference | ||
|
||
@Suppress("ObjectPropertyName") | ||
object KotlinLoggingConfiguration { | ||
private val _logLevel = AtomicReference(KotlinLoggingLevel.INFO) | ||
var logLevel: KotlinLoggingLevel | ||
get() = _logLevel.value | ||
set(value) { | ||
_logLevel.value = value | ||
} | ||
private val _appender = AtomicReference<Appender>(ConsoleOutputAppender) | ||
var appender: Appender | ||
get() = _appender.value | ||
set(value) { | ||
_appender.value = value | ||
} | ||
private val _formatter = AtomicReference<Formatter>(DefaultMessageFormatter) | ||
var formatter: Formatter | ||
get() = _formatter.value | ||
set(value) { | ||
_formatter.value = value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package mu | ||
|
||
import mu.KotlinLoggingConfiguration.logLevel | ||
|
||
enum class KotlinLoggingLevel { | ||
TRACE, | ||
DEBUG, | ||
INFO, | ||
WARN, | ||
ERROR | ||
} | ||
|
||
fun KotlinLoggingLevel.isLoggingEnabled() = this.ordinal >= logLevel.ordinal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package mu | ||
|
||
actual interface Marker { | ||
|
||
actual fun getName(): String | ||
} |
Oops, something went wrong.