我们的文件具有日志文件样式log4j
[ main] [DEBUG] (14:25:46.832 CET) server started
[ main] [ INFO] (14:25:46.832 CET) I'm a nice info line
[ main] [ERROR] (14:25:46.832 CET) wrong user password for user '..'
每一行取决于它是否应该以不同的方式(整行)着色DEBUG,INFO或ERROR
如何使用Codemirror完成此操作?
答案 0 :(得分:0)
使用正则表达式直接使用defineSimpleMode:
CodeMirror.defineSimpleMode("log4j",
{
start: [
{regex: /.*\[FATAL\].*/, token: "log4j-fatal"},
{regex: /.*\[ERROR\].*/, token: "log4j-error"},
{regex: /.*\[ WARN\].*/, token: "log4j-warn"},
{regex: /.*\[ INFO\].*/, token: "log4j-info"},
{regex: /.*\[DEBUG\].*/, token: "log4j-debug"},
{regex: /.*\[TRACE\].*/, token: "log4j-trace"},
],
});