By setting the output file path using OptionsBuilder, we can send the log messages to a file.
Example
Options opt = new OptionsBuilder()
.include(SendLogMessagesToAFile.class.getSimpleName())
.forks(1)
.measurementIterations(4)
.warmupIterations(3)
.resultFormat(ResultFormatType.JSON)
.output("/Users/Shared/logMessages.log")
.build();
Above snippet send the log messages to the file "/Users/Shared/ logMessages.log".
Find the below working application.
SendLogMessagesToAFile.java
package com.sample.app;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
public class SendLogMessagesToAFile {
@Benchmark
public void test1() throws InterruptedException {
TimeUnit.MILLISECONDS.sleep(300);
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(SendLogMessagesToAFile.class.getSimpleName())
.forks(1)
.measurementIterations(4)
.warmupIterations(3)
.resultFormat(ResultFormatType.JSON)
.output("/Users/Shared/logMessages.log")
.build();
new Runner(opt).run();
}
}
Run the above application and
open the file ‘/Users/Shared/logMessages.log’ to see the log messages.
Previous Next Home
No comments:
Post a Comment