Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing logMessage templates #24

Closed
hoehrmann opened this issue Feb 15, 2019 · 3 comments
Closed

Parsing logMessage templates #24

hoehrmann opened this issue Feb 15, 2019 · 3 comments
Assignees
Labels
clarification Protocol clarification info-needed Issue requires more information from poster

Comments

@hoehrmann
Copy link

hoehrmann commented Feb 15, 2019

As of 4102c79 the specification for logMessage is lacking in detail on how to parse the attribute

If this attribute exists and is non-empty, the backend must not 'break' (stop) but log the message instead. Expressions within {} are interpolated.

For some languages it is quite normal for expressions to include the { and } delimiters, in Perl for instance you might want to log

Value of key field in hash is {$hash{key}} # ?

I would expect either \-escaping or actually configurable delimiters. For Perl it might be better to use backticks instead of curly braces, for instance, in which case the specification should allow implementations to vary on that point.

@hoehrmann
Copy link
Author

hoehrmann commented Feb 15, 2019

I could also imagine that simply skipping over balanced nested curly braces would work to extract the "expressions", given that expressions here should be fairly simple. So if you parse the template and hit { you continue looking for { and matching }s up until you found the } that matches the outermost {. But that too should be noted, then.

function parseLogpointTemplate(template: string) {

  const parts: string[][] = [[]];
  let depth = 0;

  for (const token of template.match(/(\{|\}|[^{}]+)/g)) {

    if (token === '{') {

      if (depth++ === 0) {
        parts.push([]);
      }

      parts[parts.length - 1].push(token);

    } else if (token === '}') {

      parts[parts.length - 1].push(token);

      if (depth > 0) {
        depth--;
        if (!depth) {
          parts.push([]);
        }
      }

    } else {

      parts[parts.length - 1].push(token);

    }

  }

  return parts.map(x => x.join("")).map(x => {
    return x.startsWith('{') && x.endsWith('}') ? {
      expr: x.substring(1, x.length - 2).trim()
    } : {
      text: x
    }
  });

}

const parts = parseLogpointTemplate(
  'this is { $h->{value}{value} } the value'
);

@weinand weinand self-assigned this Mar 1, 2019
@weinand weinand added clarification Protocol clarification info-needed Issue requires more information from poster labels Mar 1, 2019
@weinand
Copy link
Contributor

weinand commented Mar 1, 2019

@hoehrmann what exactly are you proposing to do here?

@vscodebot vscodebot bot closed this as completed Mar 8, 2019
@vscodebot
Copy link

vscodebot bot commented Mar 8, 2019

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!

@vscodebot vscodebot bot locked and limited conversation to collaborators Apr 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
clarification Protocol clarification info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

2 participants