I’m looking to filter the logs messages going into pick out the location, store, operator and nonce. Nov 15 20:16:25 PROD SERVER: [ERROR] c.q.s.w.c.mycompanyControllerAdvice: logTraceId=f498cef6516543e1a70dc9bad5f7358a, order=36276, nonce=CC41B399-6664-4E88-8A17-1DD30327175C, location=20655, restaurant=294, operator=42 com.mycompany.server.exceptions.pos.mcp.McpException Can anyone help? Happy to focus on location first. ^ I need something in here I think (location=)\d
on 2016-11-15 23:29
on 2016-11-16 14:49
Given a string such as the one you have posted, you can get the location by applying the regexp / location=(\d+)/ but in any case, there are several possible solutions. For example, are alsways all these fields supplied, in exactly the same sequence? Would it preferable (more flexible) to have all NAME=VALUE pairs extracted from the string?
on 2016-11-18 16:20
Hi Ronald, Thanks for this. I need each NAME=VALUE extracted but not all together in the one expression. I need each separately. Taking your example above, how would I only select the numbers after the 'location='?
on 2016-11-21 11:57
String#scan is your friend. Assuming that the whole line is stored in variable whole_line, the expression whole_line.scan((\w+)=(\w+)) returns an array of pairs, where the first element of each pair is the NAME, and the second element is the value.