Syntax: [Log] scope whole line based on log level

to allow color schemes to color entire lines differently based on log level
This commit is contained in:
Keith Hall 2022-04-10 00:28:43 +03:00 committed by David Peter
parent 45d6b1af3b
commit c6775cc41e

View file

@ -7,8 +7,15 @@ scope: text.log
variables:
ipv4_part: (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
hours_minutes_seconds: (?:[01]\d|2[0-3]):(?:[0-5]\d):(?:[0-5]\d)
error: \b(?i:fail(?:ure|ed)?|error|exception|fatal|critical)\b
warning: \b(?i:warn(?:ing)?)\b
info: \b(?i:info)\b
debug: \b(?i:debug)\b
contexts:
main:
- include: log_level_lines
- include: main_without_log_level_line
main_without_log_level_line:
- match: (\w+)(=)
captures:
1: variable.parameter.log
@ -25,16 +32,58 @@ contexts:
- include: dates
- include: ip_addresses
- include: numbers
- match: \b(?i:fail(?:ure|ed)?|error|exception)\b
scope: markup.error.log
- match: \b(?i:warn(?:ing)?)\b
scope: markup.warning.log
- match: \b(?i:debug)\b
scope: markup.info.log
- include: log_levels
#- include: scope:text.html.markdown#autolink-inet
- match: \b\w+:/{2,3}
scope: markup.underline.link.scheme.log
push: url-host
log_level_lines:
- match: ^(?=.*{{error}})
push:
- error_line
- main_pop_at_eol
- match: ^(?=.*{{warning}})
push:
- warning_line
- main_pop_at_eol
- match: ^(?=.*{{info}})
push:
- info_line
- main_pop_at_eol
- match: ^(?=.*{{debug}})
push:
- debug_line
- main_pop_at_eol
log_levels:
- match: '{{error}}'
scope: markup.error.log
- match: '{{warning}}'
scope: markup.warning.log
- match: '{{info}}'
scope: markup.info.log
- match: '{{debug}}'
scope: markup.info.log
error_line:
- meta_scope: meta.annotation.error-line.log
- include: immediately_pop
warning_line:
- meta_scope: meta.annotation.warning-line.log
- include: immediately_pop
info_line:
- meta_scope: meta.annotation.info-line.log
- include: immediately_pop
debug_line:
- meta_scope: meta.annotation.debug-line.log
- include: immediately_pop
immediately_pop:
- match: ''
pop: true
pop_at_eol:
- match: $
pop: true
main_pop_at_eol:
- include: main_without_log_level_line
- include: pop_at_eol
dates:
- match: \b\d{4}-\d{2}-\d{2}(?=\b|T)
scope: meta.date.log meta.number.integer.decimal.log constant.numeric.value.log
@ -49,14 +98,12 @@ contexts:
scope: meta.time.log meta.number.integer.decimal.log constant.numeric.value.log
captures:
1: punctuation.separator.decimal.log
- match: ''
pop: true
- include: immediately_pop
maybe_date_time_separator:
- match: T(?={{hours_minutes_seconds}})
scope: meta.date.log meta.time.log keyword.other.log
set: time
- match: ''
pop: true
- include: immediately_pop
ip_addresses:
- match: \b(?=(?:{{ipv4_part}}\.){3}{{ipv4_part}}\b)
push:
@ -65,8 +112,7 @@ contexts:
scope: constant.numeric.value.log
- match: \.
scope: punctuation.separator.sequence.log
- match: ''
pop: true
- include: immediately_pop
- match: (?=(?:\h{0,4}:){2,6}\h{1,4}\b)
push:
- meta_scope: meta.ipaddress.v6.log meta.number.integer.hexadecimal.log
@ -74,8 +120,7 @@ contexts:
scope: constant.numeric.value.log
- match: ':'
scope: punctuation.separator.sequence.log
- match: ''
pop: true
- include: immediately_pop
numbers:
- match: \b(0x)(\h+)(?:(\.)(\h+))?\b
scope: meta.number.float.hexadecimal.log
@ -127,8 +172,7 @@ contexts:
pop: true
- match: '[^?!.,:*_~\s<&()%]+|\S'
scope: markup.underline.link.path.log
- match: ''
pop: true
- include: immediately_pop
double_quoted_string:
- meta_scope: string.quoted.double.log
- match: \\"