blob: 7a05cbf74fd98f96b7d13ccfe50e5dfd34fbeb2c (
plain) (
blame)
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
27
28
29
30
31
32
33
34
35
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.testrunner;
import org.fusesource.jansi.HtmlAnsiOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Converts ANSI output to HTML-safe log records
*
* @author jonmv
*/
public class HtmlLogger {
public static final Level HTML = new Level("html", 1) { };
private final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
private final PrintStream formatter = new PrintStream(new HtmlAnsiOutputStream(buffer));
public LogRecord toLog(String line) {
if (line.length() > 1 << 13)
line = line.substring(0, 1 << 13) + " ... (this log entry was truncated due to size)";
buffer.reset();
formatter.print(line);
formatter.flush();
return new LogRecord(HTML, buffer.toString(UTF_8)); //.replaceAll(" ", " "));
}
}
|