Skip to content

Instantly share code, notes, and snippets.

@stav
Created January 10, 2019 23:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stav/d62da3c59057e8cfdbd91061fe0bc650 to your computer and use it in GitHub Desktop.
Save stav/d62da3c59057e8cfdbd91061fe0bc650 to your computer and use it in GitHub Desktop.
Sublime Text Syntax Definition for Scrapy log files
%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
# See http://www.sublimetext.com/docs/3/scope_naming.html
#
# Note that blackslashes don't need to be escaped within single quoted strings
# in YAML. When using single quoted strings, only single quotes need to be
# escaped: this is done by using two single quotes next to each other.
#
# Scope discovery - Ctrl Shft Alt p
# >>> view.scope_name(0).split()
#
name: Scrapy Log
file_extensions:
- slog
scope: source.slog
contexts:
main:
# Strings begin and end with quotes, and use backslashes as an escape
# character
- match: '"'
scope: punctuation.definition.string.begin.nslog
push: double_quoted_string
- match: "'"
scope: punctuation.definition.string.begin.nslog
push: single_quoted_string
# Date time
- match: '\d{4}(-)\d{2}(-)\d{2}\s\d{2}(:)\d{2}(:)\d{2}'
scope: comment
captures:
1: keyword
2: keyword
3: keyword
4: keyword
# Logger (1.0+)
- match: '\[([^\]]+)\] ([A-Z]+):\s'
scope: support.constant
captures:
1: comment
2: comment
# Markers to red
- match: 'Spider opened|Received cookies from|Sending cookies to|Crawled \((\d{3})\)'
scope: keyword.control.nslog
captures:
1: constant.numeric
# Markers to green
- match: '(?<=: )Scraped(?= from <)'
scope: entity.name.class
# Request
- match: '<([A-Z]+)\s([^]]+?)>'
scope: constant.other
captures:
1: entity.other.attribute-name
2: string
# Response
- match: '<([\d]+)\s([^]]+?)>'
scope: constant.other
captures:
1: variable.parameter
2: entity.name.class
# Key
- match: '[\w-]+(?=:)'
scope: variable.language
# Parameters
- match: '[\w-]+(?=[=:])'
scope: variable.parameter
# Arguments
- match: (?<=\=)[\w/+=.]+
scope: variable.function
# Numbers
- match: '\b(-)?\d*\.?\d++\b'
scope: constant.numeric.nslog
double_quoted_string:
- meta_scope: string.quoted.double.nslog
- match: '\\.'
scope: constant.character.escape.nslog
- match: '"'
scope: punctuation.definition.string.end.nslog
pop: true
single_quoted_string:
- meta_scope: string.quoted.single.nslog
- match: '\\.'
scope: constant.character.escape.nslog
- match: "'"
scope: punctuation.definition.string.end.nslog
pop: true
@stav
Copy link
Author

stav commented Jan 10, 2019

Save YAML file to Sublime User directory, e.g.:

/home/stav/.config/sublime-text-3/Packages/User/ScrapyLog.sublime-syntax 

Then build:

  • with Tools > Build System set to "Automatic",
  • use Tools > Build (Ctrl-B)

Save Scrapy log output to a file with an slog extension and open the file in Sublime Text where it will be color coded according to your color_scheme.

scrapylog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment