Skip to content

Core

Module core

This module holds utilities used in other libraries of the toolkit. Check the packages' documentation for more details. You can find a quick recap of the main features in the sections below.

Install the Dependency

This module is not meant to be imported directly. It will be included by using any other part of the toolkit. However, if you only want to use the utilities, logging or serialization (i.e., for a desktop application), you can import it with the following code:

1
2
3
4
5
repositories {
    mavenCentral()
}

implementation("com.hexagonkt:core:$hexagonVersion")
1
2
3
4
5
<dependency>
  <groupId>com.hexagonkt</groupId>
  <artifactId>core</artifactId>
  <version>$hexagonVersion</version>
</dependency>

Defined Ports

TODO Document module exposed ports: * LoggingPort

URLs

TODO Note that GraalVM requires to install the Classpath handler manually with ClasspathHandlerProvider.registerHandler.

JVM Information

TODO Add information about the system property that disables JMX.

Logger

The following code block shows the most common use cases for the Logger class:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
val classLogger: Logger = Logger(Runtime::class) // Logger for the `Runtime` class
val instanceLogger: Logger = Logger(this::class) // Logger for this instance's class

logger.info {
    """
    You can add a quick log without declaring a Logger with 'com.hexagonkt.helpers.logger'.
    It is a default logger created for the System class (same as `Logger(System::class)`).
    """
}

classLogger.trace { "Message only evaluated if trace enabled at ${Jvm.id}" }
classLogger.debug { "Message only evaluated if debug enabled at ${Jvm.id}" }
classLogger.warn { "Message only evaluated if warn enabled at ${Jvm.id}" }
classLogger.info { "Message only evaluated if info enabled at ${Jvm.id}" }

val exception = IllegalStateException("Exception")
classLogger.warn(exception) { "Warning with exception" }
classLogger.error(exception) { "Error message with exception" }
classLogger.error { "Error without an exception" }

classLogger.time("Logs the time used to run the following block of code") {
    val message = "Block of code to be timed"
    assert(message.isNotBlank())
}

instanceLogger.flare { "Prints a log that stands out for ease searching" }

By default, Hexagon uses the Java Util Logging logging library, you can use any of its implementations by just adding another logging adapter as a dependency. Below you can see some alternatives:

TODO Add LoggingManager examples for changing logging level

Package com.hexagonkt.core.helpers

JVM information, a logger class and other useful utilities.

Package com.hexagonkt.core.logging

Provides a logging management capabilities abstracting the application from logging libraries.

Package com.hexagonkt.core.logging.jul

TODO

Package com.hexagonkt.core.security

TODO