Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.a-hansen:alog:4.1.0'
}
dependencies {
implementation("com.github.a-hansen:alog:4.1.0")
}
<dependency>
<groupId>com.github.a-hansen</groupId>
<artifactId>alog</artifactId>
<version>4.1.0</version>
</dependency>
libraryDependencies += "com.github.a-hansen" % "alog" % "4.1.0"
:dependencies [[com.github.a-hansen/alog "4.1.0"]]
An asynchronous log handler for JUL (Java Util Logging). It prints log messages on separate threads for low latency logging.
There are two ways to use Alog: programmatically and with configuration files.
Initially acquire logs with Alog.getLogger(). It will add a log handler only if one has not already been added.
import com.comfortanalytics.alog.*;
public static void main(String[] args) {
Logger log = Alog.getLogger("myLog", new File("myLog.log")));
AsyncLogHandler handler = Alog.getHandler(log);
handler.setThrottle(100);
}
Multiple logs can share the same file. A single FileLogHandler will be maintained for each absolute file path. Be aware that once closed, none of the other logs can use the same handler.
import com.comfortanalytics.alog.*;
public static void main(String[] args) {
Logger log = Alog.getLogger("myLog", new File("myLog.log")));
Logger another = Alog.getLogger("anotherLog", new File("myLog.log")));
if (log.getHandlers()[0] == another.getHandlers()[0]) {
System.out.println("This will print.");
}
}
The root log handler that prints to System.out should be replaced as well.
import com.comfortanalytics.alog.*;
public static void main(String[] args) {
Alog.replaceRootHandler();
}
Alog uses configuration as specified by Java Util Logging. See javadoc for java.util.logging.LogManager for details.
There are two handlers:
The following keys can be used with both:
The following keys can also be used with the FileLogHandler:
The filename pattern uses the following tokens:
Example configuration for an async file handler:
myLog.handlers=com.comfortanalytics.alog.FileLogHandler
com.comfortanalytics.alog.level=CONFIG
com.comfortanalytics.alog.maxQueue=50000
com.comfortanalytics.alog.backupThreshold=100000000
com.comfortanalytics.alog.filename=%halog.log
com.comfortanalytics.alog.maxBackups=5
To replace the root handler that prints to the console with one that does it ansynchronously:
handlers=com.comfortanalytics.alog.PrintStreamLogHandler
com.comfortanalytics.alog.level=FINE
com.comfortanalytics.alog.maxQueue=5000
com.comfortanalytics.alog.throttle=95