SmartLinks

You can link from recognized portions of log lines in the search results. For example, you may want to have the value of a field called userId link to that user's page in your company directory. To do that, you configure the link in your /scalyr/logs configuration file:

searchResultLinks: [
 {
  regex: "(\\d+)",
  url: "https://dir.example.com/lookup?id=${1}",
  searchFields: "userId"
 }
]

The regex will be applied to the value of the field userId in each log line. It will match any number in that field. The matched text will be captured as argument 1 due to the surrounding parentheses, and can then be used in the URL.

You can have as many link configuration objects as you like. If a value matches more than one regex, the first match will be used.

The fields that can appear in a link configuration are:

regex

A Javascript regular expression to match values against. Use parentheses to capture text for use in the URL. Captured text is numbered in order of left parentheses, starting with 1. Any backslashes in the regex will need to be escaped (doubled).

url

The target for a link from the matched text. It will open in a new tab. By default, the link text is the text of the match.

searchFields (optional)

A comma-separated list of fields (facets) to match against, or `* to match against all fields. Defaults to the raw log line (also called message). In addition to any facet pulled out by the parser, it can include the system fields serverHost, logfile, and/or message.

linkTextArg (optional)

The number of the captured argument to use as the link text (rather than the entire matched text).

caseSensitive (optional)

Whether to perform case-sensitive matching. Defaults to false.

subs (optional)

Used to perform transformations on captured arguments. For example, you may need to change dots in a classpath to slashes in the URL. Each substitution object must specify arg (which argument to transform), match (a regex matching text to transform), and replace (replacement text).

A common use of linking is to link from a file reference in a stacktrace to its source code. Here is one way to do that:

searchResultLinks: [
  {
    regex: "com\\.example\\.([a-z\\.\\d]+)[\\w\\.\\$]+\\(((\\w+\\.java):(\\d+))\\)",
    subs: [
      {arg: 1, match: "\\.", replace: "/"}
    ],
    url: "https://github.com/example/master/WebSite/src/com/example/${1}${3}#L${4}",
    linkTextArg: 2,
    caseSensitive: true
  }
]

Notes:
  • Backslashes must be escaped (doubled).
  • There are four pieces of captured text:
    1. classpath
    2. filename and line number (used as link text)
    3. filename
    4. line number
  • Defaults to matching against the raw log line.
  • Dots are replaced by slashes in the URL.
  • Case-sensitive to detect the break between classpath and filename.