-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.2 support for using KmLogging in libraries
- Loading branch information
1 parent
b7127f9
commit ba30934
Showing
7 changed files
with
87 additions
and
11 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
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
72 changes: 72 additions & 0 deletions
72
logging/src/commonMain/kotlin/org/lighthousegames/logging/KmModuleLog.kt
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,72 @@ | ||
package org.lighthousegames.logging | ||
|
||
/** | ||
* Wrapper for KmLog that allows library modules to also use KmLogging and be able to enable or disable its logging independently | ||
* of the application that is also using KmLogging. | ||
* | ||
* Example usage with code implemented in ChartsLogging.kt | ||
* ``` | ||
* object ChartsLogging { | ||
* var enabled = true | ||
* } | ||
* | ||
* fun moduleLogging(tag: String? = null): KmModuleLog { | ||
* // string passed into createTag should be the name of the class that this function is implemented in | ||
* // if it is a top level function then the class name is the file name with Kt appended | ||
* val t = tag ?: KmLogging.createTag("ChartsLoggingKt").first | ||
* return KmModuleLog(logging(t), ChartsLogging::enabled) | ||
* } | ||
* ``` | ||
*/ | ||
class KmModuleLog(val log: KmLog, val isModuleLogging: () -> Boolean) { | ||
|
||
inline fun v(msg: () -> Any?) { | ||
if (isModuleLogging()) | ||
log.verbose(msg) | ||
} | ||
|
||
inline fun v(tag: String, msg: () -> Any?) { | ||
if (isModuleLogging()) | ||
log.verbose(tag, msg) | ||
} | ||
|
||
inline fun d(msg: () -> Any?) { | ||
if (isModuleLogging()) | ||
log.debug(msg) | ||
} | ||
|
||
inline fun d(tag: String, msg: () -> Any?) { | ||
if (isModuleLogging()) | ||
log.debug(tag, msg) | ||
} | ||
|
||
inline fun i(msg: () -> Any?) { | ||
if (isModuleLogging()) | ||
log.info(msg) | ||
} | ||
|
||
inline fun i(tag: String, msg: () -> Any?) { | ||
if (isModuleLogging()) | ||
log.info(tag, msg) | ||
} | ||
|
||
inline fun w(msg: () -> Any?) { | ||
if (isModuleLogging()) | ||
log.warn(msg) | ||
} | ||
|
||
inline fun w(err: Throwable?, tag: String? = null, msg: () -> Any?) { | ||
if (isModuleLogging()) | ||
log.warn(err, tag, msg) | ||
} | ||
|
||
inline fun e(msg: () -> Any?) { | ||
if (isModuleLogging()) | ||
log.error(msg) | ||
} | ||
|
||
inline fun e(err: Throwable?, tag: String? = null, msg: () -> Any?) { | ||
if (isModuleLogging()) | ||
log.error(err, tag, 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 |
---|---|---|
|
@@ -17,7 +17,7 @@ kotlin { | |
} | ||
} | ||
} | ||
js(LEGACY) { | ||
js { | ||
browser { | ||
} | ||
} | ||
|
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ dependencies { | |
} | ||
|
||
kotlin { | ||
js(LEGACY) { | ||
js { | ||
browser { | ||
binaries.executable() | ||
commonWebpackConfig { | ||
|