# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^(?:SLF4J:|\w+(?:\.\w+)+).*(?:\R(?!(?:SLF4J:|\w+(?:\.\w+)+)|{).*)*"
test_str = ("SLF4J: Class path contains multiple SLF4J bindings.\n"
"SLF4J: Found binding in [jar:file:/opt/spark/jars/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]\n"
"SLF4J: Found binding in [jar:file:/opt/spark/jars/slf4j-log4j12-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]\n"
"SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.\n"
"SLF4J: Actual binding is of type \n"
"{\"log_timestamp\": \"2021-02-18T11:33:23.114+0000\", \"log_level\": \"WARN\", \"process_id\": \"zookeeper#2\", \"process_name\": \"zookeeper\", \"thread_id\": 1, \"thread_name\": \"QuorumPeer[myid=2](plain=/0.0.0.0:2181)(secure=disabled)\", \"action_name\": \"org.apache.zookeeper.server.quorum.QuorumPeer\", \"log_message\": \"PeerState set to LOOKING\"}\n"
"{\"log_timestamp\": \"2021-02-18T11:33:23.115+0000\", \"log_level\": \"WARN\", \"process_id\": \"zookeeper#2\", \"process_name\": \"zookeeper\", \"thread_id\": 1, \"thread_name\": \"WorkerSender[myid=2]\", \"action_name\": \"org.apache.zookeeper.server.quorum.QuorumPeer\", \"log_message\": \"Failed to resolve address: zk-2.zk-headless.intam.svc.cluster.local\"}\n"
"java.net.UnknownHostException: zk-2.zk-headless.intam.svc.cluster.local\n"
" at java.net.InetAddress.getAllByName0(InetAddress.java:1281)\n"
" at java.net.InetAddress.getAllByName(InetAddress.java:1193)\n"
" at java.net.InetAddress.getAllByName(InetAddress.java:1127)\n"
" at java.net.InetAddress.getByName(InetAddress.java:1077)\n"
" at org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer.recreateSocketAddresses(QuorumPeer.java:194)\n"
" at org.apache.zookeeper.server.quorum.QuorumPeer.recreateSocketAddresses(QuorumPeer.java:764)\n"
" at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:699)\n"
" at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:618)\n"
" at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:477)\n"
" at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:456)\n"
" at java.lang.Thread.run(Thread.java:748)\n"
"{\"log_timestamp\": \"2021-02-18T11:33:23.115+0000\", \"log_level\": \"WARN\", \"process_id\": \"zookeeper#2\", \"process_name\": \"zookeeper\", \"thread_id\": 1, \"thread_name\": \"WorkerSender[myid=2]\", \"action_name\": \"org.apache.zookeeper.server.quorum.QuorumPeer\", \"log_message\": \"Failed to resolve address: zk-2.zk-headless.sxc.svc.cluster.local\"}\n\n"
"java.lang.InterruptedException: Timeout while waiting for epoch from quorum\n"
" at org.apache.zookeeper.server.quorum.Leader.getEpochToPropose(Leader.java:1227)\n"
" at org.apache.zookeeper.server.quorum.Leader.lead(Leader.java:482)\n"
" at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:1284)\n"
" ... 19 more\n"
"{\"log_timestamp\": \"2021-02-18T11:33:23.114+0000\", \"log_level\": \"WARN\", \"process_id\": \"zookeeper#2\", \"process_name\": \"zookeeper\", \"thread_id\": 1, \"thread_name\": \"QuorumPeer[myid=2](plain=/0.0.0.0:2181)(secure=disabled)\", \"action_name\": \"org.apache.zookeeper.server.quorum.QuorumPeer\", \"log_message\": \"PeerState set to LOOKING\"}\n"
"{\"log_timestamp\": \"2021-02-18T11:33:23.115+0000\", \"log_level\": \"WARN\", \"process_id\": \"zookeeper#2\", \"process_name\": \"zookeeper\", \"thread_id\": 1, \"thread_name\": \"WorkerSender[myid=2]\", \"action_name\": \"org.apache.zookeeper.server.quorum.QuorumPeer\", \"log_message\": \"Failed to resolve address: zk-2.zk-headless.intam.svc.cluster.local\"}\n"
"java.net.UnknownHostException: zk-2.zk-headless.intam.svc.cluster.local\n"
" at java.net.InetAddress.getAllByName0(InetAddress.java:1281)\n"
" at java.net.InetAddress.getAllByName(InetAddress.java:1193)\n"
" at java.net.InetAddress.getAllByName(InetAddress.java:1127)\n"
" at java.net.InetAddress.getByName(InetAddress.java:1077)\n"
" at org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer.recreateSocketAddresses(QuorumPeer.java:194)\n"
" at org.apache.zookeeper.server.quorum.QuorumPeer.recreateSocketAddresses(QuorumPeer.java:764)\n"
" at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:699)\n"
" at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:618)\n"
" at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:477)\n"
" at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:456)\n"
" at java.lang.Thread.run(Thread.java:748)\n"
"{\"log_timestamp\": \"2021-02-18T11:33:23.115+0000\", \"log_level\": \"WARN\", \"process_id\": \"zookeeper#2\", \"process_name\": \"zookeeper\", \"thread_id\": 1, \"thread_name\": \"WorkerSender[myid=2]\", \"action_name\": \"org.apache.zookeeper.server.quorum.QuorumPeer\", \"log_message\": \"Failed to resolve address: zk-2.zk-headless.sxc.svc.cluster.local\"}\n\n\n"
"org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:699) dorg.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManorg.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:699)")
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html