Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Linux X64 Support #119

Merged
merged 10 commits into from
Jul 14, 2020
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ fabric.properties
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

github_packages.properties
github_packages.properties.old
43 changes: 40 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import org.jetbrains.dokka.gradle.DokkaTask
import java.util.Date
import java.util.Properties

plugins {
kotlin("multiplatform") version "1.3.70"
kotlin("multiplatform") version "1.3.72"
id("com.jfrog.bintray") version "1.8.4"
id("org.jetbrains.dokka") version "0.10.0"
`maven-publish`
Expand Down Expand Up @@ -67,6 +68,7 @@ kotlin {
}
}
}
linuxX64("linuxX64")
sourceSets {
commonMain {
dependencies {
Expand Down Expand Up @@ -110,6 +112,17 @@ kotlin {
}

publishing {
repositories {
maven {
val settings = fetchGitHubPackagesSettings()
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/${settings.owner}/${settings.repository}")
credentials {
username = settings.user
password = settings.token
}
}
}
publications.withType<MavenPublication> {
pom {
name.set("kotlin-logging")
Expand All @@ -135,15 +148,16 @@ publishing {
url.set("http://github.com/MicroUtils/kotlin-logging/tree/master")
}
}
artifact(tasks["javadocJar"])
// TODO: Fix generation of Java Doc Jars.
napperley marked this conversation as resolved.
Show resolved Hide resolved
// artifact(tasks["javadocJar"])
}
}

bintray {
user = "oshai"//project.hasProperty("bintrayUser") ? project.property("bintrayUser") : System.getenv("BINTRAY_USER")
key = "mykey" //https://bintray.com/profile/edit
// project.hasProperty("bintrayApiKey") ? project.property("bintrayApiKey") : System.getenv("BINTRAY_API_KEY")
setPublications("metadata", "jvm", "js")
setPublications("metadata", "jvm", "js", "linuxX64")
napperley marked this conversation as resolved.
Show resolved Hide resolved
publish = true //[Default: false] Whether version should be auto published after an upload
pkg.apply {
repo = "kotlin-logging"
Expand All @@ -170,3 +184,26 @@ bintray {
}
}
}

data class GitHubPackagesSettings(val user: String, val token: String, val owner: String, val repository: String)

fun fetchGitHubPackagesSettings(): GitHubPackagesSettings {
var owner = ""
var repository = ""
var user = ""
var token = ""
val properties = Properties()
val filename = "github_packages.properties"
if (file(filename).exists()) {
file(filename).bufferedReader().use { br ->
with(properties) {
load(br)
owner = getProperty("gpr.owner")
repository = getProperty("gpr.repository")
user = getProperty("gpr.user")
token = getProperty("gpr.token")
}
}
}
return GitHubPackagesSettings(user = user, token = token, owner = owner, repository = repository)
}
9 changes: 9 additions & 0 deletions src/linuxX64Main/kotlin/mu/Appender.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package mu

interface Appender {
napperley marked this conversation as resolved.
Show resolved Hide resolved
fun trace(message: Any?)
fun debug(message: Any?)
fun info(message: Any?)
fun warn(message: Any?)
fun error(message: Any?)
}
15 changes: 15 additions & 0 deletions src/linuxX64Main/kotlin/mu/ConsoleOutputAppender.kt
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)
napperley marked this conversation as resolved.
Show resolved Hide resolved

override fun error(message: Any?) {
fprintf(stderr, "$message\n")
}
}
36 changes: 36 additions & 0 deletions src/linuxX64Main/kotlin/mu/DefaultMessageFormatter.kt
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
}
}
14 changes: 14 additions & 0 deletions src/linuxX64Main/kotlin/mu/Formatter.kt
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?
}
129 changes: 129 additions & 0 deletions src/linuxX64Main/kotlin/mu/KLogger.kt
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
}
8 changes: 8 additions & 0 deletions src/linuxX64Main/kotlin/mu/KMarkerFactory.kt
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)
}
16 changes: 16 additions & 0 deletions src/linuxX64Main/kotlin/mu/KotlinLogging.kt
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)
}
8 changes: 8 additions & 0 deletions src/linuxX64Main/kotlin/mu/KotlinLoggingConfiguration.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package mu

object KotlinLoggingConfiguration {
var LOG_LEVEL = KotlinLoggingLevel.INFO
napperley marked this conversation as resolved.
Show resolved Hide resolved
var APPENDER: Appender = ConsoleOutputAppender
var FORMATTER: Formatter = DefaultMessageFormatter

}
13 changes: 13 additions & 0 deletions src/linuxX64Main/kotlin/mu/KotlinLoggingLevel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package mu

import mu.KotlinLoggingConfiguration.LOG_LEVEL

enum class KotlinLoggingLevel {
TRACE,
DEBUG,
INFO,
WARN,
ERROR
}

fun KotlinLoggingLevel.isLoggingEnabled() = this.ordinal >= LOG_LEVEL.ordinal
6 changes: 6 additions & 0 deletions src/linuxX64Main/kotlin/mu/Marker.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package mu

actual interface Marker {

actual fun getName(): String
}
Loading