Created
August 5, 2016 13:55
-
-
Save pesterhazy/a26da0130fd735f66c4f7542f5e3bf12 to your computer and use it in GitHub Desktop.
Filter "react-native log-ios" output for relevant app logs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Cleans up the output of "react-native log-ios" by | |
# removing all output not related to your app, similarly | |
# to how it works in the XCode debug window | |
# | |
# Usage: react-native log-ios | ./react-native-only.py "<string>" | |
# | |
# where "<string>" is the name of your app as known | |
# to the iOS logging system. E.g. "SimpleExampleApp" | |
import sys, os, re | |
class Transformer: | |
def __init__(self): | |
self.context = None | |
def transform(self, only, l): | |
regex = "^\S+\s+\S+\s+\S+\s+\S+\s+(\S+)\[\d+\]\s+(.*)$" | |
m = re.match(regex, l) | |
if m: | |
self.context = m.group(1) | |
msg = m.group(2) | |
if self.context == only: | |
return msg | |
else: | |
if self.context == only or self.context is None: | |
return l | |
return None | |
def main(): | |
only = sys.argv[1] | |
transformer = Transformer() | |
while True: | |
line = sys.stdin.readline().rstrip() | |
if not line: | |
break | |
result = transformer.transform(only, line) | |
if result: | |
sys.stdout.write(result + "\n") | |
sys.stdout.flush() | |
try: | |
main() | |
except KeyboardInterrupt: | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment