Parsing specifications#
A parsing specification is the set of rules CLP+ uses to parse log messages. Its file format and regex syntax are defined by log-surgeon and documented in log-surgeon’s parsing specification reference.
This page shows how to go from the shipped template to a specification that recognizes your own log formats, and describes the few behaviours specific to CLP+.
Start from the template#
A ready-to-use specification ships with CLP at
components/package-template/src/etc/parsing-spec.template.txt, and in the package at
etc/parsing-spec.template.txt. It mimics CLP’s built-in heuristic-parser and recognizes common
timestamps, numbers, paths, and key-value pairs, making it a reasonable starting point for most
logs.
Add a rule for your own identifiers#
Suppose your logs contain block identifiers such as blk_1073746484_5660 that you want to query by
their two components. Add a rule naming each component as a sub-rule:
block_id: "blk_(?<num>\d+)_(?<gen_stamp>\d+)"
When several rules could match the same text, log-surgeon prefers the longest match; ties are broken by each rule’s optional priority and then by file order. See the reference for details.
Compress a sample and inspect the resulting log shapes to confirm the rule works:
./clp-s c --flavour clpp --parsing-specification=./my-spec.txt /tmp/archives /tmp/sample.log
./clp-s s /tmp/archives 'stats.log_shapes'
After compression, each leaf rule is a queryable column, named by its fully qualified name and prefixed by the field the log message came from:
./clp-s s /tmp/archives 'message.block_id.num: 1073746484'
Tip
A log shape that is entirely static text means nothing was parsed. One that is almost entirely placeholders usually means a rule is matching too aggressively.
CLP+-specific behaviour#
Numbers are encoded automatically. Any leaf rule match whose text is an integer or a decimal number is stored as a JSON number rather than a string, regardless of the rule’s name. This happens transparently and is what makes numeric comparisons work:
./clp-s s /mnt/data/archives 'message.block_id.num > 1073746400'
header rules have no separator role under clp-s. In log-surgeon, a header rule at the
start of a line marks the start of a new log event. clp-s c parses each JSON string value as a
single event, so a header rule behaves like any other rule: its matches become a header parent
rule whose leaves (e.g. message.header.timestamp) are queryable.