A Kotlin logging library focused on readability in console. PrettyLog takes advantage of ANSI color codes to make your logs look โจ pretty โจ.
As of 2.0, PrettyLog supports the following targets:
jvm(Java 21)mingwx64(Windows)macosx64macosarm64linuxx64linuxarm64
Supporting both Kotlin/JVM and Kotlin/Native
repositories {
maven("https://mvn.devos.one/releases")
}
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.2")
implementation("com.squareup.okio:okio:3.10.2")
// Import the common code
implementation("cz.lukynka:pretty-log-common:<version>")
// Import the platform-specific library. Do jvm if you're doing Kotlin/JVM / Java,
// Do any other platform if you're doing Kotlin/Native [like linuxx64 or mingwx64]
implementation("cz.lukynka:pretty-log-PLATFORMNAMEHERE:<version>")
}Logging is very easy, just call the log(message, type) method. type parameter is optional and defaults to RUNTIME. Add LoggerFileWriter.load() to your main function if you want logs to be saved.
log("Hello there!")
log("general kenobi", LogType.NETWORK)You can also log exceptions!
} catch (exception: Exception) {
log(exception)
}You can change settings by simply setting LoggerSettings.<setting> to its new value
// Should the logs be saved to file?
PrettyLogSettings.saveToFile = true
// The path to the logs directory
PrettyLogSettings.saveDirectoryPath = "./logs/"
// Format of the log file name
PrettyLogSettings.logFileNameFormat = "yyyy-MM-dd-Hms"
// Logs which will be disabled and not show up
PrettyLogSettings.disabledLogTypes = setOf(LogType.WARNING)There are 16 log types by default:
You can make custom log types by making your own LogType instance. Everything from the prefix background color, text color to the actual message text color is customizable
// Create custom log prefix
val customLogStyle = LogStyle(textColor = AnsiColor.BLACK, backgroundColor = AnsiColor.CUTE_PINK_BACKGROUND)
val customLogPrefix = StaticLogPrefix(" โฝ^โขโฉโข^โผ ", customLogStyle)
// Create custom log type
val customLogType = LogType(textStyle = LogStyle.CUTE_PINK, listOf(customLogPrefix))
log("T-This is vewy cuwute message OwO", customLogType)
There is also DynamicLogPrefix which has field for text supplier instead of static string.
You may alternatively use simpler version of this for class-specific logger by referencing the class in the constructor:
val logger = PrettyLogger(this::class)
You can add multiple prefixes to a custom logger. For example, we can add "Inbound" prefix and a "Proxy" for better understanding what is being logged and from where
val proxyPrefix = StaticLogPrefix(" Proxy ", LogStyle.FILLED_PURPLE)
val inboundPrefix = StaticLogPrefix("-> Inbound ", LogStyle.GRAY)
// create custom instance of PrettyLogger
val logger = PrettyLogger(inboundPrefix, proxyPrefix)
Events.on<PacketReceivedEvent> { event ->
logger.log(event.packet.name, LogType.NETWORK)
}


