Logreader patterns

I’m specifically looking at the customPatterns area. I’m looking for lines that are like:

Could not cast UNDEF to java.lang.Number; line 510, column 29, length 30

Reading the documentation (LogReader documentation and Java Regex) it seems the below line should work.

logreader:reader:openhablog[ refreshRate=1000, customPatterns="line \d+, column \d+ length \d+" ]

But instead I get something like this in the log and it doesn’t work:

Configuration model 'log.things' has errors, therefore ignoring it: [1,243]: mismatched character 'd' expecting set null

I’ve also tried with \d and other variations. I feel like I’m missing something simple though.

Any thoughts?

Thanks,
Dan

1 Like

d\ matches only for a digit. For whitespace you can try \p{Space} or \p{javaWhitespace}.

Not tested but try this:

line\p{Space}\d{1,4}.\p{Space}column\p{Space}\d{1,4}.\p{Space}length\p{Space}\d{1,4}

Idea is to match 1 to 4 digits, whitespace and “,”.

1 Like

This error is coming from OH core, so regex pattern isn’t even passed to logreader binding yet. Reason most probably is that \ character is an escape character in java, so you need to give double \ (\\) to thing configuration file. Then single \ will be passed to the binding.

@gitMiguelI tried your method with the following line in my thing configuration.

logreader:reader:openhablog[ refreshRate=1000, errorPatterns="ERROR+", errorBlacklistingPatterns="Host unreachable|Read timed out|No response", warningBlacklistingPatterns="t_cool|t_heat|gDoors[a-zA-Z]+_Last|Host unreachable", customPatterns="line\p{space}\d{1,4}."]

but, I received the following error:

Configuration model 'log.things' has errors, therefore ignoring it: [1,243]: mismatched character 'p' expecting set null

So I thought, I would try @pauli_anttila suggestion (I had tried this in the past). I no longer received the above error but nothing ever gets picked up by the pattern. I’ve forced an error to occur in the logs that should be picked up but it isn’t.

logreader:reader:openhablog[ refreshRate=1000, errorPatterns="ERROR+", errorBlacklistingPatterns="Host unreachable|Read timed out|No response", warningBlacklistingPatterns="t_cool|t_heat|gDoors[a-zA-Z]+_Last|Host unreachable", customPatterns="line\\p{space}\\d{1,4}."]

Here is the test error that I’m trying to pick up. But I want to pick up any error that indicates a similar issue.

Error during the execution of startup rule 'test.rules loaded Event': Could not cast UNDEF to java.lang.Number; line 40, column 28, length 30

I guess the space should be Space

customPatterns="line\\p{Space}\\d{1,4}."

You can test you regex patterns e.g. by https://www.freeformatter.com/java-regex-tester.html

Tester works only with “real” patterns, so when you find correct pattern, remember double the \ characters (if any used).

1 Like

That did it. Thanks, the tester site is a great resource!

What did it? Pali’s double backslash version of the expression or the regex tester?

I’m wondering because I just looked at my config and the following seems to work without double backslashes. I’ve set up the binding through PaperUI even though it shouldn’t make any difference:

\[ERROR\]
\[WARN\p{javaSpaceChar}\]

…captures:

2020-04-30 20:52:06.075 [vent.ChannelTriggeredEvent] - logreader:reader:openhablog:newErrorEvent triggered 2020-04-30 20:52:05.253 [ERROR] [e.automation.jsr223.jython.LogReader] - Traceback (most recent call last):
2020-04-30 20:52:06.076 [vent.ChannelTriggeredEvent] - logreader:reader:openhablog:newWarningEvent triggered 2020-04-30 20:52:05.254 [WARN ] [e.automation.internal.RuleEngineImpl] - Fail to execute action: 1

This is what is working in my log.things file and it works. I think the double \ is only needed in openHAB not in the tester site.

logreader:reader:openhablog[ refreshRate=1000, errorPatterns="ERROR+", errorBlacklistingPatterns="Host unreachable|Read timed out|No response", warningBlacklistingPatterns="t_cool|t_heat|gDoors[a-zA-Z]+_Last|Host unreachable", customPatterns="line\\p{Space}\\d{1,4}."]
1 Like

Double backlash is only needed in thing files.

1 Like